Repository navigation
Description
Problem: When the gateway's authorization server (AS-2) redeems an ID-JAG, it cannot say which of its own users the ID-JAG is for. Today the issued token's sub is always <ID-JAG iss>#<sub> (claimnames.QualifySubject in id_jag_handler.go). The gateway cannot find the user's stored connections, and no token can name a real user yet.
This issue makes redemption resolve the ID-JAG's subject to a local user and, when everything checks out, issue the delegated-access marker that lets the gateway read that user's connections.
Scope: embedded mode, ID-JAG redemption. "Embedded" is defined by approval, not by who runs the gateway. AS-2 approves redemptions implicitly for the issuers, clients and resources its administrator configured, and reads no per-user approval record. AS-2 and the issuer of the ID-JAG (AS-1) sign users in through the same company identity provider. A gateway that shares the identity provider but needs each user's approval is external mode, for example a gateway the client's operator does not run (Mecatl's external gateway, "Phase 3, Slice 5: External gateway — Agents use a gateway Mecatl doesn't run, with no extra login step" (stacklok/mecatl#2810)). A valid mapping is not permission in general. In external mode each client also needs the user's approval: "Delegated access: user approval at an external gateway" (#7158).
Design home: "User-owned upstream credential storage (RFC): shared rows, account binding, client scope, and lifecycle" (#6885); the delegated-access proposal, sections 2.1 (resolver), 2.2 (actor), 3 (configuration), 4 (rollout) and 11 (open questions), and its issue ledger (wave 3, security constraints 5 to 7 and 9). Mecatl's flow: credentials-and-lifecycle.md step (8) and "Error reasons"; how AS-2 resolves the user.
Depends on:
- "Delegated access: subject resolver and actor policy packages" (Delegated access: subject resolver and actor policy packages #7157, the old part 1).
- The refusal half of "Add a delegated-access marker that gates credential lookup for approved delegated tokens" (Add a delegated-access marker that gates credential lookup for approved delegated tokens #6404). A marked token must be refused as a subject or actor token before any marked token exists.
- "Gate ID-JAG by issuer assertion types" (PR Gate ID-JAG by issuer assertion types #6678) changes the same trusted-issuer configuration. Rebase onto it once it merges.
The work is split into four sub-issues, in this order: "Delegated access: subject mapping setting and code gate for ID-JAG issuers" (#7244); "Delegated access: actor checks at ID-JAG redemption" (#7245); "Delegated access: resolve the ID-JAG subject and issue the marked token behind the gate" (#7246); and "Delegated access: turn on subject resolution at ID-JAG redemption" (#7247). The first three merge before the storage prerequisites listed under "Gate", behind the code gate, because resolution and the marker stay unreachable in code until the last one removes it. This issue closes with the last one.
The flow
(1) user ── login ──> AS-1 ──────────────> AS-1 access token
(7) broker ── RFC 8693 at AS-1 ──> AS-1 ──> ID-JAG
{ iss: AS-1, aud: AS-2, client_id: <broker's client at AS-2>,
sub: <AS-1 user>, upstream_subject: {iss: <IdP>, claim, value},
act: {iss: <ActIssuer>, sub: <agent>}, resource: <vMCP>, jti, exp }
(8) broker ── RFC 7523 jwt-bearer at AS-2 ──> AS-2
assertion = ID-JAG, resource = <vMCP> [, authorization_details: the one-call narrowing]
AS-2 runs the checks below, then mints:
{ iss: AS-2, sub: U, aud: <vMCP>, client_id, act (copied),
https://toolhive.dev/claims/delegated_access, no_upstream_session, exp }
(9) broker ── tools/call + token ──> vMCP ── reads (U, routed provider) ──> upstream
Before (8) can resolve, the user has signed in at AS-2 through the same identity provider. That sign-in creates U and a provider-identity row for (identity-provider upstream, subject). Then the user connected the upstream the tool needs, for example GitHub, whose row the callback writes under the same U.
AS-2 sees only the ID-JAG. It never sees the AS-1 access token, the broker's refresh token or the agent's credential.
Configuration
Two settings, set only from Go by embedders (json:"-", like ActorProfile): config files and the CRD cannot set them. Per trusted issuer, on JWTBearerGrantPolicy, and also on JWTBearerIssuerPolicyRunConfig so applyJWTBearerPolicies copies them. Tracked in "Delegated access: subject mapping setting and code gate for ID-JAG issuers" (#7244).
-
subject_mode:namespaced(default, today'siss#sub) orresolve. A Go zero value never selectsresolve.resolvealso makes the token carry the delegated-access marker. -
actor_issuers:act.issvalues accepted besides the ID-JAG's owniss.
No setting names the user's identity provider or the claim. The ID-JAG's upstream_subject is accepted only when its issuer and claim are the issuer and subject claim of AS-2's own sign-in upstream (the first upstream, OIDC), which the resolver already takes. The redemption allow is the existing client checks (rows 1, 6 and 14). Settings considered and left out until something has a consumer: where the subject is read from (issuer_claim, in "Delegated access: tokens and actors from third-party issuers" (#7159)), a separate marker opt-in, the CRD fields.
Validation and startup (each with a test):
-
resolvetogether withsubject_bindingsis refused. -
resolveoractor_issuerson anamespacedissuer is refused. -
resolveon an issuer that accepts plainjwt_beareris refused. An emptyaccepted_assertion_typesmeans both, so aresolveissuer must set[id_jag]. -
resolvewhen AS-2 has no identity-provider upstream is refused: resolution could never succeed. - AS-2's own issuer as a trusted issuer is already refused for every issuer today.
What AS-1 must send (a ToolHive AS-1, configured by the embedder):
- The target lists
upstream_subjectinrequired_subject_claims, so every ID-JAG carrieshttps://toolhive.dev/upstream_subject. Without it, issuance refuses withupstream_subject_missingrather than minting an ID-JAG that AS-2 cannot resolve. - The actor validator registration's
ActIssueris listed in AS-2'sactor_issuersfor AS-1. ToolHive refuses anActIssuerequal to its own issuer (validateActIssuer), soact.issnever equals the ID-JAG'sissfor a ToolHive AS-1. - AS-1's ID-JAG lifetime is long enough for the broker to redeem it and for the token AS-2 issues, which is capped at the ID-JAG's
exp. Relevant for the short per-client lifetime in "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061).
Checks at redemption
In this order. Steps 1 to 8 exist today; the rest are new or changed. Every refusal happens before the ID-JAG's jti is used up (step 15), so a refused or failed redemption never burns the ID-JAG. One exception is a replay, which step 15 refuses.
| # | Check | Today | This issue |
|---|---|---|---|
| 1 | The client is registered for the jwt-bearer grant (explicit-grant clients) | yes | unchanged |
| 2 | Assertion form; signature, typ, iss, aud, time claims |
yes | unchanged |
| 3 | aud: an array has exactly one element |
done: "Refuse ID-JAGs with a multi-valued aud" (#7204) | unchanged |
| 4 | The issuer is enabled for the grant | yes | unchanged |
| 5 | jti present |
yes | unchanged |
| 6 | client_id claim equals the authenticated client |
yes | unchanged |
| 7 | Assertion age | yes | unchanged |
| 8 | Resource against the resource claim |
done: "ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted" (#6892) | unchanged |
| 9 | Effective actor: the outermost act; if it has no iss, the token's iss (Okta); a missing or malformed act is actor_denied |
act copied, not checked |
new for resolve issuers ("Delegated access: actor checks at ID-JAG redemption" (#7245)); namespaced issuers unchanged |
| 10 | act.iss equals the ID-JAG's iss or is in actor_issuers; anything else is refused before the policy runs |
no | new for resolve issuers |
| 11 | Actor policy (from the sub-issue) on the effective actor. The default policy is built once per trusted issuer from its iss and actor_issuers, so it performs row 10's check; an embedder's Policy may check more. A policy error means it could not decide and returns server_error |
no | new for resolve issuers |
| 12 | Resolve the subject to U (resolve issuers, from upstream_subject) |
iss#sub |
new, see below ("Delegated access: resolve the ID-JAG subject and issue the marked token behind the gate" (#7246)) |
| 13 | (no separate allow) the client is bounded by rows 1, 6 and 14 | subject_bindings by subject |
subject_bindings is refused together with resolve; namespaced issuers keep it |
| 14 | The client's own audiences | done: access_denied with resource_denied, no resource in the description ("Add reason codes to redemption refusals" (#7193)) |
unchanged |
| 15 | Use up the jti (atomic across replicas through the assertion store) |
yes | unchanged; stays after every refusal |
| 16 | Lifetime bound | ID-JAG exp |
plus the marker cap |
Resolution (step 12):
ID-JAG iss = AS-1
upstream_subject = {iss: IdP, claim, value} IdP and claim must be AS-2's sign-in upstream's
│
Ref{IdP, claim, value} ──► Resolver ──► U
- Parse
https://toolhive.dev/upstream_subjectas{iss, claim, value}. A missing or malformed claim is refused. -
issmust be the issuer of AS-2's identity-provider upstream (the first sign-in leg), andclaimthat upstream's subject claim. Otherwise the redemption is refused asinvalid_grantwithinvalid_assertion. - Call the
ResolverwithRef{iss, claim, value}. The standalone resolver mapsissto the identity-provider upstream with that issuer and reads its provider-identity row. Rows are written only on the first sign-in leg, so an issuer from a later leg, such as GitHub, never resolves. -
ErrUnknown(no row, or the row's user is gone) andErrAmbiguousare refused.ErrUnavailablereturnsserver_error, neverinvalid_grant. Because step 15 has not run, the ID-JAG is not used up, so a client that re-submits it while it is valid can succeed. Mecatl's broker never re-submits; it mints a new ID-JAG, which also works. A resolver that returns an empty user with a nil error is treated asErrUnknown. - Embedded mode: approval is implicit. No approval record is read; the client is bounded by rows 1, 6 and 14.
DPoP:
- An ID-JAG that carries
cnfmust not become an unbound bearer token. Done for every issuer by "Refuse unauthenticated ID-JAG clients and cnf-bound assertions" (Refuse unauthenticated ID-JAG clients and cnf-bound assertions #7214).
Refusals and reason codes
Each refusal puts the reason code from "Authorization server: reason codes in error_description for ID-JAG redemption refusals" (#7030) at the start of error_description. If #7030 has not landed yet, the pull request that adds a refusal adds its row to #7030's table.
The error code says whether a new ID-JAG can help, following draft -06 §4.4.3: invalid_grant means the ID-JAG failed a validation rule, and a re-issued one may succeed; access_denied means the ID-JAG is valid but this user, client or actor is not authorized here, and a re-issued one will not help. The reason code only refines the error code.
| Refusal | error |
Reason code |
|---|---|---|
aud array with more than one element |
invalid_grant |
invalid_assertion |
act.iss not allowed |
access_denied |
actor_denied |
| Actor policy denies | access_denied |
actor_denied |
upstream_subject missing or malformed |
invalid_grant |
invalid_assertion |
upstream_subject issuer or claim is not AS-2's sign-in upstream's |
invalid_grant |
invalid_assertion |
| Unknown or ambiguous user | access_denied |
subject_unknown (-06 §4.4.3: the user "lacks a … provisioning record") |
| The client's audiences do not cover the resource | access_denied |
resource_denied (-06 §4.4.1: MUST be access_denied "if none of the resources are acceptable"; done in #7193) |
An ID-JAG with cnf, for every issuer |
invalid_grant |
invalid_assertion (done in #7214) |
| Resolver unavailable | server_error (or 503) |
none |
| Actor policy could not decide (it returned an error) | server_error (or 503) |
none |
| Resolution or marker reached while the gate is closed | access_denied |
subject_unknown (the client sees the same as an unmapped subject; the server logs the gate at WARN once) |
The actor checks (rows 9 to 11) run only for resolve issuers. A namespaced issuer keeps today's behaviour: an ID-JAG without act (for example a user-only cross-app access ID-JAG) still redeems, and existing deployments need no actor_issuers.
- Document what the default actor policy does not check, in the pull request that wires it in. It checks only the actor's issuer, so it does not restrict actors per subject or per client: any
act.subat an allowed issuer passes, anactwithoutissis checked as the token issuer, and under theclientsource every client of the token issuer passes. Clients are bounded separately, by the client checks (rows 1, 6 and 14), and a finer check needs anotherPolicy. Say inEvaluate's doc that it trustsRequest.Actorto come fromactor.Effectivewith the sameTokenIssuerandClientID, and does not re-check a hand-builtActor. Both sentences were left out of "Delegated access: subject resolver and actor policy packages" (Delegated access: subject resolver and actor policy packages #7157) because nothing calls the policy yet.
Mecatl's step (8) was written against draft -04, where its check 6 refused with invalid_target and an unmapped subject in embedded mode with invalid_grant and invalid_assertion. "docs(agent-identity): follow ID-JAG -06 for AS-2 redemption errors" (stacklok/mecatl#2825) updates it to this table: check 6 becomes 6a (the requested resource is the claim's, else invalid_target), 6b (the client's registered audiences cover the resource, else resource_denied) and 6c (the actor, else actor_denied), and an unknown user is subject_unknown. Mecatl's broker already fails the call on an access_denied it does not know, so no Mecatl outcome changes, and it no longer retries these refusals with a new ID-JAG, which could never succeed.
Each refusal is logged with the issuer, the client and the reason, never the subject, the jti or any claim value.
The issued token and response
-
subis U.issis AS-2.audis the granted resource.client_idis the redeeming client. -
actis copied unchanged (Mecatl: the agent instance, so every call is attributable to it). -
no_upstream_sessionis kept, so the interactive upstream-token path never serves this token. - No
tsidand no refresh token. -
expis the earliest of: the configured lifetime, the ID-JAG'sexp, and the marker cap (a few minutes) for a marked token, whateverdelegationLifespansays. - Dropped from this issue. Granted
authorization_detailsin the response belongs to "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061).scopeis not needed: the broker sends none, and RFC 6749 section 5.1 lets the authorization server omit it.
The delegated-access marker (issuance; moved here from "Add a delegated-access marker that gates credential lookup for approved delegated tokens" (#6404))
The marker's definition (https://toolhive.dev/claims/delegated_access in pkg/authserver/claimnames, presence only, honoured only for the embedded issuer, internal) and its refusal as a subject or actor token are in "Add a delegated-access marker that gates credential lookup for approved delegated tokens" (#6404), which lands first.
- Issued only at ID-JAG redemption, only for
resolveissuers (resolveimplies the marker), and only after steps 3 to 13 have passed: the subject resolved to a local user, the client check, the actor policy, and (in external mode, later) an approval. - Never issued at login, and never merely because ordinary delegation,
may_act, a delegate-client exemption, wildcard or rule actor matching ("Reduce delegate-client provisioning cost: TrustedIssuer actor matching and client-assertion auth" (Reduce delegate-client provisioning cost: TrustedIssuer actor matching and client-assertion auth #6321)) or a CEL match succeeded. - Never issued for a synthetic subject. Synthetic identities have no provider-identity row, so they cannot resolve; a test pins it.
- Terminal: a marked token gets no refresh token, and "Add a delegated-access marker that gates credential lookup for approved delegated tokens" (Add a delegated-access marker that gates credential lookup for approved delegated tokens #6404) refuses it in any further exchange.
- Rollout (design section 4): every gateway replica must enforce the marker before the authorization server issues marked tokens. Upgrade consumers first, or isolate the new path with an audience old consumers do not accept. The gate below enforces the order inside ToolHive; the release notes state it for embedders.
- A marked token does not require the ID-JAG to carry a
resourceclaim. The resource is bounded by the "ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted" (ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted #6892) check when the claim is present, and by the per-(issuer, client, resource) allow either way. Whether to require the claim for third-party issuers is an open question in "Delegated access: tokens and actors from third-party issuers" (Delegated access: tokens and actors from third-party issuers #7159). It does not affect this issue: a ToolHive AS-1 always signs the claim.
Gate (security constraints 5 to 7)
AS-2 cannot observe how the vMCP is wired, so no configuration check can prove that the read gates exist. A release can ship between any two items.
- Resolution (step 12) and marker issuance are unreachable in code until these have landed:
- "vMCP: session identity binding is not enforced for tools/list (and other list methods)" (vMCP: session identity binding is not enforced for
tools/list(and other list methods) #6779); - "vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user" (vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user #6888);
- parts A and C of "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);
- user-keyed storage (the storage plan's step 2a, tracked in "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) once rewritten);
- "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).
- "vMCP: session identity binding is not enforced for tools/list (and other list methods)" (vMCP: session identity binding is not enforced for
- The refusal is unconditional: not a setting, not an operator acknowledgement, not a build tag. With
subject_mode: resolveconfigured, redemption is refused (table above) and the server logs once at startup that resolution is not yet enabled in this build. - The refusal is removed by "Delegated access: turn on subject resolution at ID-JAG redemption" (Delegated access: turn on subject resolution at ID-JAG redemption #7247), owned by this redemption work, once every item above has landed. It removes the refusal and carries the in-process proof and the flow-test changes below. There is no kind proof of resolution: Mecatl's own phase 1 end-to-end test covers the full path.
Tests
- Unit: one table per check in the order above, with the exact
errorand reason code; resolution with a fakeResolver(found, unknown, ambiguous, unavailable, empty with nil error); the marker issued only when every condition holds and absent when any one fails; lifetime is the minimum of the client's lifespan if set (else the server's), the ID-JAG's remaining validity, and the marker cap, which wins. - Configuration: each validation refusal and the startup check, with the error text.
- Gate: with the refusal in place, no configuration reaches resolution or marker issuance, on the redemption path. Removing the refusal must fail this test on purpose.
- Integration, two servers (
two_server_id_jag_integration_test.go): AS-1 mints through real issuance with an actor validator, and AS-2 redeems. Assertsact.issis AS-1'sActIssuerand passes the actor-issuer check. This would have caught the design'sact.iss == AS-1assumption. - Flow test (
delegated_agent_flow_integration_test.go, step 6, "AS-2 redeems an ID-JAG"): flipssubfrom<AS-1 iss>#<sub>to U, and the two-elementaudrow from accepted to refused. Adds a step before redemption in which the user signs in at AS-2 through the same mock identity provider and connects a second upstream that stands in for GitHub. - Real-user invariant: after the user connects the second upstream, a redeemed ID-JAG's
subequals theUserIDon that upstream's row. Builds on "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). - A synthetic-subject upstream: a user whose identity-provider leg is synthetic does not resolve.
- In-process proof, in "Delegated access: turn on subject resolution at ID-JAG redemption" (Delegated access: turn on subject resolution at ID-JAG redemption #7247): a real ID-JAG from AS-1 is redeemed at AS-2 with a
resolveissuer, and the token names the user and carries the marker. A marked token presented by another client or actor, or as a token-exchange subject, is refused (the vMCP side is tested by the storage track).
Docs
-
docs/arch/17-token-exchange-delegation.md: subject modes, the check order, the marker, the gate. - The PR bodies state the user-facing change: before, every ID-JAG redemption issued
iss#sub; after, aresolveissuer issues the local user (once the gate is removed). The settings are Go-only, so there are no operator docs or CRD fields.
Coordination with the storage track
Agreed with the storage track:
- The marker claim name and constant ("Add a delegated-access marker that gates credential lookup for approved delegated tokens", Add a delegated-access marker that gates credential lookup for approved delegated tokens #6404). ToolHive's authorization server defines it. The vMCP decides the admission route from the raw claims in
pkg/auth/token.go, as it readstsid, and the credential read in Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407 checks the route. - The
Resolverread of provider-identity records (the sub-issue): not found means unknown, anything else means unavailable, in both backends. Provider-identity rows are written only on the identity-provider leg; reconnect writes token rows only. - Configuration: two Go-only settings, no CRD or run-configuration fields.
resolvedoes not requireupstreamCredentialKeying: user; the vMCP fails closed per request unless storage keys rows by user. - "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) is the storage track's. This issue's tests use a fake store, and the real-user check stays in the flow test.
- "Delegated access: turn on subject resolution at ID-JAG redemption" (Delegated access: turn on subject resolution at ID-JAG redemption #7247) removes the gate (see "Gate").
Not in scope
- User approval, the approval link, administrator pre-approval, and resolution through an approval record or a directory sync: "Delegated access: user approval at an external gateway" (Delegated access: user approval at an external gateway #7158, under "Phase 3, Slice 5: External gateway — Agents use a gateway Mecatl doesn't run, with no extra login step" (Phase 3, Slice 9: External gateway — Agents use a gateway Mecatl doesn't run, with no extra login step mecatl#2810)).
- Resolution from an identity provider's own ID-JAG (a second subject source,
issuer_claim), resolution on AS-2's RFC 8693 token-exchange path, foreign actor tokens, the per-issuerjtireuse policy, and whether marked tokens require aresourceclaim. These serve agent platforms other than Mecatl: "Delegated access: tokens and actors from third-party issuers" (Delegated access: tokens and actors from third-party issuers #7159, under "Delegated client access to a user's connections" (Delegated client access to a user's connections #6406)). ID-JAGjtistays single use; that is already atomic across replicas through the Redis assertion store. - Narrowing the token to one tool call with an
authorization_detailsrequest: "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061). The grantedauthorization_detailsin the response belongs to that issue. - Audit events for redemption: separate work under "Add audit logging to authserver" (Add audit logging to authserver #3919).
Sub-issues:
- "Delegated access: subject mapping setting and code gate for ID-JAG issuers" (Delegated access: subject mapping setting and code gate for ID-JAG issuers #7244).
- "Delegated access: actor checks at ID-JAG redemption" (Delegated access: actor checks at ID-JAG redemption #7245).
- "Delegated access: resolve the ID-JAG subject and issue the marked token behind the gate" (Delegated access: resolve the ID-JAG subject and issue the marked token behind the gate #7246).
- "Delegated access: turn on subject resolution at ID-JAG redemption" (Delegated access: turn on subject resolution at ID-JAG redemption #7247).
- "Delegated access: subject resolver and actor policy packages" (Delegated access: subject resolver and actor policy packages #7157).
- "ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted" (ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted #6892).
- "Authorization server: reason codes in error_description for ID-JAG redemption refusals" (Authorization server: reason codes in error_description for ID-JAG redemption refusals #7030).
Activity
[-]Delegated access: subject mapping and user approval[/-][+]Delegated access: subject mapping at ID-JAG redemption[/+]Add reason codes to redemption refusals
Refuse ID-JAGs with a multi-valued aud (#7204)
jhrozek commentedon Nov 27, 2026
All sub-issues are done; #7247 turned resolution on (#7356).