Skip to content

Sign authorization_details into minted ID-JAGs - #7305

Merged
rdimitrov merged 6 commits into
mainfrom
as2-call-binding-6-as1-signing
Nov 26, 2026
Merged

rdimitrov merged 6 commits into
mainfrom
as2-call-binding-6-as1-signing

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

An access token that AS-2 issues from an ID-JAG is good for any call to the resource until it expires. "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061) narrows it to one MCP call. AS-1 signs the call's RFC 9396 authorization_details entry into the ID-JAG, and AS-2 copies the signed entry into the access token. AS-2's half merged in "Process the ID-JAG authorization_details claim" (#7290). This PR is AS-1's half, the last authorization-server piece of #7061.

  • A token-exchange request for an ID-JAG now accepts the authorization_details parameter. Before, it refused it.
  • A type is signed into an ID-JAG only when its registration opts in: it must list the new authorizationdetails.IDJAGIssuance key in Type.GrantTypes. Listing the token-exchange grant type keeps meaning access-token exchange only. toolcalldetails.Register lists the new key next to token exchange and JWT-bearer.
  • AS-1 parses the value with the embedder's registry (Registry.ParseIDJAGIssuance). Then, after the grant checks and before the actor validator, it runs each type's hook through Pending.GrantSubset. Hooks keep or drop whole entries; they cannot change or add one.
  • AS-1 signs the kept entries into the ID-JAG's authorization_details claim. The response returns the same bytes in its authorization_details member (draft section 4.3.4).
  • The kept entries are the client's bytes in encoding/json form (compacted, <, >, &, U+2028 and U+2029 escaped), grouped by type in the order the types first appear. AS-2 copies the signed bytes of the entries it keeps, so when it keeps them all, the ID-JAG claim, both token responses and the access token's claim are the same bytes. An integer above 2^53 keeps every digit.
  • The kept entries must fit 32 KiB in that signed form, checked before the actor validator. The escapes can make it several times the request's size, and the redemption request carries the ID-JAG base64url-encoded in a 64 KiB body. Over the limit is malformed_entry.
  • The MCP call type refuses a list-call entry on an ID-JAG request, with list_call_unsupported. The vMCP does not accept list calls yet, so no ID-JAG carries one.
  • The registry reaches the refresh-token handler, which mints ID-JAGs, through a new tokenexchange.WithIDJAGAuthorizationDetailsRegistry option. buildTokenExchangeFactories sets it from Config.AuthorizationDetailsRegistry. The private exchange-grant registry is unchanged.
  • Docs: "On ID-JAG minting" (new), plus "Request and response", "Checks and errors", "Claims and subject", "Wiring" and the MCP call type paragraph in docs/arch/17-token-exchange-delegation.md, and the delegated-token paragraph in docs/authz.md.

Closes #7061

Release order. Depends on "Process the ID-JAG authorization_details claim" (#7290), which is merged. AS-2 processing must ship in the same release as AS-1 signing or an earlier one. An AS-2 that predates it ignores the claim, so the token comes out unrestricted. AS-2 claim processing is already on main, so this holds as long as this PR ships in a release that contains #7290.

The vMCP enforcement must also ship in the same release or an earlier one: "vMCP: accept an access token for the one call its authorization_details names, once" (#7062), merged in #7302. Without it, a narrowed token carries the entry but nothing enforces it at the vMCP. Mecatl's "Bind each gateway token to its call" (stacklok/mecatl#2727) merges only with the ToolHive pin bump that contains all three. The release notes of that release should call this out, together with #7290's refusal of an ID-JAG that carries the claim at a server without a registry.

Type of change

  • New feature

Test plan

  • Unit tests: go test -race ./pkg/authserver/... ./pkg/mcp/toolcalldetails/... (all packages pass)
  • Linting: golangci-lint run ./pkg/authserver/... ./pkg/mcp/toolcalldetails/... (0 issues), task docs-verify, codespell on the changed files
  • Manual testing (described below)

New tests:

  • authorizationdetails/idjag_issuance_test.go: the key equals the ID-JAG token-type URN and New accepts it. A token-exchange-only type is ErrUnknownType on ParseIDJAGIssuance, and an issuance-only type is ErrUnknownType on token exchange. The hooks see the token-exchange grant type.
  • refresh_token_id_jag_details_test.go:
    • the signed claim and response member, byte for byte;
    • the full hook Request, including that the hook runs in both phases;
    • a SPIFFE client's actor, and Subject.Expiry capped by id_jag_max_lifetime;
    • no parameter, or one empty value, gives no claim;
    • dropping whole entries;
    • entries that sign to exactly 32 KiB are minted;
    • every refusal, in both phases, with and without a registry, with its HTTP status and nothing minted: repeated, unknown_type (including a type registered for token exchange without the opt-in), malformed_entry (including null, a typeless entry, a value over 64 KiB and entries that sign to over 32 KiB), empty_grant (including []), the hook's reason, and server_error for a hook that fails, returns a fosite error, changes or adds an entry;
    • shape checks run before the store read, and hooks run only after the grant checks;
    • each refusal's log line (reason and fields), never an entry value, a hook's error text or an unknown type;
    • the factory option;
    • the minting core refuses malformed details.
  • refresh_token_actor_details_test.go: for a client with an actor profile, hooks run before the validator and see an empty Actor with ActorTokenPresent. No refusal reaches the validator: a hook refusal, empty_grant, server_error, unknown_type and the signed size limit. An accepted entry is signed next to act.
  • refresh_token_id_jag_test.go: the mint reads the clock again after the hooks, and a grant that expires between the decision and the mint is refused with invalid_grant.
  • pkg/mcp/toolcalldetails: TestRegister_IDJAGPath runs the MCP registration through the registry on both sides (ParseIDJAGIssuance and GrantSubset for AS-1, JWT-bearer GrantSubset for AS-2), and a list call is refused on the AS-1 side.
  • two_server_id_jag_details_integration_test.go (end to end over HTTP, AS-1 and AS-2 in one test process; test types only, so nothing under pkg/authserver imports pkg/mcp):
    • a call entry plus a test-type entry holding 12345678901234567890123, <b>&, U+2028 and U+2029 are identical across AS-1's response member, the ID-JAG claim, AS-2's response member and the access-token claim;
    • entries that sign to exactly 32 KiB are minted at AS-1 and redeemed at AS-2; one byte more is refused at AS-1 with malformed_entry;
    • refusals at AS-1 (a hook's single_entry_required, malformed_entry, unknown_type for an unregistered type and for a type not opted in, empty_grant);
    • parameter_not_allowed at AS-2;
    • an AS-2 without the type refuses the signed ID-JAG with unknown_type.
  • delegated_agent_flow_integration_test.go: a call test type is registered on both servers. The broker sends the entry on the ID-JAG request and redeems with no parameter; the four copies are equal; expires_in stays within the ID-JAG. A second entry is refused at AS-1 before the actor validator, and a redemption that still sends the parameter gets parameter_not_allowed, on memory and Redis.

Manual run: one OS process hosting two embedded authorization servers (AS-1 on 127.0.0.1:4601, AS-2 on :4602; a server cannot name its own issuer as an ID-JAG target), driven with curl from a shell script. The user's login was simulated by signing a login-shaped access token with AS-1's key. Over HTTP:

  1. AS-1 exchanged the login token for an exchange grant.
  2. AS-1 minted an ID-JAG with the two entries above, sent with whitespace.
  3. AS-2 redeemed it without the parameter.

All four copies were the same 308 bytes, with every digit of the big integer kept and <, > and & escaped. The refusals returned single_entry_required, unknown_type and empty_grant at AS-1, and parameter_not_allowed at AS-2. The review fixes (the signed size limit, the list-call refusal, the clock re-read) are covered by the HTTP tests above, not by a new manual run.

Changes

File Change
pkg/authserver/server/tokenexchange/refresh_token_id_jag_details.go New: parse the parameter, run the hooks, the signed size limit, refusals
pkg/authserver/server/tokenexchange/refresh_token_id_jag.go decideIDJAG parses before the grant read and runs the hooks after the grant checks; issueIDJAG reads the clock again before the mint
pkg/authserver/server/tokenexchange/id_jag_mint.go Stop refusing the parameter; sign the claim; echo it; refuse malformed details in the minting core
pkg/authserver/server/tokenexchange/refresh_token_handler.go WithIDJAGAuthorizationDetailsRegistry, the handler field
pkg/authserver/server_impl.go Pass the registry to the refresh-token factory
pkg/authserver/authorizationdetails/authorizationdetails.go IDJAGIssuance opt-in key, Registry.ParseIDJAGIssuance; hook-contract docs (hooks run twice on a mint)
pkg/mcp/toolcalldetails/toolcalldetails.go Register lists IDJAGIssuance; the hook refuses a list call on an ID-JAG request; package doc
factory.go, config.go, runner/embeddedauthserver.go, redemption_details.go Doc comments for the AS-1 path
docs/arch/17-token-exchange-delegation.md, docs/authz.md Docs

Does this introduce a user-facing change?

Yes, for clients of a ToolHive authorization server that mints ID-JAGs:

Request Before After
ID-JAG request with authorization_details of a type that lists authorizationdetails.IDJAGIssuance 400 invalid_authorization_details 200; the ID-JAG carries the kept entries in authorization_details, and the response has the same authorization_details member
...of a type registered only for token exchange (no opt-in), a type not registered, or with no registry 400 invalid_authorization_details 400 invalid_authorization_details, unknown_type
...with a value that is not a JSON array of objects 400 invalid_authorization_details 400 invalid_authorization_details, malformed_entry
...with [], or entries every hook drops 400 invalid_authorization_details 400 invalid_authorization_details, empty_grant
...whose kept entries are over 32 KiB once signed 400 invalid_authorization_details 400 invalid_authorization_details, malformed_entry
...that a hook refuses (for mcp_tool_call: single_entry_required, malformed_entry, invalid_arguments_hash, invalid_method, list_call_unsupported) 400 invalid_authorization_details 400 with the hook's code and reason
...that a hook fails on, or a hook that changes or adds an entry 400 invalid_authorization_details 500 server_error, "The authorization_details could not be processed."
...with the parameter repeated (authorization_details=&authorization_details=, before: treated as absent) 200, no claim 400 invalid_request, "The authorization_details parameter must not be repeated.", as on token exchange
...with the parameter repeated and a value not empty 400 invalid_authorization_details 400 invalid_request, "The authorization_details parameter must not be repeated.", as on token exchange
ID-JAG request without the parameter, or with one empty value 200 200, unchanged

Where the check happens moved too. The parameter used to be refused right after scope, before the actor parameters and the target. Now its shape is checked after the target, and the hooks run after the grant checks and before the actor validator.

Embedders: toolcalldetails.Register already lists everything the MCP call type needs; register it on both servers, in the registry passed with runner.WithAuthorizationDetailsRegistry. For a type of your own to be signed into ID-JAGs, list authorizationdetails.IDJAGIssuance in its GrantTypes. Existing token-exchange types are not affected: they keep echoing on access-token exchange and are refused (unknown_type) on an ID-JAG request.

Special notes for reviewers

  • Size. 11 non-test files and about 535 changed lines, against the 10-file guideline. Four of them (config.go, runner/embeddedauthserver.go, factory.go, redemption_details.go) change only doc comments that would otherwise be false.

  • AS-1 also uses GrantSubset, not Grant. Token exchange for an access token uses Pending.Grant, whose output is re-encoded hook output. AS-1 uses GrantSubset so that the ID-JAG carries the entries the client sent, not a hook's rewrite. That gives AS-1 the same whole-entries-only rule as AS-2: a hook that changes or adds an entry is a server_error.

  • "The bytes the client sent", precisely. The signer encodes claims with encoding/json, which compacts a json.RawMessage and escapes <, >, &, U+2028 and U+2029. grantIDJAGDetails encodes the kept entries once itself, so the size limit applies to the signed form; mintIDJAG signs that form and echoes it, so the response member equals the signed claim byte for byte. Whitespace, those five characters and the grouping of entries by type are the only differences from the request; numbers keep every digit.

  • Hook context on this path. The subject token is an opaque exchange-grant refresh token. So Subject describes the grant:

    • Issuer is AS-1; Subject is the grant's user (the ID-JAG's sub); ClientID is the client that holds the grant;
    • IssuedAt is the grant's creation, and Expiry is the earlier of its expiry and its id_jag_max_lifetime cap;
    • GrantedAudience is the target issuer (the ID-JAG's aud), and RequestedTokenType is the ID-JAG type.

    For a client with an actor profile, the actor token is validated after the hooks. There Exchange.Actor is empty and ActorTokenPresent is true. Otherwise Actor is the client ID, or the verified SPIFFE ID for a SPIFFE client.

  • The hooks run twice per request. decide runs in both of fosite's handler phases, as it already did for the exchange-grant entry. The handler is deliberately stateless between the phases. Type.Grant's doc no longer promises "at most once per request": it now says a token exchange for an ID-JAG calls the hook in both phases, and a hook must be decide-only.

  • The hooks run before the actor validator (an external call), so a refused entry never costs a validator call. They run after the grant checks because the hook Request needs the grant.

  • ID-JAG signing is an explicit opt-in (authorizationdetails.IDJAGIssuance). A type registered for the token-exchange grant has always been echo-only: its entries were never put in a token. If that registration also covered ID-JAG minting, an existing type written for exchanged access tokens would start being signed into ID-JAGs that other authorization servers trust, without its author changing anything. The opt-in fails closed instead: such a type is refused on an ID-JAG request with unknown_type, the same as an unregistered type, until its registration lists the key.

    • Why this key: GrantTypes is the existing per-type list of where a type is accepted, so the opt-in lives there and needs no new field. The value is the ID-JAG token-type URN, urn:ietf:params:oauth:token-type:id-jag, which is the requested_token_type of exactly this request. It needs no invented ToolHive URN and cannot equal any grant type (a different URN namespace). The constant name says what it opts into, so it does not read as a grant type.
    • Registry.ParseIDJAGIssuance checks the key, but the hooks still see the token-exchange grant type in Request.GrantType, since that is the grant the request rides. Registry.New already accepts any non-blank entry, so no validation change was needed; a test pins that it accepts the key.
    • Access-token exchange is unchanged. A type listing only the new key is not accepted there.
  • Redemption side, not changed here. Listing JWT-bearer still means ID-JAG redemption, as merged in Process the ID-JAG authorization_details claim #7290. That is safe today because the plain RFC 7523 grant refuses an assertion that carries the claim, so JWT-bearer can only mean the ID-JAG. A matching redemption key (for example IDJAGRedemption) would make the two sides symmetric, and keep a future plain JWT-bearer use of details from implicitly covering ID-JAG redemption. It would also be a breaking change for embedders already registered for JWT-bearer. Worth deciding in a follow-up, not here.

  • Hook errors. Only an authorizationdetails.Error reaches the client, as on the two other hook paths. Any other hook error, a *fosite.RFC6749Error included, is a server_error. The private exchange-grant mapper passes fosite errors through, so this path does not reuse it.

  • No registry. Without a registry, the value is parsed by a registry that knows no type. The 64 KiB limit and the shape rules then apply before unknown_type is answered, and [] is empty_grant either way.

  • Logging. Refusals use this handler's existing Exchange grant refused WARN line with a fixed reason: repeated, unknown_type, malformed_entry, details_too_large, empty_grant, hook_rejected or hook_failed.

    • unknown_type logs no types: they are request text that matched no registration, as on access-token exchange. empty_grant adds the dropped types, which are registered names.
    • hook_rejected adds code and hook_reason, as grantFailure does on the other paths.
    • Entry values and a failed hook's error text are never logged.

🤖 Generated with Claude Code

rdimitrov and others added 4 commits November 25, 2026 15:56
A token-exchange request for an ID-JAG now accepts the RFC 9396
authorization_details parameter instead of refusing it. AS-1 parses it
with the embedder's registry, runs each type's hook through
Pending.GrantSubset after the grant checks and before the actor
validator, and signs the kept entries into the ID-JAG's
authorization_details claim. The response returns the same bytes in its
authorization_details member (draft section 4.3.4).

The kept entries keep the bytes the client sent, so AS-2, which copies
the signed bytes, issues an access token whose claim equals the
ID-JAG's byte for byte; an integer above 2^53 survives the whole path.

Refusals: a repeated parameter is invalid_request; no registry or a
type not registered for token exchange is unknown_type; a value that
breaks the generic shape is malformed_entry; [] or a grant that keeps
no entry is empty_grant; a hook's own error passes through; a hook that
changes or adds an entry is server_error. Shape checks run before the
store is read, and a refused entry never reaches the actor validator.

The registry reaches the refresh-token handler through the new
WithIDJAGAuthorizationDetailsRegistry option; the private
exchange-grant registry is unchanged.

Refs #7061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The hook on the ID-JAG mint path now sees a SPIFFE client's verified
SPIFFE ID as Exchange.Actor, as on token exchange for an access token,
and Subject.Expiry is the grant's effective end: the earlier of its
stored expiry and the client's id_jag_max_lifetime cap.

A value that is not a JSON array of objects is malformed_entry with or
without a registry, so the shape is reported before the registration;
"[]" is empty_grant either way. Doc comments now say which hooks decide
runs twice, and the arch doc's logging note no longer claims the types
are the only form value logged.

Refs #7061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On the ID-JAG mint path only an authorizationdetails.Error from a hook
reaches the client; any other hook error, a fosite error included, is a
server_error, as on token exchange and redemption. Refusals log with
the same fixed reasons and fields those paths use (repeated,
hook_rejected with code and hook_reason, hook_failed).

Without a registry the value is parsed by a registry that knows no
type, so the 64 KiB limit and the generic shape rules apply before
unknown_type is answered, and the hand-written array check goes away.

Type.Grant no longer promises one call per request: a token exchange
for an ID-JAG calls it in both handler phases. Type.GrantTypes says a
token-exchange registration also covers signing into an ID-JAG, which
a hook can refuse by RequestedTokenType. idJAGExpiry reuses earliest.

Refs #7061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A type registered for the token-exchange grant has always been
echo-only on access-token exchange. Treating that registration as
consent to sign its entries into ID-JAGs that other authorization
servers trust would change what existing types do without their
authors deciding it. A type is now signed into an ID-JAG only when it
lists the new authorizationdetails.IDJAGIssuance key in GrantTypes;
otherwise an ID-JAG request carrying it gets unknown_type, like an
unregistered type. Access-token exchange is unchanged.

The key's value is the ID-JAG token-type URN, the requested_token_type
of such a request, so no new URN is invented and it cannot equal a
grant type. Registry.ParseIDJAGIssuance checks it, while the hooks
still see the token-exchange grant type. toolcalldetails.Register
lists the key. ID-JAG redemption keeps keying on the JWT-bearer grant.

Refs #7061

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 25, 2026
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.16981% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.11%. Comparing base (10943fb) to head (f1133bb).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...rver/tokenexchange/refresh_token_id_jag_details.go 96.49% 2 Missing ⚠️
pkg/authserver/server/tokenexchange/id_jag_mint.go 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7305      +/-   ##
==========================================
+ Coverage   81.98%   82.11%   +0.13%     
==========================================
  Files         923      931       +8     
  Lines       93575    94366     +791     
==========================================
+ Hits        76717    77489     +772     
- Misses      16853    16872      +19     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Keep both edits to the authorization details boundary paragraph: the
ID-JAG signing sentence and the pointer to the vMCP's enforcement.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 25, 2026

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this reads well and the shape is right. I walked one tools/call through AS-1, AS-2 and the vMCP and the pieces line up: entries only narrow, an empty grant is refused rather than minted without the claim, and nothing is refused after the actor validator or after a store write. The IDJAGIssuance opt-in is a good call, and nothing in the new authserver code knows about MCP, which I was glad to see.

One thing I'd like fixed before merge: the size check (inline on id_jag_mint.go). The rest are smaller.

One thing without a line to hang on: the user-facing table covers the all-empty repeated case, but a repeated parameter with a non-empty value also changes, from invalid_authorization_details to invalid_request ("must not be repeated"). Worth a row.

- Check the kept entries in the form the ID-JAG signs, before the actor
  validator: encoding/json escapes can make it several times the request's
  size, and the redemption request carries the ID-JAG base64url-encoded in a
  64 KiB body. Over 32 KiB is malformed_entry, logged as details_too_large.
- The MCP call type refuses a list-call entry on a token exchange for an
  ID-JAG (list_call_unsupported), since the vMCP does not accept list calls
  yet.
- Do not log the request's types on an unknown_type refusal, as on token
  exchange for an access token.
- Read the clock again before minting for clients without an actor profile,
  so a grant that expires while the hooks run is refused.
- Keep pkg/authserver tests free of pkg/mcp: the two-server and
  delegated-flow tests use a test type, and the MCP registration's ID-JAG
  path is tested in pkg/mcp/toolcalldetails.
- Tests assert the HTTP status and that nothing is minted on each refusal,
  and cover empty_grant, unknown_type, server_error and the size limit for an
  actor-profile client.
- Correct the "byte for byte" wording: AS-2 may keep fewer entries, kept
  entries are grouped by type, and U+2028 and U+2029 are escaped too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Nov 25, 2026
@rdimitrov
rdimitrov merged commit d08524f into main Nov 26, 2026
64 of 65 checks passed
@rdimitrov
rdimitrov deleted the as2-call-binding-6-as1-signing branch November 26, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details

2 participants