Repository navigation
Description
Part of #6886. Depends on #6898 (ID-JAG issuance) and the per-user rows of "User-keyed upstream storage behind the embedder option" (#7263) (and of "Re-authorization walks the full upstream chain instead of evaluating existing credentials" (#6831) for runner-built storage); uses the per-user revocation time (#6972). Related: #4122 (refresh-token rotation race across pods).
Problem: a grant lets a client get ID-JAGs for the user for days or weeks without the user present. If the company IdP disables the user in that time, nothing notices: the grant keeps working until it expires. A grant records the user, not an upstream session, and upstream tokens are stored per authorization session today, so the server cannot find the user's upstream refresh token from a grant.
Change:
- One upstream refresh token per user (through the per-user rows of "User-keyed upstream storage behind the embedder option" (User-keyed upstream storage behind the embedder option #7263), and of "Re-authorization walks the full upstream chain instead of evaluating existing credentials" (Re-authorization walks the full upstream chain instead of evaluating existing credentials #6831) for runner-built storage), from the most recent sign-in, independent of any one client signing out. Record its expiry: the IdP's
refresh_expires_inwhen it sends one, otherwise a configured maximum per IdP. - At ID-JAG issuance, and when deriving a child grant:
- if the recorded expiry has passed, refuse with
owner_action_requiredand record a per-user revocation (Per-user revocation time for grants issued by token exchange #6972) with that reason; no call to the IdP; - if the re-check interval has passed, refresh the upstream token first.
- if the recorded expiry has passed, refuse with
- Refresh rules:
- one refresh per user at a time across replicas, under a lease; the in-flight state is recorded before the IdP call;
- a request waiting for the lease re-reads its grant afterwards, so it returns the revocation reason if the lease holder revoked it;
- a lease timeout answers 503 with
Retry-Afterand revokes nothing.
- What the IdP answers:
- success: store the new token, rotated or not, and the time;
invalid_grantbefore the recorded expiry and after a clean previous refresh: per-user revocation withupstream_revoked; discard the upstream token;invalid_grantat or after the recorded expiry, or after an ambiguous previous refresh (this row wins when both apply): per-user revocation withowner_action_required; discard it. A refresh is ambiguous when one was in flight as the server crashed or lost the response, so it cannot know whether the IdP rotated the token;- network error or 5xx: 503 with
Retry-After; nothing revoked.
- The IdP must issue a refresh token at sign-in. Document and test, per supported IdP, what the sign-in must request (
offline_accessor its equivalent). With no refresh token, every issuance ends withowner_action_required, unless the operator has turned the re-check off for that IdP (off by default). - Configuration: the re-check interval; the maximum upstream refresh-token lifetime per IdP; the lease timeout; the per-IdP switch above.
- Audit:
upstream_recheck.refreshed,upstream_recheck.revoked, andupstream_recheck.refusedlog lines with the user, the IdP, and the outcome; never tokens.
Limits, documented: it catches an account disabled or grants revoked at the IdP within about one interval. It does not catch a plain sign-out at the IdP. ID-JAGs and access tokens already issued stay valid until they expire.
Acceptance:
- a disabled upstream account ends the user's grants at the next issuance after the interval, with
upstream_revoked; - a recorded expiry that has passed ends them with
owner_action_required, with no call to the IdP; - an unreachable IdP gives 503 and revokes nothing;
- concurrent issuances for one user across replicas make one IdP call;
- a crash between the IdP call and storing the result does not turn the next
invalid_grantintoupstream_revoked; - a client signing out does not end grants while the upstream token is valid.
Activity