Repository navigation
Sign authorization_details into minted ID-JAGs - #7305
Conversation
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]>
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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]>
jhrozek
left a comment
There was a problem hiding this comment.
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]>
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_detailsentry 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.authorization_detailsparameter. Before, it refused it.authorizationdetails.IDJAGIssuancekey inType.GrantTypes. Listing the token-exchange grant type keeps meaning access-token exchange only.toolcalldetails.Registerlists the new key next to token exchange and JWT-bearer.Registry.ParseIDJAGIssuance). Then, after the grant checks and before the actor validator, it runs each type's hook throughPending.GrantSubset. Hooks keep or drop whole entries; they cannot change or add one.authorization_detailsclaim. The response returns the same bytes in itsauthorization_detailsmember (draft section 4.3.4).encoding/jsonform (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.malformed_entry.list_call_unsupported. The vMCP does not accept list calls yet, so no ID-JAG carries one.tokenexchange.WithIDJAGAuthorizationDetailsRegistryoption.buildTokenExchangeFactoriessets it fromConfig.AuthorizationDetailsRegistry. The private exchange-grant registry is unchanged.docs/arch/17-token-exchange-delegation.md, and the delegated-token paragraph indocs/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
Test plan
go test -race ./pkg/authserver/... ./pkg/mcp/toolcalldetails/...(all packages pass)golangci-lint run ./pkg/authserver/... ./pkg/mcp/toolcalldetails/...(0 issues),task docs-verify, codespell on the changed filesNew tests:
authorizationdetails/idjag_issuance_test.go: the key equals the ID-JAG token-type URN andNewaccepts it. A token-exchange-only type isErrUnknownTypeonParseIDJAGIssuance, and an issuance-only type isErrUnknownTypeon token exchange. The hooks see the token-exchange grant type.refresh_token_id_jag_details_test.go:Request, including that the hook runs in both phases;Subject.Expirycapped byid_jag_max_lifetime;unknown_type(including a type registered for token exchange without the opt-in),malformed_entry(includingnull, a typeless entry, a value over 64 KiB and entries that sign to over 32 KiB),empty_grant(including[]), the hook's reason, andserver_errorfor a hook that fails, returns a fosite error, changes or adds an entry;refresh_token_actor_details_test.go: for a client with an actor profile, hooks run before the validator and see an emptyActorwithActorTokenPresent. No refusal reaches the validator: a hook refusal,empty_grant,server_error,unknown_typeand the signed size limit. An accepted entry is signed next toact.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 withinvalid_grant.pkg/mcp/toolcalldetails:TestRegister_IDJAGPathruns the MCP registration through the registry on both sides (ParseIDJAGIssuanceandGrantSubsetfor AS-1, JWT-bearerGrantSubsetfor 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 underpkg/authserverimportspkg/mcp):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;malformed_entry;single_entry_required,malformed_entry,unknown_typefor an unregistered type and for a type not opted in,empty_grant);parameter_not_allowedat AS-2;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_instays within the ID-JAG. A second entry is refused at AS-1 before the actor validator, and a redemption that still sends the parameter getsparameter_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:
All four copies were the same 308 bytes, with every digit of the big integer kept and
<,>and&escaped. The refusals returnedsingle_entry_required,unknown_typeandempty_grantat AS-1, andparameter_not_allowedat 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
pkg/authserver/server/tokenexchange/refresh_token_id_jag_details.gopkg/authserver/server/tokenexchange/refresh_token_id_jag.godecideIDJAGparses before the grant read and runs the hooks after the grant checks;issueIDJAGreads the clock again before the mintpkg/authserver/server/tokenexchange/id_jag_mint.gopkg/authserver/server/tokenexchange/refresh_token_handler.goWithIDJAGAuthorizationDetailsRegistry, the handler fieldpkg/authserver/server_impl.gopkg/authserver/authorizationdetails/authorizationdetails.goIDJAGIssuanceopt-in key,Registry.ParseIDJAGIssuance; hook-contract docs (hooks run twice on a mint)pkg/mcp/toolcalldetails/toolcalldetails.goRegisterlistsIDJAGIssuance; the hook refuses a list call on an ID-JAG request; package docfactory.go,config.go,runner/embeddedauthserver.go,redemption_details.godocs/arch/17-token-exchange-delegation.md,docs/authz.mdDoes this introduce a user-facing change?
Yes, for clients of a ToolHive authorization server that mints ID-JAGs:
authorization_detailsof a type that listsauthorizationdetails.IDJAGIssuanceinvalid_authorization_detailsauthorization_details, and the response has the sameauthorization_detailsmemberinvalid_authorization_detailsinvalid_authorization_details,unknown_typeinvalid_authorization_detailsinvalid_authorization_details,malformed_entry[], or entries every hook dropsinvalid_authorization_detailsinvalid_authorization_details,empty_grantinvalid_authorization_detailsinvalid_authorization_details,malformed_entrymcp_tool_call:single_entry_required,malformed_entry,invalid_arguments_hash,invalid_method,list_call_unsupported)invalid_authorization_detailsinvalid_authorization_detailsserver_error, "The authorization_details could not be processed."authorization_details=&authorization_details=, before: treated as absent)invalid_request, "The authorization_details parameter must not be repeated.", as on token exchangeinvalid_authorization_detailsinvalid_request, "The authorization_details parameter must not be repeated.", as on token exchangeWhere 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.Registeralready lists everything the MCP call type needs; register it on both servers, in the registry passed withrunner.WithAuthorizationDetailsRegistry. For a type of your own to be signed into ID-JAGs, listauthorizationdetails.IDJAGIssuancein itsGrantTypes. 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, notGrant. Token exchange for an access token usesPending.Grant, whose output is re-encoded hook output. AS-1 usesGrantSubsetso 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 aserver_error."The bytes the client sent", precisely. The signer encodes claims with
encoding/json, which compacts ajson.RawMessageand escapes<,>,&, U+2028 and U+2029.grantIDJAGDetailsencodes the kept entries once itself, so the size limit applies to the signed form;mintIDJAGsigns 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
Subjectdescribes the grant:Issueris AS-1;Subjectis the grant's user (the ID-JAG'ssub);ClientIDis the client that holds the grant;IssuedAtis the grant's creation, andExpiryis the earlier of its expiry and itsid_jag_max_lifetimecap;GrantedAudienceis the target issuer (the ID-JAG'saud), andRequestedTokenTypeis the ID-JAG type.For a client with an actor profile, the actor token is validated after the hooks. There
Exchange.Actoris empty andActorTokenPresentis true. OtherwiseActoris the client ID, or the verified SPIFFE ID for a SPIFFE client.The hooks run twice per request.
decideruns 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
Requestneeds 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 withunknown_type, the same as an unregistered type, until its registration lists the key.GrantTypesis 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 therequested_token_typeof 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.ParseIDJAGIssuancechecks the key, but the hooks still see the token-exchange grant type inRequest.GrantType, since that is the grant the request rides.Registry.Newalready accepts any non-blank entry, so no validation change was needed; a test pins that it accepts the key.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.Errorreaches the client, as on the two other hook paths. Any other hook error, a*fosite.RFC6749Errorincluded, is aserver_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_typeis answered, and[]isempty_granteither way.Logging. Refusals use this handler's existing
Exchange grant refusedWARN line with a fixed reason:repeated,unknown_type,malformed_entry,details_too_large,empty_grant,hook_rejectedorhook_failed.unknown_typelogs no types: they are request text that matched no registration, as on access-token exchange.empty_grantadds the dropped types, which are registered names.hook_rejectedaddscodeandhook_reason, asgrantFailuredoes on the other paths.🤖 Generated with Claude Code