Skip to content

Record how a token was admitted on Identity - #7287

Merged
jhrozek merged 5 commits into
mainfrom
admission-route
Nov 25, 2026
Merged

jhrozek merged 5 commits into
mainfrom
admission-route

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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.AdmissionRoute with three values: interactive, delegated, and the zero value (no route). Only TokenValidator sets it, and it is not serialized.
  • A route is assigned only on a validator bound to the embedded authorization server (WithEmbeddedAuthServerIssuer equal 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-empty tsid, no delegated-access marker, and no proof of a session-less mint (no act chain, no no_upstream_session).
  • delegated: the marker, no usable tsid, and a configured audience, so the token's aud was actually checked.
  • Everything else, including a token carrying both tsid and the marker, gets no route and is served exactly as before.
  • Introspected claims no longer set SessionlessGrant (see the user-facing section).
  • The route is set before upstream tokens are loaded, so the load context already carries it.
  • Architecture doc: the "Admission route" block in docs/arch/17-token-exchange-delegation.md.

Part of #6407

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

go vet ./pkg/auth/ and go 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 Identity as on an unbound validator apart from the route; a token with tsid and the marker served unchanged on bound and unbound validators; introspected claims getting neither a route nor SessionlessGrant; 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

File Change
pkg/auth/identity.go AdmissionRoute type and field
pkg/auth/token.go classifier, verifying-key provenance, middleware wiring
pkg/auth/token_test.go, pkg/auth/identity_test.go tests
docs/arch/17-token-exchange-delegation.md admission route section

Does 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 SessionlessGrant when the response named the embedded issuer and carried no_upstream_session or an act chain, which put it on Cedar's session-less claim path. Now introspected claims never get SessionlessGrant: 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

  • Narrower than the issue text. Part A of Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407 lists a sessionless value and a 401 for a token carrying both tsid and 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.
  • Embedders. A validator bound with WithEmbeddedAuthServerIssuer but without WithKeyProvider never 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.
  • Consumers compare for one value (== AdmissionRouteDelegated), never "not empty". The field doc says so.
  • Known gap, not changed here. An introspection response carrying a string tsid still makes loadUpstreamTokens load that session's upstream credentials, as it does on main. 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.
  • Audience required for any route. A bound validator with no configured audience gives no route, interactive or delegated, and serves the token as before. This goes beyond the RFC, which asks for the audience only on the delegated route, because aud is 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.
  • SessionlessGrant keeps 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):

tsid marker act chain or no_upstream_session audience route
non-empty string absent no any interactive
absent, empty or non-string present (any value) any configured delegated
anything else none

Steps, one commit each:

  1. Classification core: the type, the field, boundToEmbeddedIssuer, sessionlessProof (shared with isSessionlessGrant), the classifier, and its table test.
  2. Provenance: an unexported validateToken that reports whether claims are unverified (introspection), signed by some key, or signed by the in-process key; the route needs the last, SessionlessGrant needs either signed state. The exported ValidateToken is unchanged.
  3. Middleware wiring before the upstream load, without touching loadUpstreamTokens; end-to-end tests.
  4. Architecture doc.

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.

jhrozek and others added 4 commits November 24, 2026 22:33
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]>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 24, 2026 22:01
@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Nov 24, 2026
rdimitrov
rdimitrov previously approved these changes Nov 24, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. loadUpstreamTokens still loads upstream credentials for an introspected token with a string tsid, because it doesn't consult the route. Make sure #7263 keys that load on AdmissionRouteInteractive; until then this field protects nothing there.
  2. interactive is granted without an audience check while delegated requires one. A line in the AdmissionRouteInteractive doc comment saying so would help whoever consumes it for credential reads.

🤖 Reviewed with Claude Code

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.79245% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.98%. Comparing base (8d64314) to head (8abea5e).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/auth/token.go 86.79% 7 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 24, 2026
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]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 25, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@jhrozek
jhrozek merged commit 1082992 into main Nov 25, 2026
48 of 49 checks passed
@jhrozek
jhrozek deleted the admission-route branch November 25, 2026 10:39
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants