Repository navigation
Record how a token was admitted on Identity - #7287
Conversation
Part C of "Ownership-checked credential read for delegated tokens, keyed by user and routed provider" (#6407) needs to know how a request got in before it reads a user's stored credential: through an interactive sign-in or a delegated (marked) token. Add an AdmissionRoute type and field on Identity, and a classifier on the token validator that decides it from the validated claims. The classifier only answers on a validator bound to the embedded authorization server. Interactive means a usable tsid, no delegated-access marker and no proof of a session-less mint. Delegated means the marker without a usable tsid, and also requires a configured audience, so the token's aud was checked. Every other token, including one carrying both a tsid and the marker, stays unspecified and reads nothing. The proof of a session-less mint is the one isSessionlessGrant uses, so the two never disagree; the binding check and that proof move into helpers both share. Nothing calls the classifier yet; the middleware wiring follows. Co-authored-by: Mecatl <[email protected]>
The admission route and SessionlessGrant both say how a token was minted by the embedded authorization server. A validator bound to that server can also have an introspection URL, and the claims an introspection response returns are copied verbatim: a response naming the embedded issuer with no_upstream_session, tsid or the delegated-access marker would otherwise pass as if our server had signed it. ValidateToken now wraps an unexported validateToken that also reports how far the claims can be vouched for: not at all (introspection), a verified signature from some key set, or a verified signature from the embedded server's in-process key provider. Introspected claims never set SessionlessGrant and never get a route. The exported ValidateToken is unchanged. The route is stricter than SessionlessGrant: it also requires the in-process key. A key found only through the HTTP JWKS fallback, for example an operator-configured jwks URL, is not proof the embedded server signed the token, so such a token gets no route, while SessionlessGrant still accepts any verified signature. A validator bound to the embedded issuer without a key provider has no in-process key, so classifyRoute never returns a route for it. Co-authored-by: Mecatl <[email protected]>
The token validator now classifies every request it admits and puts the result on Identity, so later consumers (the delegated credential read, session binding) can key on how the token got in. The route is set before upstream tokens are loaded, so the load context already carries it. Validators not bound to the embedded issuer are unchanged: their route stays unspecified and they serve every token as before. A token that carries both a tsid and the delegated-access marker is served with an unspecified route, and upstream credentials are still loaded for it. Co-authored-by: Mecatl <[email protected]>
The auth middleware now records an admission route on the identity. Describe the route values, the conditions under which the validator sets them and how consumers must compare them in the delegated-access marker section of the token exchange architecture page. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Approve: recording how a token was admitted at the validator is the right place and the right shape.
Design: TokenValidator is the only code that sees both the verified claims and which key verified them, so classifying the route there (classifyRoute) is the correct owner. Every Identity built from a bearer token goes through Middleware, which the runner and vMCP both wire with the key provider and embedded issuer; the other Identity constructors leave the route at its zero value, which is the safe direction. Gating delegated on the in-process key, the embedded-issuer binding and a configured audience fails closed, and nothing changes on the wire or in config on upgrade. The one behaviour change, introspected claims no longer setting SessionlessGrant, is stated in the PR body and only affects opaque tokens the embedded server doesn't issue.
Non-blocking notes for the follow-up:
loadUpstreamTokensstill loads upstream credentials for an introspected token with a stringtsid, because it doesn't consult the route. Make sure #7263 keys that load onAdmissionRouteInteractive; until then this field protects nothing there.interactiveis granted without an audience check whiledelegatedrequires one. A line in theAdmissionRouteInteractivedoc comment saying so would help whoever consumes it for credential reads.
🤖 Reviewed with Claude Code
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7287 +/- ##
==========================================
+ Coverage 81.86% 81.98% +0.11%
==========================================
Files 915 922 +7
Lines 92868 93367 +499
==========================================
+ Hits 76029 76549 +520
+ Misses 16834 16813 -21
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The delegated route already needed a configured validator audience, so that the token's aud was checked. The interactive route did not, which left aud unchecked for an interactive token minted for another resource on the same authorization server. Require the audience for both routes; a validator without one gives no route and serves the token as before. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 8abea5e: still approve.
The only new commit, "Require an audience for the interactive route", moves the "audience was checked" requirement from the delegated branch to the top of classifyRoute, so interactive and delegated share one gate. That is the right place: a token minted for another resource on the same authorization server can no longer get an interactive route when the validator doesn't check aud. It fails closed, and since the route is only a hint, a token with no route is served exactly as before. There is no wire or config change. The only reclassification is that validators with an embedded issuer but no audience go from interactive to no route. The no-audience and whitespace-audience cases are tested.
Non-blocking, for #7263: thv run with an embedded auth server doesn't require --oidc-audience, so local setups without it silently get no interactive route. The operator and vMCP both require an audience. If #7263 keys the upstream-token load on the route, consider a startup warning or a hard requirement there so the failure is visible.
🤖 Reviewed with Claude Code
Summary
A delegated token (an access token from ID-JAG redemption that names a real user) has no
tsid, so the vMCP has no way to tell it apart from any other session-less token, and nothing downstream can decide to read that user's stored credential for it. Part C of "Ownership-checked credential read for delegated tokens, keyed by user and routed provider" (#6407), session binding in "vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user" (#6888), and the canonical-user rule in "User-keyed upstream storage behind the embedder option" (#7263) all need to know how a request got in. This PR adds that answer once, in the token validator. It is part A of #6407.Identity.AdmissionRoutewith three values:interactive,delegated, and the zero value (no route). OnlyTokenValidatorsets it, and it is not serialized.WithEmbeddedAuthServerIssuerequal to the validator's issuer), and only for a JWT verified with the embedded server's in-process key (WithKeyProvider). Introspected claims, and tokens verified only through the HTTP JWKS fallback, get no route.interactive: a non-emptytsid, no delegated-access marker, and no proof of a session-less mint (noactchain, nono_upstream_session).delegated: the marker, no usabletsid, and a configured audience, so the token'saudwas actually checked.tsidand the marker, gets no route and is served exactly as before.SessionlessGrant(see the user-facing section).docs/arch/17-token-exchange-delegation.md.Part of #6407
Type of change
Test plan
task test)task lint-fix)go vet ./pkg/auth/andgo test ./pkg/auth/pass at every commit.Classification is covered by a table test over every rule. Middleware tests cover: the route on each token shape; an interactive token producing the same
Identityas on an unbound validator apart from the route; a token withtsidand the marker served unchanged on bound and unbound validators; introspected claims getting neither a route norSessionlessGrant; a token signed with a key only the HTTP JWKS serves getting no route while the same claims signed with the in-process key do; and an unbound validator never writing the canonical-user key.Changes
pkg/auth/identity.goAdmissionRoutetype and fieldpkg/auth/token.gopkg/auth/token_test.go,pkg/auth/identity_test.godocs/arch/17-token-exchange-delegation.mdDoes this introduce a user-facing change?
One narrow one. On a validator bound to the embedded authorization server that also has an introspection URL configured, a token accepted through introspection used to get
SessionlessGrantwhen the response named the embedded issuer and carriedno_upstream_sessionor anactchain, which put it on Cedar's session-less claim path. Now introspected claims never getSessionlessGrant: an introspection response is the endpoint's word, not a signature this validator checked. Signed JWTs are unaffected, and so are validators not bound to the embedded issuer.Nothing reads the new route yet, so no request succeeds or fails differently because of it.
Special notes for reviewers
sessionlessvalue and a 401 for a token carrying bothtsidand the marker. Both were dropped: nothing in this phase reads a sessionless route, and a contradictory token that gets no route reads nothing, so the refusal added an error path without adding safety. Our server never mints such a token. The issue text will be updated to match.WithEmbeddedAuthServerIssuerbut withoutWithKeyProvidernever assigns a route, and a validator without a configured audience never assigns a route. The runner and vMCP always pass both the key provider and the issuer; an embedder that wants the delegated route must pass a key provider and an audience.== AdmissionRouteDelegated), never "not empty". The field doc says so.tsidstill makesloadUpstreamTokensload that session's upstream credentials, as it does onmain. Only the configured introspection endpoint can produce such a token, and the embedded server issues only JWTs. The gap closes only when user-keyed storage (User-keyed upstream storage behind the embedder option #7263) is enabled: then a non-interactive token gets a blank canonical user and storage refuses to read anything. Until that default flips, the gap stays open.audis otherwise never checked and an interactive token minted for another resource on the same authorization server would be accepted. Deployment note: a CLI setup of the embedded authorization server with no OIDC audience (thv run --from-config) gets no route, so it does no interactive reads once User-keyed upstream storage behind the embedder option #7263 lands. Vmcp and the operator already require an audience.SessionlessGrantkeeps accepting any verified signature (only introspection is excluded); the route is stricter on purpose because part C will read stored credentials on it.Implementation plan
Approved implementation plan
Rules (validator bound to the embedded issuer, JWT verified with the in-process key; otherwise no route):
tsidactchain orno_upstream_sessionSteps, one commit each:
boundToEmbeddedIssuer,sessionlessProof(shared withisSessionlessGrant), the classifier, and its table test.validateTokenthat reports whether claims are unverified (introspection), signed by some key, or signed by the in-process key; the route needs the last,SessionlessGrantneeds either signed state. The exportedValidateTokenis unchanged.loadUpstreamTokens; end-to-end tests.Decisions: marker counts by presence (D2); delegated needs a configured audience (D3); route needs the in-process key (D4); introspected claims get neither a route nor
SessionlessGrant(D1); no Cedar change.