Skip to content

security(auth): a deactivated or soft-deleted user appears to keep using tokens already issued #20443

Open
0 of 3 issues completed

Description

@mrveiss

Found while working on #19670, by reading the code; nothing was run against a live token.

Deactivating or soft-deleting a user revokes nothing. _set_active(False) in autobot_shared/user_management/user_service_lifecycle.py sets is_active and writes an audit row, and soft delete sets deleted_at. The backend's only revocation gate, autobot-backend/auth_revocation.py, refuses a token only if it predates a password change, and a grep of the auth path finds no is_active or deleted_at check. login_eligibility.py checks at login only.

So a deactivated user, including one deprovisioned through autobot-slm-backend/api/scim.py, appears to keep working with any token already issued until it expires, including reads of team knowledge. Team lookups don't check user or organisation state either (get_user_teams filters only Team.deleted_at), so bumping the membership epoch can't close this from the cache side (#19670).

Not established: whether something outside the files read rejects these tokens, and how long a token lives. The first step is a test with a real token.

Acceptance criteria

Activity

  1. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    The test confirms the finding: a real signed login token was admitted after deactivation and after soft delete, and a live user's token still works as the control. The user part is fixed in #20444 by writing the same revocation marker change_password writes.

    Decision needed, organisations: deactivating or soft-deleting an organisation must give its users the same answer.

    Option Effect Cost
    A. Write the marker for every member at that moment No per-request cost, reuses the store and its fail-closed behaviour One write per member; a member added later isn't covered, and a partial failure needs handling
    B. An organisation marker checked on every request via the token's org_id Covers late joiners at once A lookup on every request; relies on the claim, and whether SLM tokens carry it isn't established

    Recommendation: A.

    Decision needed, store outage: if the marker can't be written, deactivation still happens and the audit row records None, as change_password does today, so that user's old tokens keep working until they expire (up to 24 hours). Failing the deactivation would make SCIM deprovisioning return a 500 during an outage. Recommendation: keep today's behaviour, since deprovisioning should still apply, and the audit row shows the gap.

    Known limits: a token minted in the same second as the deactivation survives, as it does for a password change. Token kinds outside the marker are tracked in the follow-up linked below.
    Follow-up for other token kinds: #20446.

  2. added
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 1, 2026
  3. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    A third decision, from review of #20444: redis.conf sets allkeys-lru, so Redis can evict a revocation marker under memory pressure, and an evicted marker revives the tokens it revoked. This also applies to password changes today. The live setting has not been checked. Options: move the markers to a store that does not evict (a dedicated Redis database or instance with noeviction, or the database), or accept it. Recommendation: a store that does not evict, since a revocation that can silently undo itself is not one. This needs an owner call because it changes deployment configuration.

  4. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    An update on the store-outage question. #20444 now retries a failed marker write and raises, and the deactivation stays committed. But the failure doesn't reach the HTTP caller: the write runs in the dependency teardown after the route has answered, so the caller sees success and the error only reaches the server log. That was seen in a throwaway app on the venv's FastAPI version, not on a real route.

    After the retries fail, that user's existing token can stay live for up to 24 hours. Options, if that's not acceptable:

    Option Effect Cost
    A. Accept it: outage-only, logged at error level No new code A silent gap to the person deprovisioning
    B. Routes own their commit, so they can answer with an error The caller knows Changes the deactivate, delete and SCIM routes
    C. An account check on every request A deactivated user is refused even with no marker, which would also remove the eviction risk for them A database read per request
    D. A durable outbox for marker writes Retries outlive the outage New machinery

    Recommendation: B, since a person deprovisioning someone should be told it may not have fully taken effect. C is the strongest if the per-request read is acceptable, so it's worth measuring.

  5. 4 remaining items

  6. mrveiss commented on Nov 1, 2026

    @mrveiss
    OwnerAuthor

    Maintainer decision (2026-11-01): revocation markers move to a store that can't evict, a dedicated noeviction Redis or the database, whichever ships most simply through the builtin updater. The choice was left to the implementer. Observed: the live host runs allkeys-lru with a 6 GB limit and evicted_keys 0; the compose file has a 512 MB limit with the same policy.

    Chosen: the database.

    • Eviction policy applies to a whole Redis instance, so a noeviction store means a second Redis service that the updater, the install and compose all have to deploy and monitor. A table ships as an ordinary migration.
    • A marker in the same database as the user can commit in the same transaction as the deactivation. A failed commit then leaves no marker, and a marker can't be lost after a committed deactivation, for users of that database.
    • The SLM already keeps its own markers in a table, with the same only-goes-up rule.

    Cost: the request gate reads this on every authenticated request, which Redis made cheap. Redis stays as a rebuildable read cache in front of the table, so the table is the system of record and an evicted entry just means one database read. The design must be measured so it doesn't slow every request, and a miss must fail closed when the database can't answer, as today.

  7. removed
    needs-decisionBlocked on an owner decision; options and a recommendation are on the issue
    on Nov 1, 2026
  8. github-actions commented on Nov 1, 2026

    @github-actions
    Contributor

    Landed via the merge train (#20458, merge 0dbb02f5d4) via #20444

  9. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    Landed via the merge train (#20707, merge 1416e3d202) via #20499

  10. mrveiss commented on Nov 2, 2026

    @mrveiss
    OwnerAuthor

    Verified against main at the merge train (PR #20707), merge 1416e3d202. Only boxes with code evidence are ticked.

    AC Evidence
    A test establishes what a token issued before deactivation does today. delivered. tests/security/test_deactivated_user_token_20443.py: control test_a_live_users_token_is_admitted and test_a_deactivated_users_token_is_refused_once_the_change_commits; session variants test_a_session_opened_before_the_deactivation_is_refused.
    A token of a deactivated or soft-deleted user is refused on its next request (test), and reactivation behaviour is recorded. delivered. Refused: test_a_deactivated_users_token_is_refused_once_the_change_commits, test_a_soft_deleted_users_token_..., test_a_hard_deleted_users_token_...; SCIM path autobot-slm-backend/tests/api/test_scim_revocation_20443.py. Reactivation recorded: test_reactivation_does_not_revive_the_old_token_but_a_new_login_works. A failed marker answers 503, the change stays committed (test_revocation_routes_20443.py).
    A user of a deactivated or soft-deleted organisation gets the same answer (test). delivered. test_deactivated_org_members_token_20443.py (test_a_members_token_is_refused_and_another_organisations_member_is_untouched, org_member_revocation.py).
    The membership cache rows in #19670 are closed by this, or by making team lookups hide those users. NOT delivered. Not ticked: the merge only adds comments to tenant_groups_writers_19670_test.py; no evidence that the #19670 rows are closed or that get_user_teams hides these users.
  11. github-actions commented on Nov 8, 2026

    @github-actions
    Contributor

    Landed in #21020, merge 8e6ba8f15b

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