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.
This issue can merge before the gates listed under "Gate", because resolution and the marker stay unreachable in code until they land.
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
Per trusted issuer, on TrustedIssuer.JWTBearerGrant (JWTBearerGrantPolicy, multi_issuer_validator.go) in the run configuration, and on MCPExternalAuthConfig (v1beta1, JWTBearerGrant) in the CRD. The names below are proposals; the final names are agreed together with the storage track's configuration (ledger wave 0).
-
subject_mode:namespaced(default, today'siss#sub) orresolve. A Go zero value never selectsresolve. -
subject_source: where the user's identity is read from, for aresolveissuer. Required whensubject_modeisresolve; there is no default.upstream_subject(built here): the ID-JAG carrieshttps://toolhive.dev/upstream_subject = {iss, claim, value}. This is the case where the ID-JAG's issuer sits between the user's identity provider and AS-2 and vouches for the user's account there. A ToolHive AS-1 is the example.issuer_claim(reserved, not built here): the ID-JAG's issuer is itself the identity provider (Okta or Entra issuing ID-JAGs), and the user is matched onbinding_claimread from the ID-JAG's own claims. Built in "Delegated access: tokens and actors from third-party issuers" (Delegated access: tokens and actors from third-party issuers #7159). Until then, configuration refuses this value with an error naming that issue.
Third-party identity providers are never asked to add a claim: a ToolHive-private claim is read only from issuers that emit it, and the identity provider's own claims are read through
binding_claim. -
actor_source: where the acting agent is read from (the packages sub-issue defines the two sources). Defaultact.act(built here): the outermostact; anactwithoutisstakes the token'siss.client(reserved, not built here): the agent is the client, as with Entra, which never emitsact. Built with the third-party issuers issue. Until then, configuration refuses it.
The name parallels
subject_source: one says where the user comes from, the other where the agent comes from. -
binding_claim: the claim the user is matched on at the identity provider, for example Oktauid, Entraoidwithtidequal to the issuer's tenant, orsubwhere the operator confirms it is immutable. Validation (from the sub-issue) rejectsemail,preferred_usernameandupn, and warns onsubfor Okta custom authorization servers. Required whensubject_modeisresolve. Withsubject_source: upstream_subject, theclaimmember ofupstream_subjectmust equal it. -
allowed_upstream_issuers: the identity providers this issuer may name inupstream_subject. Any other is refused (ID-JAG draft §9.8: the subject's own issuer does not establish trust). Required whensubject_sourceisupstream_subject. -
actor_issuers:act.issvalues accepted besides the ID-JAG's owniss. -
Redemption allow per (client, resource), replacing
subject_bindingsforresolveissuers.subject_bindingsmust name every subject and allows no wildcard, so it cannot express "any user of this issuer, through this client, to this resource". -
grants_credential_access: whether redemptions from this issuer may carry the marker. Defaultfalse.
Validation and startup:
- Configuration refuses
subject_mode: resolveandgrants_credential_accesson AS-2's own issuer. AS-1 and AS-2 are always two servers with different issuers. - Configuration refuses
grants_credential_accesswithoutsubject_mode: resolve. A namespaced subject is never a local user, so marking it would mean nothing. - Startup check: for each allowed upstream issuer, AS-2 has an identity-provider upstream (the first sign-in leg) with that issuer, and its subject claim equals
binding_claim. Otherwise resolution can never succeed, and the refusal at redemption would not point at the cause. The error names the issuer and both claims. - CRD: the new fields, the converter to the run configuration, and the same refusals at admission, proven on kind (ledger: anything that changes operator or CRD behaviour is proven on a real kind cluster). Generated CRD docs updated.
- Sequence the configuration and CRD pull request with the storage track's
upstreamCredentialKeying, which lands in the same validation, startup checks and generated docs.
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 |
logged as a draft departure, accepted | refuse |
| 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 |
default from the claim; mismatch only logged | refusals from "ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted" (#6892) |
| 9 | Effective actor: the outermost act; if it has no iss, the token's iss (Okta) |
act copied, not checked |
new for resolve issuers; 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, subject_source: upstream_subject) |
iss#sub |
new, see below |
| 13 | Redemption allowed for (issuer, client, resource) | subject_bindings by subject |
new for resolve issuers; namespaced issuers keep subject_bindings |
| 14 | The client's own audiences | yes, invalid_target with the resource in the hint |
access_denied with resource_denied, no resource in the description ("Authorization server: reason codes in error_description for ID-JAG redemption refusals" (#7030)) |
| 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), building the lookup key from the configured subject_source:
subject_source: upstream_subject (built here) subject_source: issuer_claim (reserved)
ID-JAG iss = AS-1 ID-JAG iss = the identity provider
upstream_subject = {iss: IdP, claim, value} <binding_claim> = value
│ │
Ref{IdP, claim, value} Ref{ID-JAG iss, binding_claim, value}
└───────────────────► Resolver ◄─────────────────────┘
→ U
- Parse
https://toolhive.dev/upstream_subjectas{iss, claim, value}. A missing or malformed claim is refused. -
issmust be inallowed_upstream_issuers, andclaimmust equalbinding_claim. - 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 for a configured (issuer, client, resource). No approval record is read.
DPoP:
- An ID-JAG that carries
cnfmust not become an unbound bearer token. Today redemption ignorescnf. Until redemption can bind the issued token to the same key (design: "bound to the same DPoP key when the ID-JAG carriedcnf"), proposed rule: refuse aresolve-mode redemption of an ID-JAG withcnf, withinvalid_grant. A ToolHive AS-1 never emitscnf(it refuses DPoP withdpop_not_supported), so Mecatl is unaffected.
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 issuer not allowed, or wrong binding claim | invalid_grant |
invalid_assertion |
| Unknown or ambiguous user | access_denied |
subject_unknown (-06 §4.4.3: the user "lacks a … provisioning record") |
| Redemption not allowed for (issuer, client, resource) | access_denied |
resource_denied (-06 §4.4.1: MUST be access_denied "if none of the resources are acceptable") |
resolve redemption of an ID-JAG with cnf |
invalid_grant |
invalid_assertion |
| 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.
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 per-(issuer, client, resource) allow, 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. - The response returns the granted
scopeandauthorization_detailswhen present (draft -06 §4.4.1; the narrowing request itself is "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)). Returning the grantedresourceis not required by -06 (see "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)).
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 issuers with
grants_credential_access, 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);
- "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).
- "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 a separate item, "turn on resolution at redemption", owned by this redemption work, once every gate above has landed. It flips the refusal off and carries the kind e2e below; the storage track supplies the recording backend (integration harness part 1, under Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407).
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 three bounds. - Configuration: each validation refusal and the startup check, with the error text, including
subject_sourcemissing for aresolveissuer andsubject_source: issuer_claimrefused as not yet supported. - 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.
- Kind e2e, in the pull request that removes the gate: a real ID-JAG from AS-1 is redeemed at AS-2, and a recording backend receives exactly the user's stored credential for the routed provider. A marked token presented by another client or actor, or as a token-exchange subject, reads nothing.
Docs
-
docs/arch/17-token-exchange-delegation.md: subject modes, the check order, the marker, the gate. - Operator docs for the new configuration and CRD fields. The PR body states the user-facing change: before, every ID-JAG redemption issued
iss#sub; after, aresolveissuer issues the local user (once the gate is removed), and a two-elementaudis refused.
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 names as above: snake_case in the run configuration, camelCase in the CRD. Neither configuration pull request has to land first.
grants_credential_accessdoes not requireupstreamCredentialKeying: user; the vMCP refuses the new routes at startup 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.
- "Turn on resolution at redemption" 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 (
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). This issue only returns the grantedauthorization_details. - Audit events for redemption: separate work under "Add audit logging to authserver" (Add audit logging to authserver #3919).
Sub-issues:
- "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)