Skip to content

Turn on subject resolution at ID-JAG redemption - #7356

Merged
jhrozek merged 7 commits into
mainfrom
gate-and-u1-proof
Nov 27, 2026
Merged

jhrozek merged 7 commits into
mainfrom
gate-and-u1-proof

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Stacked on "Read delegated credentials in upstream_inject" (#7355): the base branch is that PR's branch. Retarget this PR to main once that one merges.

An authorization server (AS-2) can resolve an ID-JAG's upstream subject to its own local user (subject_mode: resolve), and a gateway can read that user's upstream credential. The step between the two has been closed on purpose: every redemption from a resolve issuer was refused as subject_unknown by a compile-time gate (delegatedAccessEnabled = false), because the authorization server cannot see whether the gateway behind it handles a delegated token safely. The pieces that make it safe are in now: the resolver and the marked token ("Resolve ID-JAG subjects and issue marked tokens behind the gate" (#7262)), delegated session binding ("Bind delegated sessions to client and actor" (#7315)), user-keyed upstream storage ("Add user-keyed upstream token storage" (#7308), "Add per-user upstream credential reads" (#7323) and "Wire user-keyed upstream storage into the auth server" (#7332)) and the delegated credential read in upstream_inject (#7355). This PR removes the gate, as "Delegated access: turn on subject resolution at ID-JAG redemption" (#7247) asks, and proves the path they were built for:

  1. A user signs in once at the agent's authorization server (AS-1).
  2. An agent gets an ID-JAG for that user.
  3. AS-2 resolves the ID-JAG to its own local user and issues a short-lived delegated token.
  4. A vMCP calls GitHub with that user's GitHub token.

What changed:

  • Gate removed. The constant, checkSubjectModeGate, the startup WARN and the stale comments are deleted. A resolve redemption now goes from the actor-issuer check straight into resolution, actor policy and issuance. Namespaced redemptions take the code they took before.
  • Gate tests become reachability tests. A resolve issuer issues the resolved user's token, refuses an unknown subject with the ID-JAG unconsumed, and checks the actor after the actor-issuer allowlist. Tests that only pinned the closed gate are deleted.
  • In-process end-to-end test (pkg/vmcp/server): AS-1, AS-2 in resolve mode with user-keyed storage, and a vMCP with upstream_inject in front of a backend that records the Authorization header. The positive case asserts the exact header (Bearer gh-token-alice) and that the resolved user owns the GitHub row. Refusals each reach no backend and are asserted on their exact error: unknown user, another client or actor on the delegated session, a marked token re-exchanged, a two-element aud, cnf, a missing resource claim, GitHub disconnected (fails closed, tool hidden), a row owned by another user, a namespaced issuer, and a marked token at a validator with no audience. It also covers the first-connect order, and an expired GitHub row refreshed through the delegated read, shared with the interactive route, on memory and Redis storage.
  • HTTP-level tests (pkg/authserver): a resolved redemption that asks for offline_access gets no refresh_token and no scope; an ID-JAG redeems once, a replay is refused, and a fresh ID-JAG redeems; AS-1 ignores an unknown exchange parameter. The delegated agent flow test now runs AS-2 in resolve mode and checks the user and identity-link rows. Two handler-level tests pin the token shape (marker, no tsid) and that a synthetic subject never resolves.
  • Docs. docs/arch/17-token-exchange-delegation.md describes resolve mode as live, what a resolved token carries, and what a gateway needs before an embedder turns it on.

Closes #7247

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

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

The new and changed tests were run under -race on this stack (the delegated access, redemption, flow and resolution tests, and the tokenexchange package). The full task test is left to CI. Each commit builds on its own, and the end-to-end tests are skipped in the commit that adds them and run from the commit that removes the gate.

Changes

Area Change
pkg/authserver/server/tokenexchange Remove the gate, its warning and the stale comments (about 60 changed lines, mostly deletions); convert and delete the tests that pinned it
pkg/vmcp/server New end-to-end test for the delegated path
pkg/authserver HTTP tests for a resolved redemption, flow test in resolve mode, synthetic-subject test
docs/arch/17-token-exchange-delegation.md Resolve mode is live; gateway requirements

Does this introduce a user-facing change?

Yes, for embedders that set subject_mode: resolve on a trusted issuer.

Before: every redemption from a resolve issuer was refused with 400 access_denied / subject_unknown, and the server logged a startup WARN that resolution was not enabled.

After: when the ID-JAG's upstream_subject resolves to a local user, the server issues a token. It carries the local user as sub, the delegated-access marker and no_upstream_session, has no tsid and no refresh token, grants no scope (the response's scope member is empty and scp is empty), and lives at most five minutes. An ID-JAG can be redeemed once, so a client needs a fresh one for each token. The startup WARN is gone. Namespaced issuers behave as before.

Release note: embedders turning on subject_mode: resolve must upgrade every gateway replica first. An older replica binds a marked token's session the way it binds the user's interactive session. The gateway also needs user-keyed upstream storage on the authorization server and a credential reader. Mecatl must pin a release containing this change before it configures resolve.

Special notes for reviewers

  • Commit order. The end-to-end tests are skipped in "Add an in-process delegated access end-to-end test" and the skip is removed in "Turn on subject resolution at ID-JAG redemption", so every commit passes. The first two commits only depend on main.
  • Which backends are covered. Delegated access is tested here for upstream_inject backends only. The token-exchange, AWS STS, Entra OBO and XAA strategies get their delegated-route behaviour from "Route exchanges through shared subject tokens" and "Route XAA through shared ID token lookup", which are not in this stack, and nothing here tests a marked token at those backends.
  • No scope on redemption. fosite encodes "granted nothing" as an empty scope member, which RFC 6749 section 3.3 requires because it differs from a requested scope; omitting it would claim the requested scope was granted. vMCP's opt-in per-tool scope check reads a scope claim by default while this server emits scp, so a delegated token gets insufficient_scope on any tool with a scope requirement. That is unchanged here.
  • Startup checks. Starting with resolve still requires an OIDC first upstream. Nothing at the authorization server checks that user-keyed storage is on or that the gateway has a reader; the docs state it as a requirement on the gateway.
  • Where the end-to-end test lives. It is in pkg/vmcp/server because the vMCP harness and the AS-chain helpers it combines are test code in that package, and test code is not importable from pkg/authserver. It builds on the chain* helpers there. The two-server fixtures in pkg/authserver are a separate copy; converging them into one importable fixture would be its own change.
  • Not covered by these tests. A real SPIFFE actor token (the actor validator is a mock that accepts any token), Dex, a user who cancels the GitHub leg at first sign-in (NonFatalSecondaryLegs is not exposed through RunConfig), and more than one replica. The real-path check is Mecatl's kind test.

@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 27, 2026 16:27
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 27, 2026
jhrozek and others added 7 commits November 27, 2026 17:53
Pin the sessionless claims on resolved ID-JAG redemptions so issued tokens stay eligible for delegated admission, and check that the ID-JAG handler's issuance adds no refresh token and that redemption grants no scope.

Co-authored-by: Mecatl <[email protected]>
Guard against resolving synthetic sign-ins after an upstream switches to OIDC under the same name. A retained upstream-token row must not establish a local identity.

Co-authored-by: Mecatl <[email protected]>
Prove the delegated access path in process across AS-1, AS-2
(subject_mode: resolve with user-keyed upstream storage) and vMCP
(upstream_inject with the user credential reader): the redeemed token's
call reaches the backend with exactly Alice's GitHub token, and each
refusal reaches no backend.

Also cover the first-connect order (an ID-JAG refused before the user
signs in redeems after it), an expired GitHub row refreshed through the
delegated read on memory and Redis storage with the row shared by the
interactive route, and a row owned by another user.

The test lives in pkg/vmcp/server because the AS-chain helpers and the
vMCP credential harness it combines are test code in that package.

The tests are skipped while subject resolution is closed; the change
that turns it on removes the skip. They pass with it on, under -race.

Co-authored-by: Mecatl <[email protected]>
Redemptions from resolve issuers were refused as an unknown subject by
a compile-time gate while the pieces behind it landed. Those pieces are
in, so remove the gate, its startup warning and the stale comments.

The tests that pinned the closed gate become reachability tests: a
resolve issuer now issues the resolved user's token, refuses an unknown
subject with the ID-JAG unconsumed, and checks the actor after the
actor-issuer allowlist. The delegated access end-to-end tests are no
longer skipped.

Co-authored-by: Mecatl <[email protected]>
A resolve issuer's redemption issues no refresh token and grants no
scope, even when the client asks for offline_access, because a
redemption has no login session to refresh.

The ID-JAG is single use: presenting it again is refused as invalid_grant
and leaves the first token stored, while a fresh ID-JAG for the same user
redeems to an equivalent token. That is the retry Mecatl makes.

AS-1 ignores an unknown exchange parameter on the ID-JAG request,
neither refusing it nor copying it into the ID-JAG.

Co-authored-by: Mecatl <[email protected]>
AS-2 in the flow test now resolves the ID-JAG's upstream subject to a
local user, as a gateway does. The user signs in at AS-2 once through
the company IdP, and AS-2 runs with user-keyed storage.

The redeemed sub is the user that sign-in created, which the test
reads back from the user and provider-identity rows. The token also
carries the delegated-access marker and no_upstream_session, has no
tsid, and expires no later than the ID-JAG.

The memory and Redis subtests change AS-1's storage; AS-2 runs on
memory in both.

Co-authored-by: Mecatl <[email protected]>
Resolve mode is no longer refused at redemption, so replace the page's
description of the closed gate. Say what a resolved token carries (the
local sub, the delegated-access marker, no_upstream_session, no tsid,
no refresh token, the five-minute cap) and what a gateway needs before
an embedder turns resolve on.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek changed the base branch from credential-read-4-upstream-inject to main November 27, 2026 16:56
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 27, 2026
@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.68%. Comparing base (4d83959) to head (5b88b51).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7356      +/-   ##
==========================================
- Coverage   82.69%   82.68%   -0.02%     
==========================================
  Files         947      947              
  Lines       97369    97351      -18     
==========================================
- Hits        80519    80492      -27     
- Misses      16845    16854       +9     
  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.

@ChrisJBurns ChrisJBurns left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. With the gate gone, resolve redemptions still run every check before the ID-JAG is consumed, resolved tokens keep their limits, and gateways still fail closed.

One non-blocking suggestion for a follow-up: the server doesn't check at startup that a resolve issuer comes with user-keyed upstream storage (WithUserKeyedUpstreamStorage), which the new docs list as required. Without it, delegated calls fail closed and nothing is exposed, but the operator only finds out at request time. A startup validation error, or at least a warning, would surface the misconfiguration early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delegated access: turn on subject resolution at ID-JAG redemption

2 participants