Skip to content

security(auth): admin status can't be changed, and the role routes don't affect it #20670

Open

Description

@mrveiss

Corrected 2026-11-02. This issue first said a demoted admin keeps access until their token expires. That was wrong: there is no demotion to go stale. From reading the code on main; not run.

Problem

The role routes and admin access are disconnected, in both directions.

  • The token's role comes only from is_platform_admin (api/auth.py:105), and refresh copies it forward (auth.py:513-518).
  • No route changes is_platform_admin after an account is created. The only writers are the first-admin seed and the create path (user_management/services/seed.py:110, user_service.py:78,98).
  • POST and DELETE /{user_id}/roles/{role_id} and PUT /{user_id}/role (api/user_management/users.py:392,421,458) write UserRole rows only. Those feed live permission checks, never the token.

So an admin who revokes another user's "admin" role changes nothing on token-role checks such as require_transcriber_admin, even after a fresh login, and an admin can't be demoted at all. Giving a user admin through PUT /{user_id}/role grants no token admin either. A person using those routes would reasonably believe they had changed who is an admin.

Paths checked

Path Affects token role?
The three role routes above, and role ids at creation No
is_platform_admin at creation Yes, only then
update_user (user_service.py:229) No role field
Deactivation and deletion (user_service_lifecycle.py:111) Already revokes tokens through the epoch (#20443)
Company role definitions and assignments (llc/api/roles.py, llc/services/membership_service.py) Company-scoped; not traced into admin status
SCIM and SSO in the main backend None found, beyond a read-only SSO audit

Decision needed

What does changing someone's admin status mean?

  • A (recommended): is_platform_admin is the one source of admin, changed only through a new admin route. In the same transaction it queues PasswordEpochMark with lead 0 (autobot_shared/user_management/password_epoch.py), so old tokens stop on the next request, failing closed if Redis is down. The role routes stay permissions only, and the screens say so. No new store. A self-demoting admin is signed out and returns as a normal user.
  • B: derive the token's role from UserRole at login, and have the role routes bump the epoch. This changes who counts as admin at every gate, and is_platform_admin becomes redundant or needs reconciling.
  • C: read the role live in get_current_user. A database read on every request, reintroducing the dependency dependencies.py:168-175 avoids. Not recommended.

Acceptance criteria

  • The decision is recorded here.
  • An admin can change a user's admin status, and it takes effect on the next request.
  • A test through a real admin route such as PATCH /providers: a token from before the change is refused, with an unchanged-admin control, a promotion case, and the Redis-down fail mode.
  • The user management screens don't imply a role route changes admin status, if the decision keeps them separate.
  • Host evidence after a finished builtin update.

Refs #12924, #20443, #16335.

Activity

  1. added
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 2, 2026
  2. changed the title [-]security(auth): a demoted admin keeps admin access until their token expires[/-] [+]security(auth): admin status can't be changed, and the role routes don't affect it[/+] on Nov 2, 2026
  3. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision (2026-11-02): option A. is_platform_admin is the one source, changed through a new admin route that also revokes old tokens through the existing password epoch. No new store; the role routes stay permissions only. The implementation PR waits for the merge coordinator to ask.

  4. removed
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 2, 2026
  5. 8 remaining items

  6. mrveiss commented on Nov 15, 2026

    @mrveiss
    OwnerAuthor

    Closure pass, checked against origin/main at c2b5a4fa95. I read the code; I ran no tests. The work landed in #21020 (merge 8e6ba8f15b), which follows option A.

    Criterion Ticked? Evidence
    Decision recorded yes (already) maintainer comment of 2026-11-02, option A
    An admin can change a user's admin status, and it takes effect on the next request ticked now autobot-backend/api/user_management/admin_status.py:31 PUT /user-management/users/{user_id}/admin, gated by require_platform_admin (:40), mounted in api/user_management/router.py:23. autobot_shared/user_management/user_service_lifecycle.py:213 set_platform_admin queues PasswordEpochMark (:256), with lead 1 on demotion and 0 on promotion (:56). tests/security/test_admin_status_20670.py:79 test_revoking_admin_voids_the_old_admin_token_on_the_next_request
    A test through a real admin route such as PATCH /providers: old token refused, unchanged-admin control, promotion, Redis-down no Present: control (:72, :97), promotion (:104, :136), store-down fail mode (:198 write fails → 503 and the change stays committed; :283 pending check unavailable → 503). Missing: the old-token refusal is asserted through get_current_user directly (_assert_refused), not through an HTTP request to a real admin route. The only HTTP test (:212) checks the 403 gate on the new route with get_current_user overridden.
    User management screens don't imply a role route changes admin status no #21020 lists this as not delivered. On main, autobot-frontend/src/views/AdminUsersView.vue:63-78 shows a Role select that includes admin (src/constants/roles.ts:44 ASSIGNABLE_ROLES = ['admin', 'user', 'readonly']), and its change handler calls PUT /api/user-management/users/{id}/role (:438). That is the role route, which per the decision does not change admin status. No frontend caller of the new /admin route was found.
    Host evidence after a finished builtin update no The local install runs c2b5a4fa95 (it includes 8e6ba8f15b; the update finished with failed=0), and admin_status.py is deployed. No admin-status change shows in the install's backend logs, and making one is a write, which a read-only check cannot do.

    Still needed: an HTTP-level revocation test through a real admin route; screen wording, or a switch to the /admin route for the admin choice; host evidence of a demotion refusing an old token. The issue stays open.

  7. github-actions commented on Nov 16, 2026

    @github-actions
    Contributor

    Landed via the merge train (#21658, merge 7e54fc095d) via #21648

  8. mrveiss commented on Nov 16, 2026

    @mrveiss
    OwnerAuthor

    Closure pass against origin/main 7e54fc0 (train #21658).

    Ticked:

    • Real-route test: autobot-backend/tests/security/test_admin_status_20670.py test_demoting_through_the_route_refuses_the_old_admin_token_on_a_real_admin_route (control 200 before, PUT /user-management/users/{id}/admin, old token 401, another admin's token 200) and test_promoting_through_the_route_voids_the_old_token_and_the_next_login_reaches_admin_routes. The Redis-down fail mode is test_a_store_that_cannot_record_is_a_503_and_the_change_stays_committed (same file), exercised at the service layer, not over HTTP.
    • Screens: autobot-frontend/src/constants/roles.ts:46 ASSIGNABLE_ROLES = ['user', 'readonly']; components/admin/UserRoleSelect.vue:5-7 states roles change permissions only and admin is not offered; admin status has its own control, components/admin/AdminStatusControl.vue.

    Left: host evidence after a finished builtin update. The install's recorded deployed commit is c2b5a4f, which does not include 7e54fc0. Awaiting a builtin update to 7e54fc0 or later.

  9. mrveiss commented on Nov 16, 2026

    @mrveiss
    OwnerAuthor

    Unticked the real-route test AC. On main (7e54fc0), test_admin_status_20670.py covers three cases through the real PUT /user-management/users/{id}/admin route and a real admin route (#21648): the old-token refusal, the unchanged-admin control, and promotion. The Redis-down fail mode that this AC also asks for is tested only at the service layer, not through the route. Remaining: an HTTP-level test where the epoch store is down, asserting the route's 503 and that the change stays committed.

  10. github-actions commented on Nov 16, 2026

    @github-actions
    Contributor

    Landed via the merge train (#21663, merge bbd78c1a0d) via #21659

  11. mrveiss commented on Nov 16, 2026

    @mrveiss
    OwnerAuthor

    Closure check against origin/main at bbd78c1 (merge of #21663, via #21659). Real-route test AC ticked; the host AC stays open.

    autobot-backend/tests/security/test_admin_status_20670.py, through the real user_management router behind the real credential gate (_client, line 325):

    • Old-token refusal and unchanged-admin control: test_demoting_through_the_route_refuses_the_old_admin_token_on_a_real_admin_route (line 351): pre-change token 200, then 401 after the change; another admin's token still 200.
    • Promotion: test_promoting_through_the_route_voids_the_old_token_and_the_next_login_reaches_admin_routes (line 369).
    • Store failure, cannot record: test_a_store_that_cannot_record_makes_the_route_a_503_and_the_change_stays_committed (line 388).
    • Store failure, down: test_a_store_that_is_down_refuses_the_caller_at_the_gate_and_the_change_never_runs (line 411).

    Host AC left unticked: awaiting a builtin update to bbd78c1 or later (the deployed commit does not include it).

  12. mrveiss commented on Nov 17, 2026

    @mrveiss
    OwnerAuthor

    Host check after the builtin update to main @ b43fe28 (read-only):

    AC "Host evidence after a finished builtin update" stays unticked. This shows the code is deployed and healthy. It does not show the revocation behaviour. Proving that needs a live admin-status change on the host, where a token issued before the change is refused. That changes a real user's admin standing, so it needs the owner to run it or approve it. Not attempted.

  13. mrveiss commented on Nov 21, 2026

    @mrveiss
    OwnerAuthor

    Read-only check of the local install on 2026-11-21 (install at main d8cbd91). No data was changed.

    • The admin-status route PUT /api/user-management/users/{id}/admin is served and returns 401 unauthenticated.
    • Not verified: that old tokens are revoked after an admin-status change. Checking this needs a write: change a disposable test user's admin status, then replay that user's earlier token and expect 401. That has not been done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions