Skip to content

User-keyed upstream storage behind the embedder option #7263

Done

Description

@jhrozek

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
    tsid passed 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 UserID is the canonical user before
    returning it, and before any expiry check or refresh. A single read of
    another user's row returns ErrInvalidBinding. 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 UserID or nil tokens are refused.
  • Storage lifetime: the token's ExpiresAt plus 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 an Identity in the context.
  • Unwrap and ConsumeAssertionJWT are 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's sub) in the load context only for a token from the embedded
    authorization server (WithEmbeddedAuthServerIssuer set and equal to the
    validator's issuer) that also carries tsid (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 InProcessService built 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 UserCredentialReader with
    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
    own InProcessService over the wrapped storage, sharing the refresher (one
    deduplication for all refreshes), and calls GetValidTokensForUser for 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 UserID returns
    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 UserID or nil tokens are refused. A token with no
    expiry has no storage TTL; one with an expiry keeps ExpiresAt + 30 days.
    The Redis key escapes the user ID.
  • A token not from the embedded issuer, carrying tsid and the sub of a
    user with rows, reads nothing and the request is not failed by it.
  • Startup with the field: the wrapper is outermost; Unwrap and
    ConsumeAssertionJWT work.
  • 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.
  • ResolveUpstreamTokenRowID returns 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.

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

  1. added
    needs-triage
    on Nov 24, 2026
  2. removed
    needs-triage
    on Nov 24, 2026
  3. jhrozek commented on Nov 26, 2026

    @jhrozek
    ContributorAuthor

    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).

  4. jhrozek commented on Nov 26, 2026

    @jhrozek
    ContributorAuthor

    This was done in PR #7332

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions