Credential and session revocation (#838, #839) #850

Merged
Cordy merged 34 commits from revocation-838-839 into main 2026-10-06 16:59:57 +00:00
Owner

Closes #838, closes #839.

Spec: docs/superpowers/specs/2026-10-03-revocation-design.md. Plan: docs/superpowers/plans/2026-10-06-revocation.md. Each of the 8 tasks was implemented by a subagent and passed a task review; this was followed by a whole-branch review, one fix wave and one residual fix.

What changes

  • Local accounts: a per-account generation counter, bumped on password change, demote and delete. Delete, reset and demote end that person's browser sessions at once. Delete and reset also stop cached WebDAV credentials. Delete removes the person's app passwords. Promotion signs nobody out.
  • Own password change: signs out every other session and keeps the current one; app passwords keep working.
  • Per-request resolver replaces the add-only admin flag. Admin is recomputed on every request. Directory sessions and app passwords are re-checked every auth.directoryRecheck (default 5m, allowed range 30s to 1h). Accounts that are deleted or disabled are signed out: AD userAccountControl, Keycloak enabled, checked by user id. While the directory is unreachable, the last known state is kept and retried every 30s, with a 3s cap and dedupe per user.
  • LDAP credential cache: entries now expire after auth.ldapCacheTTL. During an outage a cached credential is still served. Binds are bounded to 10s.
  • OIDC Back-Channel Logout 1.0: POST /auth/backchannel-logout. It validates iss, aud, iat, events and nonce absence, and keeps a jti replay cache. JWKS refreshes have a cooldown so unauthenticated callers can't use Cairn to hammer the IdP. Body cap 64 KiB. Outside OIDC mode it answers 501.
  • Audit: auth-sessions-revoked, auth-directory-change. "Signed in now" counts only valid sessions.
  • Users & access shows both recheck intervals read-only. Docs (deployment, users-access, local-accounts, account, admin-policy) and the CHANGELOG are updated (v0.6.318, security fix).

Verification

  • go vet, go test ./... (53 packages), -race on auth/api/spaces/config, and the web tests all pass.
  • Mokapi AD re-run of the #838 table, with both settings at 30s:
Step Basic admin WebDAV Session admin Session
baseline 200 207 200 200
removed from admin group, +35s 403 207 403 200
password changed, old pw +35s 401 401 403 200 (documented, #848)
deleted, +35s 401 401 401 401

Not in this PR

  • #848: an AD or Keycloak password change doesn't end browser sessions.
  • #849: retryable app-password removal on delete.
  • #846: account-sources docs.
  • #845: CAEP.
  • The oidc-stdlib variant branch would answer 501 on back-channel logout until it adds a verifier.
Closes #838, closes #839. Spec: `docs/superpowers/specs/2026-10-03-revocation-design.md`. Plan: `docs/superpowers/plans/2026-10-06-revocation.md`. Each of the 8 tasks was implemented by a subagent and passed a task review; this was followed by a whole-branch review, one fix wave and one residual fix. ## What changes - **Local accounts:** a per-account generation counter, bumped on password change, demote and delete. Delete, reset and demote end that person's browser sessions at once. Delete and reset also stop cached WebDAV credentials. Delete removes the person's app passwords. Promotion signs nobody out. - **Own password change:** signs out every other session and keeps the current one; app passwords keep working. - **Per-request resolver** replaces the add-only admin flag. Admin is recomputed on every request. Directory sessions and app passwords are re-checked every `auth.directoryRecheck` (default 5m, allowed range 30s to 1h). Accounts that are deleted or disabled are signed out: AD `userAccountControl`, Keycloak `enabled`, checked by user id. While the directory is unreachable, the last known state is kept and retried every 30s, with a 3s cap and dedupe per user. - **LDAP credential cache:** entries now expire after `auth.ldapCacheTTL`. During an outage a cached credential is still served. Binds are bounded to 10s. - **OIDC Back-Channel Logout 1.0:** `POST /auth/backchannel-logout`. It validates iss, aud, iat, events and nonce absence, and keeps a jti replay cache. JWKS refreshes have a cooldown so unauthenticated callers can't use Cairn to hammer the IdP. Body cap 64 KiB. Outside OIDC mode it answers 501. - **Audit:** `auth-sessions-revoked`, `auth-directory-change`. "Signed in now" counts only valid sessions. - **Users & access** shows both recheck intervals read-only. Docs (deployment, users-access, local-accounts, account, admin-policy) and the CHANGELOG are updated (v0.6.318, security fix). ## Verification - `go vet`, `go test ./...` (53 packages), `-race` on auth/api/spaces/config, and the web tests all pass. - Mokapi AD re-run of the #838 table, with both settings at 30s: | Step | Basic admin | WebDAV | Session admin | Session | |---|---|---|---|---| | baseline | 200 | 207 | 200 | 200 | | removed from admin group, +35s | 403 | 207 | 403 | 200 | | password changed, old pw +35s | 401 | 401 | 403 | 200 (documented, #848) | | deleted, +35s | 401 | 401 | 401 | 401 | ## Not in this PR - #848: an AD or Keycloak password change doesn't end browser sessions. - #849: retryable app-password removal on delete. - #846: account-sources docs. - #845: CAEP. - The oidc-stdlib variant branch would answer 501 on back-channel logout until it adds a verifier.
Final review finding 1 (critical): app passwords survived account deletion
and a re-created name inherited them.

- Local account delete removes that user's app passwords.
- App-password requests carry Source "app"; the resolver requires a config
  user or local account to exist, and re-checks anyone else against the IdP
  with the directory-session machinery (interval, per-user dedupe, 3s cap,
  outage keeps the last known answer, 30s retry).
- A directory rejection also deletes the user's app passwords (OnReject).

Finding 7: demoting a non-admin no longer revokes sessions or writes an
audit row.
Final review finding 2: a directory username that differs from the lookup
key read as a deletion and signed everyone out.

- LDAP Recheck retries through the login filter when the UsernameAttr
  search finds nothing; only zero on both is exists=false, more than one is
  still an error.
- OIDC: ResolverConfig.Recheck gains the session's sub; with one present the
  Keycloak user is fetched by id (GET /users/{id}, 404 = gone) via the new
  spaces.Manager.UserStatusByID. Sessions without a sub and app-password
  users keep the username lookup.
Final review finding 3: bind used context.Background, so during a directory
outage every refill waited for go-ldap's 60s default and stalled whole
WebDAV mounts. The bind now runs under a 10s context (dial timeout and
connection timeout armed like Recheck), failing fast into the outage rule
that serves the cached credential.
Final review finding 4: valid (Resolver.Valid, which reads the local store)
ran under Sessions.mu, so a local-store write in progress during an admin
page load stalled every session lookup. Snapshot live entries under the
lock, release it, then filter.
Final review finding 8: a failed directory re-check now logs a WARN naming
the user, source and error, at most once per user per 10 minutes
(ResolverConfig.Logger, wired to the server log).

Finding 11: the back-channel logout jti replay cache holds at most 10000
entries; once full of live entries (after pruning expired ones) a new token
gets the generic 400 instead of evicting a live jti.
Final review finding 12.
Final review finding 9: Users & access printed Go durations ("every 5m",
"alle 5m"). The pure render helper now formats them per locale with
singular and plural units: "every 5 minutes", "alle 5 Minuten",
"toutes les 5 minutes", "ogni 5 minuti", "1 minute 30 seconds".
Final review findings 5, 6, 10 and 13:
- Demotion ends browser sessions; WebDAV and app passwords keep working
  without administrator rights. Delete stops WebDAV and removes app
  passwords; a reset stops the old password, app passwords stay.
- deployment.md: app passwords follow their account; a directory-side
  password change does not end browser sessions (out of scope, documented).
- auth.users accounts are never deleted, reset or locked out by the
  dashboard; a same-named Remove admin can end their current sessions.
- Spec: 4.1 only demotion bumps the generation (admin is per request);
  4.2 app-password liveness; out-of-scope note for directory password
  changes. CHANGELOG line for app passwords removed on delete.
docs: spec 4.2 matches app-password re-check by id (#838)
All checks were successful
ci / test-and-build (pull_request) Successful in 2m48s
3756d1a680
Cordy merged commit 427cc4e17e into main 2026-10-06 16:59:57 +00:00
Cordy deleted branch revocation-838-839 2026-10-06 17:00:02 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#850
No description provided.