Repository navigation
Description
Part of "Delegated client access to a user's connections" (#6406).
Why. Upstream connections (a user's GitHub token, say) are stored under
the login session that created them, upstream:{tsid}:{provider}. A token with
no tsid, such as the access token a scheduled agent gets from ID-JAG
redemption, finds nothing, even when the user connected GitHub at the gateway.
A user's second client also has to connect every provider again, because its
login has a new tsid ("Re-authorization walks the full upstream chain instead
of evaluating existing credentials" (#6831)).
This issue lets an embedder that builds the authorization server in Go store
connections per user, so both paths find the same row. It is off by default.
Deployments built by the runner or the operator are unchanged here; they get
the same storage in "Re-authorization walks the full upstream chain instead of evaluating existing credentials" (#6831).
What changes
Storage (a wrapper in pkg/authserver/storage, applied inside
authserver.New as the outermost layer when a new config field is set; zero
value off; an embedder sets it through NewEmbeddedAuthServerWithStorage):
- Rows are keyed
upstream:user:{userID}:{provider}(user ID escaped). The
tsidpassed in is ignored. A user's second client reuses their connections
instead of running each provider's login again. - Every read checks that the row's
UserIDis the canonical user before
returning it, and before any expiry check or refresh. A single read of
another user's row returnsErrInvalidBinding. A bulk read skips it and
logs at ERROR with the expected user, the stored user and the provider. The
chain walk then treats that provider as not connected and runs its leg
again, and the new row replaces the bad one. - Writes with an empty
UserIDor nil tokens are refused. - Storage lifetime: the token's
ExpiresAtplus 30 days; a token that never
expires (a GitHub OAuth App) gets no storage expiry. Today such rows go away
with the 7-day session bound. - A canonical user missing from the context is an error
(ErrNoCanonicalUser), never a fallback to some other key. - The wrapper reads the canonical user only from the authorization server's
own context key (serveridentity), never from anIdentityin the context. UnwrapandConsumeAssertionJWTare forwarded, so remembered consent, the
DCR store, device codes and client lookups keep working.- The field's doc comment says not to enable it over storage that already
keys rows by user.
Validator (pkg/auth/token.go):
- When it loads upstream tokens, the validator puts the canonical user (the
token'ssub) in the load context only for a token from the embedded
authorization server (WithEmbeddedAuthServerIssuerset and equal to the
validator's issuer) that also carriestsid(an interactive login). For
any other token, user-keyed storage finds no user
and the validator loads nothing, quietly: no error, no 401 caused by it. - Storage that is not user-keyed sees no change: the context value is
ignored, and loading works exactly as today.
Refresh grants (the check "Refuse refresh grants whose upstream credential is
dead" (PR #6930) added), when the field is on:
- Checks only the identity provider's row (the first upstream).
- Refuses the grant when that row is absent (including deleted during the
refresh), has no refresh token, belongs to another user, or the identity
provider rejects the refresh; also when there is no canonical user. - Grants on a transient failure, with one WARN.
- Refreshes through its own
InProcessServicebuilt on the shared refresher,
inside today's timeout. - Deletes nothing.
- Keeps today's early return for a session without a
tsid(a redemption
issues no refresh token). - With the field off, the guard is exactly today's.
Only when the field is on: the guard's canonical user, the refresher setting
the user from the row it refreshes, and the DCR refresh-token carry-forward
change below. With the field off, none of these run.
Carry-forward: with the field on, the callback's DCR refresh-token
carry-forward never copies an old refresh token onto a row other clients
share.
The callback's chain identity check is unchanged. Under user keying it cannot
see another user's row (the wrapper skips it), so the skip-and-log above
replaces it.
Reader (pkg/auth/upstreamtoken):
- New interface
UserCredentialReaderwith
GetValidTokensForUser(ctx, userID, provider), implemented by
InProcessService. It sets the canonical user, reads one provider for one
user, and refreshes an expired row with the existing deduplication. - No row, a placeholder row with no tokens, or a refresh rejected with
invalid_grant: a defined "needs authorization" error. Storage errors and
transient refresh failures: infrastructure errors. Another user's row:
ErrInvalidBinding. - In this issue its only caller is the refresh-grant guard, which builds its
ownInProcessServiceover the wrapped storage, sharing the refresher (one
deduplication for all refreshes), and callsGetValidTokensForUserfor the
identity provider's row. The vMCP strategies use it in "Ownership-checked
credential read for delegated tokens, keyed by user and routed provider"
(Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407).
No storage interface changes. No change to the empty-expected
compare-and-swap contract (types.go).
Acceptance (in-process, memory and miniredis):
- Two clients of one user share one connection; re-authorization skips a
connected provider. - The owner check runs before refresh. A row with no
UserIDreturns
ErrInvalidBinding. A placeholder row returns(nil, nil). - An owner-check contract test runs against both decorated stores (memory
and Redis). The contract suite from "Compare the owner on upstream token
reads" (PR Compare the owner on upstream token reads #7219) can be reused for it. - Synthetic-subject (synthesis-mode) users are still served: their rows are
read only by that user. - A bulk read skips another user's row and logs at ERROR; the chain walk then
runs that leg again. - Writes with an empty
UserIDor nil tokens are refused. A token with no
expiry has no storage TTL; one with an expiry keepsExpiresAt+ 30 days.
The Redis key escapes the user ID. - A token not from the embedded issuer, carrying
tsidand thesubof a
user with rows, reads nothing and the request is not failed by it. - Startup with the field: the wrapper is outermost;
Unwrapand
ConsumeAssertionJWTwork. - The guard cases above, including a hung identity provider cut off by the
timeout, and "the guard deletes nothing". - With the field off, over storage that reads the canonical user, the guard,
the refresher and the callback behave exactly as today. - The carry-forward never copies an obsolete refresh token onto a shared row.
ResolveUpstreamTokenRowIDreturns the user-key row ID.- The reader cases above.
- Storage without the field, and runner-built storage, are untouched.
Depends on. Nothing.
Not in this issue.
- User keying for runner-built and operator-managed deployments, migration of
existingtsidrows, the refresher's conditional delete, reconnecting a
provider, and dropping one dead provider instead of failing the request:
"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). - The tests that one upstream identity never maps to two users: "Test that one
upstream identity never maps to two authorization-server users" (Test that one upstream identity never maps to two authorization-server users #6980). - The kind test harness (recording every backend call, two-upstream login):
"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). - Refresh serialized across replicas: "Handle multi-pod refresh token rotation
race condition" (Handle multi-pod refresh token rotation race condition #4122). thv vmcp serveandthv vmcp validatecallingValidateAuthServerIntegration
(carried over from "Add upstreamCredentialScope opt-in and enforce its issuer
trust" (Add upstreamCredentialScope opt-in and enforce its issuer trust #6403)): user-keyed storage does not need it, so it ships as its own
change.
Release notes. New opt-in user-keyed upstream storage for Go embedders;
no change for existing callers. Enabling it ignores existing session-keyed
rows (users connect again), keeps rows when a token is revoked, and keeps
tokens that never expire without a storage TTL. Do not enable it over a
storage layer that already keys rows by user: rows would be keyed twice and
deletes would find nothing.
Activity
Add user-keyed upstream token storage (#7308)
jhrozek commentedon Nov 26, 2026
I'm dropping the bulk-read provider filter from this issue: the lines saying the vMCP loads only the providers its backends are configured for, and the matching test.
It was added as a mitigation for a design review point: with rows keyed by user, a stolen interactive token, or a client the user approved once, would get every connection the user has. For one authorization server that doesn't hold up. Rows are already limited to that server's upstreams by its storage key prefix, and the interactive sign-in walks all of them anyway. The filter also limits loading, not use, since a loaded token only reaches the strategies of this resource's backends. Deriving the set from the vMCP's backend auth strategies turned out to be fragile: discovered outgoing auth, a missing default strategy or a new strategy type could each silently drop a provider a backend needs, and the validator had to treat "everything filtered out" differently from "no connection".
The concern does come back once rows are shared between authorization servers or held by a central one. It's recorded there: each server's load is then limited to its own upstream list, and which client may use which connection is client scope in "User-owned upstream credential storage (RFC): shared rows, account binding, client scope, and lifecycle" (#6885).
jhrozek commentedon Nov 26, 2026
This was done in PR #7332