Skip to content

Delegated access: subject mapping at ID-JAG redemption #6887

Done
8 of 8 issues completed
Done

Description

@jhrozek

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:

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's iss#sub) or resolve. A Go zero value never selects resolve. resolve also makes the token carry the delegated-access marker.
  • actor_issuers: act.iss values accepted besides the ID-JAG's own iss.

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):

  • resolve together with subject_bindings is refused.
  • resolve or actor_issuers on a namespaced issuer is refused.
  • resolve on an issuer that accepts plain jwt_bearer is refused. An empty accepted_assertion_types means both, so a resolve issuer must set [id_jag].
  • resolve when 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_subject in required_subject_claims, so every ID-JAG carries https://toolhive.dev/upstream_subject. Without it, issuance refuses with upstream_subject_missing rather than minting an ID-JAG that AS-2 cannot resolve.
  • The actor validator registration's ActIssuer is listed in AS-2's actor_issuers for AS-1. ToolHive refuses an ActIssuer equal to its own issuer (validateActIssuer), so act.iss never equals the ID-JAG's iss for 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_subject as {iss, claim, value}. A missing or malformed claim is refused.
  • iss must be the issuer of AS-2's identity-provider upstream (the first sign-in leg), and claim that upstream's subject claim. Otherwise the redemption is refused as invalid_grant with invalid_assertion.
  • Call the Resolver with Ref{iss, claim, value}. The standalone resolver maps iss to 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) and ErrAmbiguous are refused. ErrUnavailable returns server_error, never invalid_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 as ErrUnknown.
  • Embedded mode: approval is implicit. No approval record is read; the client is bounded by rows 1, 6 and 14.

DPoP:

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.sub at an allowed issuer passes, an act without iss is checked as the token issuer, and under the client source 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 another Policy. Say in Evaluate's doc that it trusts Request.Actor to come from actor.Effective with the same TokenIssuer and ClientID, and does not re-check a hand-built Actor. 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

  • sub is U. iss is AS-2. aud is the granted resource. client_id is the redeeming client.
  • act is copied unchanged (Mecatl: the agent instance, so every call is attributable to it).
  • no_upstream_session is kept, so the interactive upstream-token path never serves this token.
  • No tsid and no refresh token.
  • exp is the earliest of: the configured lifetime, the ID-JAG's exp, and the marker cap (a few minutes) for a marked token, whatever delegationLifespan says.
  • Dropped from this issue. Granted authorization_details in 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). scope is 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 resolve issuers (resolve implies 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 resource claim. 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.

Tests

  • Unit: one table per check in the order above, with the exact error and reason code; resolution with a fake Resolver (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. Asserts act.iss is AS-1's ActIssuer and passes the actor-issuer check. This would have caught the design's act.iss == AS-1 assumption.
  • Flow test (delegated_agent_flow_integration_test.go, step 6, "AS-2 redeems an ID-JAG"): flips sub from <AS-1 iss>#<sub> to U, and the two-element aud row 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 sub equals the UserID on 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 resolve issuer, 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, a resolve issuer 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:

Not in scope

Sub-issues:

Sub-issues

Sub-issues

8 of 8 Issues completed
Loading 8 sub-issues

Activity

  1. added
    needs-triage
    on Oct 20, 2026
  2. changed the title [-]Delegated access: subject mapping and user approval[/-] [+]Delegated access: subject mapping at ID-JAG redemption[/+] on Nov 16, 2026
  3. removed
    needs-triage
    on Nov 23, 2026
  4. jhrozek commented on Nov 27, 2026

    @jhrozek
    ContributorAuthor

    All sub-issues are done; #7247 turned resolution on (#7356).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions