Skip to content

Reader role migration: give administrators the reader role too, so one an identity provider demotes stays a reader - #810

Merged
schmitch merged 2 commits into
mainfrom
claude/792-reader-role-for-admins
Nov 2, 2026
Merged

schmitch merged 2 commits into
mainfrom
claude/792-reader-role-for-admins

Conversation

@schmitch

@schmitch schmitch commented Nov 2, 2026

Copy link
Copy Markdown
Member

Fixes #792

Problem

Migration 0013 gave the built-in reader role only to users holding neither admin nor writer. An identity provider or upstream demotes an account through sync_admin_role(…, false) (crates/db/src/authz_dao.rs:380-408), which deletes admin and nothing else. That covers OIDC admin_groups/admin_claim and a credential-forwarding admin_group.

  • An account provisioned on 2.2 holds the realm's new_account_access role next to admin, so a demotion leaves it a reader.
  • An administrator from before the upgrade held admin alone, so the same demotion left it Roles only. It got 403 on every private repository while everyone else read them.

Change

  • migrations/0013_reader_role.sql gives reader to every kind = 'user' account that does not hold writer, administrators included.
    • While they are administrators it adds nothing: the web UI shows the highest built-in role (accessLevel), and changing the level there removes every other level role.
    • Writers read every repository through writer already.
    • Service accounts stay Roles only.
    • 0013 has not shipped, so it is changed in place, as Reader role migration: rename the role in workload-identity rules too, so they keep their grants #784 did. A development database that already ran the old 0013 reports a checksum mismatch and needs recreating.
  • docs/changes/2.2.0/733.upgrade.md says administrators get the role too.

Tests

readers_before_the_upgrade_get_the_reader_role (crates/db/tests/migrations.rs) checks:

  • an administrator holds admin and reader after the upgrade;
  • after sync_admin_role(…, false), as an identity provider's demotion runs it, reader remains.

Without the migration change it fails with left: ["admin"], right: ["admin", "reader"].

Run locally:

  • cargo test -p forge-db --test migrations: 5 passed;
  • cargo clippy -p forge-db --all-targets -- -D warnings, cargo fmt --all --check and cargo xtask changelog --check: clean.

Generated by Claude Code

claude and others added 2 commits November 2, 2026 21:00
Migration 0013 gave the built-in `reader` role only to users holding
neither `admin` nor `writer`. An identity provider or upstream that
manages an account's admin rights (OIDC `admin_groups`/`admin_claim`, a
credential-forwarding `admin_group`) demotes it with `sync_admin_role`,
which takes `admin` away and nothing else. An account provisioned on 2.2
holds the realm's `new_account_access` role next to `admin` and stays a
reader; an administrator from before the upgrade held `admin` alone and
was left Roles only, reading nothing.

0013 now gives `reader` to every user that is not a writer,
administrators included. While they are administrators it adds nothing
(the access level shown is the highest built-in role). 0013 has not
shipped, so it changes in place. The migration test checks that an
administrator holds both roles after the upgrade and a reader remains
once the identity provider takes `admin` away; 733.upgrade.md says so.

Fixes #792

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012e6DJc1H3748D8sheqhKTV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants