Skip to content

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

Open
3 of 4 issues completed
Open

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:

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's iss#sub) or resolve. A Go zero value never selects resolve.

  • subject_source: where the user's identity is read from, for a resolve issuer. Required when subject_mode is resolve; there is no default.

    • upstream_subject (built here): the ID-JAG carries https://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 on binding_claim read 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). Default act.

    • act (built here): the outermost act; an act without iss takes the token's iss.
    • client (reserved, not built here): the agent is the client, as with Entra, which never emits act. 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 Okta uid, Entra oid with tid equal to the issuer's tenant, or sub where the operator confirms it is immutable. Validation (from the sub-issue) rejects email, preferred_username and upn, and warns on sub for Okta custom authorization servers. Required when subject_mode is resolve. With subject_source: upstream_subject, the claim member of upstream_subject must equal it.

  • allowed_upstream_issuers: the identity providers this issuer may name in upstream_subject. Any other is refused (ID-JAG draft §9.8: the subject's own issuer does not establish trust). Required when subject_source is upstream_subject.

  • actor_issuers: act.iss values accepted besides the ID-JAG's own iss.

  • Redemption allow per (client, resource), replacing subject_bindings for resolve issuers. subject_bindings must 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. Default false.

Validation and startup:

  • Configuration refuses subject_mode: resolve and grants_credential_access on AS-2's own issuer. AS-1 and AS-2 are always two servers with different issuers.
  • Configuration refuses grants_credential_access without subject_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_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 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_subject as {iss, claim, value}. A missing or malformed claim is refused.
  • iss must be in allowed_upstream_issuers, and claim must equal binding_claim.
  • 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 for a configured (issuer, client, resource). No approval record is read.

DPoP:

  • An ID-JAG that carries cnf must not become an unbound bearer token. Today redemption ignores cnf. Until redemption can bind the issued token to the same key (design: "bound to the same DPoP key when the ID-JAG carried cnf"), proposed rule: refuse a resolve-mode redemption of an ID-JAG with cnf, with invalid_grant. A ToolHive AS-1 never emits cnf (it refuses DPoP with dpop_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

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 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 three bounds.
  • Configuration: each validation refusal and the startup check, with the error text, including subject_source missing for a resolve issuer and subject_source: issuer_claim refused 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. 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.
  • 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, a resolve issuer issues the local user (once the gate is removed), and a two-element aud is 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 reads tsid, and the credential read in Ownership-checked credential read for delegated tokens, keyed by user and routed provider #6407 checks the route.
  • The Resolver read 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_access does not require upstreamCredentialKeying: 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

Sub-issues:

Activity

  1. changed the title [-]Delegated access: subject mapping and user approval[/-] [+]Delegated access: subject mapping at ID-JAG redemption[/+] on Nov 16, 2026
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

    needs-triageIssue needs initial triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions