Skip to content

Process the ID-JAG authorization_details claim - #7290

Merged
rdimitrov merged 6 commits into
mainfrom
as2-call-binding-4-as2-claim
Nov 25, 2026
Merged

rdimitrov merged 6 commits into
mainfrom
as2-call-binding-4-as2-claim

Conversation

@rdimitrov

@rdimitrov rdimitrov commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Review commit by commit. The PR is above the usual size, so it is split into two commits: "Keep the raw authorization_details bytes" (about 60 non-test lines, no behaviour change: the validator keeps the claim's raw bytes so integer precision survives) and "Process the ID-JAG authorization_details claim" (the processing, refusals, wiring and docs). After those: a merge of main (the per-client lifespan and the tool-call type) and three review commits, "Address review of the ID-JAG details processing", "Update the authorization details docs for ID-JAG redemption" and "Split the authorization details request by grant".

Builds on "Refuse tokens that carry authorization_details" (#7282), now in main: this PR narrows that refusal to the plain RFC 7523 grant and processes the claim on the ID-JAG grant instead.

A client that redeems an ID-JAG at this authorization server gets an access token good for any call to the resource. To narrow a gateway token to one MCP call, the call has to travel in the ID-JAG's signed authorization_details claim, and the redeeming server has to carry it into the token. ID-JAG draft §4.4.1 requires the redeeming server to process that claim. Today redemption refuses every assertion that carries it. This PR makes the ID-JAG handler process it, as specified in "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061).

  • Raw bytes. verifySignature also decodes the verified payload into a map of raw members and keeps the authorization_details bytes in ValidatedClaims.AuthorizationDetails (nil when absent), so integers above 2^53 keep every digit. A map, not a struct, so another letter case does not match. This is its own behaviour-preserving first commit.
  • ID-JAG claim processing, after subject resolution and before the ID-JAG is consumed (grantSignedDetails in redemption_details.go):
    • a claim that is present (in the registered or the extra claims) but is null, [], a string, an object, or an array with a non-object is invalid_grant / invalid_assertion;
    • no registry, or a type not registered for the JWT-bearer grant, is invalid_authorization_details / unknown_type, logged at WARN with the ID-JAG issuer and the entry types (never the entries);
    • an entry that breaks the generic shape rules is malformed_entry;
    • the registered hooks decide, and their authorizationdetails.Error reasons pass through;
    • each entry a hook keeps must equal a distinct signed entry of its type as a JSON value (numbers compared as written, so 1 and 1.0 differ), and the grant is built from the signed bytes (Pending.GrantSubset), so the token carries exactly what the issuer signed. A hook that changes or adds an entry is a hook bug: server_error, a log line, and no token;
    • a type whose hook keeps none of its entries is dropped; the redemption is refused with empty_grant only when no entry is left after merging all types, because a redeemed token without details would be unrestricted.
  • Token and response. The granted entries go into the access token's authorization_details claim and the token response's authorization_details member, from the same bytes.
  • The parameter. Both redemption handlers refuse the authorization_details parameter with invalid_authorization_details / parameter_not_allowed, before the assertion is consumed. A single empty value counts as absent; a repeated parameter is invalid_request ("The authorization_details parameter must not be repeated."), as on token exchange.
  • Plain RFC 7523 keeps refusing the claim with invalid_grant / invalid_assertion; the AS-3 refusal now runs on the plain handler only.
  • Hook request. authorizationdetails.Request is split by grant: a common core (Entries, GrantType, ClientID, GrantedAudience, Subject), plus Exchange *ExchangeContext (Actor, ActorTokenPresent, RequestedTokenType, RequestedScopes), set only on token exchange, and Redemption *RedemptionContext (ResolvedUser), set only on ID-JAG redemption. A hook checks the part for nil before reading it. On redemption ClientID is the authenticated client, GrantedAudience is [resource], Subject.Subject is the ID-JAG's sub and External is true; Redemption.ResolvedUser is set only when the redemption resolved the subject (subject_mode: resolve). Subject.Claims no longer holds the lossy decoded copy of authorization_details; hooks read Request.Entries.
  • Typed errors. Registry.Parse returns ErrUnknownType (which wraps ErrInvalid) when every entry is well formed but a type is not registered, so unknown_type and malformed_entry can differ. New Pending.GrantSubset returns the kept signed entries and the types that were dropped (Subset).
  • Wiring. IDJAGIssuanceFactory takes options ...FactoryOption and applies WithAuthorizationDetailsRegistry, which buildJWTBearerFactoriesForConfig passes. AuthorizationDetailsRegistryReachable now takes the trusted issuers: a registry is reachable when token exchange is on or a trusted issuer accepts ID-JAG assertions (idJAGRedeemable, the same predicate the per-client lifespan check uses).

Part of "Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details" (#7061). The per-client lifetime from that issue is "Add a per-client access token lifespan for ID-JAG redemption" (#7284), and the mcp_tool_call type is "Add the MCP tool-call details type" (#7283).

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Scoped runs while working: go test -ldflags=-extldflags=-Wl,-w -race ./pkg/authserver/... and golangci-lint run --allow-parallel-runners ./pkg/authserver/... (0 issues), codespell on the changed paths.

New tests:

  • TestIDJAGRedemptionDetailsClaim: one row per error-table entry on the ID-JAG handler (shape refusals, presence in registered or extra claims only, no raw bytes, no registry, no registry with an untyped entry, exchange-only type, unregistered type, case-variant member, untyped entry, two entries, the same entry twice, hook refusal, hook failure, changed entry, added entry, 1 → 1.0, hook granting nothing, dropping one of two entries, reordered members, the parameter in its forms). Every refusal asserts the consumer was never called; every success asserts the token claim and the response member are equal.
  • TestJWTBearerRedemptionRefusesDetailsParameter and TestPlainRedemptionRefusesAuthorizationDetailsClaim for the plain handler.
  • TestPending_GrantSubset (kept, reordered, one dropped, a type dropped while another keeps one, every type dropped, changed / added / renumbered / rounded / foreign entries, trailing data, oversized entry), TestPending_GrantSubset_LoneSurrogate (the token carries the signed \ud800, not the hook's replacement character), TestEntryTypes, TestVerifySignature_AuthorizationDetailsRaw (absent, integer above 2^53, null, another letter case, a repeated member at the top level and inside an entry).
  • Hook subject: TestIDJAGRedemptionDetailsHookRequest (namespaced issuer: ResolvedUser empty) and TestIDJAGRedemptionDetailsResolvedSubject (resolve issuer: ResolvedUser set and Subject still the ID-JAG's sub; resolution failing: hook never called, nothing consumed).
  • Logs: TestIDJAGRedemptionDetailsLogs (one WARN per refusal kind, never an entry's value) and TestJWTBearerDetailsParameterLogLevel (plain grant: WARN once per issuer, and a redemption without the parameter does not use up that WARN), TestIDJAGDetailsRefusalLogLevel (ID-JAG: WARN once per client or issuer and reason, DEBUG after).
  • HTTP: TestIntegration_IDJAGAuthorizationDetailsClaim redeems a test-signed ID-JAG carrying an entry with an integer above 2^53; the response member and the access token's claim equal the entry digit for digit. TestIntegration_AuthorizationDetailsIgnoredOnOtherGrants became TestIntegration_AuthorizationDetailsParameterRefusedOnRedemption.
  • Redis: TestIDJAGHandler_RedisBackedDetails compares the stored claim byte for byte with the original, including 9007199254740993; TestSession_UnmarshalJSONKeepsAuthorizationDetailsRaw covers the decoder.
  • Reachability: an ID-JAG row (passes) and a plain-JWT-bearer-only row (fails) in TestAuthorizationDetailsRegistryReachable, TestEmbeddedAuthServer_AuthorizationDetailsRegistryReachability and TestValidateAuthorizationDetailsRegistryForRunConfig.

Changes

File Change
pkg/authserver/server/tokenexchange/validator.go, multi_issuer_validator.go Keep the raw authorization_details bytes (first commit)
pkg/authserver/server/tokenexchange/redemption_details.go New: parameter refusal, claim processing, token claim and response echo
pkg/authserver/server/tokenexchange/id_jag_handler.go Process the claim after subject resolution; refuse the parameter after client authentication; factory options
pkg/authserver/server/tokenexchange/jwt_bearer_handler.go Refuse the parameter; WARN once per issuer
pkg/authserver/server/tokenexchange/redeemer.go, redemption_refusal.go Carry the granted entries into the session and the response; the claim refusal is plain-only
pkg/authserver/server/tokenexchange/authdetails.go, refresh_token_handler.go, factory.go detailsSubject takes the resolved user and drops the claim from Claims; option docs
pkg/authserver/authorizationdetails/ ErrUnknownType, Request split into a core plus ExchangeContext / RedemptionContext, Pending.GrantSubset and Subset, hook-contract docs
pkg/mcp/toolcalldetails/ The hook reads the per-grant parts
pkg/authserver/config.go, server_impl.go, runner/embeddedauthserver.go Reachability rule covers ID-JAG redemption; registry passed to the ID-JAG factory
pkg/authserver/server/session/session.go, claimnames/ Stored sessions keep authorization_details as raw JSON
docs/arch/17-token-exchange-delegation.md, docs/arch/README.md, docs/authz.md "Authorization details" rewritten; refusal-reason, bound-ID-JAG and terminal-token rows

Does this introduce a user-facing change?

Yes. Before → after:

  • A JWT-bearer or ID-JAG redemption that sends the authorization_details parameter: the parameter was ignored → 400 invalid_authorization_details, error_description parameter_not_allowed. A single empty value is still treated as absent; a repeated parameter is 400 invalid_request.
  • An ID-JAG that carries the authorization_details claim: refused with 400 invalid_grant / invalid_assertion (since "Refuse tokens that carry authorization_details" (Refuse tokens that carry authorization_details #7282)) → processed. The granted entries are in the access token's authorization_details claim and in the token response's authorization_details member. Refusals follow the table in docs/arch/17-token-exchange-delegation.md ("On ID-JAG redemption"): invalid_assertion for a malformed claim, unknown_type, malformed_entry, a hook's own reason, empty_grant, or 500 server_error for a hook that grants an entry that was not signed.
  • An ID-JAG that carries the claim at a server without a registry (or without the type registered for the JWT-bearer grant): 400 invalid_authorization_details, unknown_type, with a WARN line naming the ID-JAG issuer and the entry types. On a server that predates "Refuse tokens that carry authorization_details" (Refuse tokens that carry authorization_details #7282) such an ID-JAG was accepted and the token came out unrestricted. Release notes should call this out.
  • A plain RFC 7523 assertion that carries the claim: still 400 invalid_grant / invalid_assertion (unchanged from Refuse tokens that carry authorization_details #7282).
  • Embedders:
    • a registry with token exchange off and a trusted issuer that accepts id_jag assertions was a startup error (ErrAuthorizationDetailsRegistryUnreachable) → accepted. With only plain jwt_bearer issuers it is still refused. The error text now reads "authorization details registry requires token exchange or ID-JAG redemption to be enabled";
    • AuthorizationDetailsRegistryReachable changes signature: in v0.69.0 it took one bool, now it also takes the trusted issuers;
    • authorizationdetails.Request moves Actor, ActorTokenPresent, RequestedTokenType and RequestedScopes into the new Exchange *ExchangeContext, set only on token exchange; a new Redemption *RedemptionContext (ResolvedUser) is set only on ID-JAG redemption. A hook reading those fields must read them through the part, after a nil check. Subject.Claims no longer carries authorization_details;
    • the mcp_tool_call hook grants only on ID-JAG redemption or on a token exchange that requests an ID-JAG, and refuses a request with neither part (id_jag_required);
    • new Pending.GrantSubset, Subset, claimnames.AuthorizationDetailsKey and session.Session.UnmarshalJSON; a stored session holds authorization_details as json.RawMessage;
    • a hook returns the entries it keeps exactly as it received them in Request.Entries.

Release order. This PR, then "vMCP: accept an access token for the one call its authorization_details names, once" (#7062), then AS-1 signing the claim into the ID-JAG. AS-2 processing (this PR) must ship in the same release as AS-1 signing, or an earlier one: an AS-2 without this PR refuses (or, before #7282, ignores) the claim. With "Add the MCP tool-call details type" (#7283) on main, an embedder that registers that type gets single-call tokens out of redemption as soon as this merges, but until the vMCP enforces the entry (#7062) such a token is still good for any call. The AS-1 signing PR says "Depends on" this one and stays in draft until it merges.

Special notes for reviewers

  • Deviation from the draft, on purpose. ID-JAG §4.4.1 lets the redeeming server "modify, filter, or omit" the entries. This server only drops whole signed entries: a hook may not narrow inside an entry or add one. That is the rule for the mcp_tool_call type in Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061, and stricter than the draft for other types. Per-type narrowing is "Narrow authorization_details on token exchange and refresh" (Narrow authorization_details on token exchange and refresh #6912). The same note is at grantSignedDetails.
  • [] asymmetry, on purpose. Token exchange accepts and echoes the parameter []; redemption refuses the claim [] (invalid_assertion), because a redeemed token without details is unrestricted.
  • empty_grant is decided once. A type whose hook keeps none of its entries is a normal outcome; the redemption is refused only when nothing is left after merging. With the one registered call type that is exactly "every entry dropped".
  • No generic single-entry rule. single_entry_required comes from the mcp_tool_call hook (Add the MCP tool-call details type #7283), not from the redemption code, so a future type may allow several entries. Two entries of two different registered types are each judged by their own hook.
  • Parameter refusal order differs by handler. The ID-JAG handler refuses the parameter after client authentication and the client's grant check, before the ID-JAG is validated, and logs at WARN once per client and reason and at DEBUG after (claim refusals: once per issuer and reason). The plain handler refuses it after the assertion validates and the issuer is enabled, and logs at WARN once per issuer and at DEBUG after, like the AS-3 claim refusal: that grant needs no client authentication and a refused assertion is not consumed, so one assertion can be resent.
  • No registry means unknown_type for any well-shaped claim, even an entry without a type, so the WARN line always tells the operator a registration is missing. That line names at most eight types, and logs any type that is not a short URI-like name as <invalid>, so no free-form claim text reaches the log.
  • Code choice. A refused claim content uses RFC 9396's invalid_authorization_details as Authorization server: narrow a JWT-bearer access token to one MCP call with authorization_details #7061 specifies, not the draft's invalid_grant (§4.4.3), so the client gets an actionable reason. Comment at detailsRefusal.
  • JWTBearerIssuanceFactory takes no options. The plain handler applies none (it refuses the claim and the parameter without a registry), and Add a per-client access token lifespan for ID-JAG redemption #7284 adds options only to the ID-JAG factory, so adding an unused variadic here would be dead surface. "Add a per-client access token lifespan for ID-JAG redemption" (Add a per-client access token lifespan for ID-JAG redemption #7284) also adds options ...FactoryOption to IDJAGIssuanceFactory; expect a small conflict there.
  • Hook contract. A hook registered for both token exchange and JWT-bearer checks Request.Exchange or Request.Redemption for nil instead of trusting that an empty field is empty for the right reason.
  • Stored sessions. session.Session.UnmarshalJSON keeps authorization_details as json.RawMessage when a stored session is decoded, so memory and Redis hold the same bytes and big integers keep every digit.
  • Size. About 335 added code lines (547 with comments, 131 removed) over 15 non-test files, above the 400-line / 10-file guidance. The raw-bytes step is a separate, behaviour-preserving first commit and can become its own PR if reviewers prefer.

🤖 Generated with Claude Code

rdimitrov and others added 2 commits November 25, 2026 00:21
Redemption will process the authorization_details claim an ID-JAG
carries, and the issued token must carry the entries exactly as signed.
The claims decoded through map[string]any lose integer precision above
2^53, so verifySignature now also decodes the verified payload into a
map of raw members and keeps the authorization_details bytes in
ValidatedClaims.AuthorizationDetails (nil when absent). A map, not a
struct field, so a member in another letter case does not match.

No behaviour changes: nothing reads the new field yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ID-JAG draft section 4.4.1 requires the redeeming server to process the
authorization_details claim the ID-JAG's issuer signed, and a gateway
token narrowed to one MCP call depends on it. Until now redemption
refused every assertion that carried the claim.

The ID-JAG handler now processes the claim after subject resolution and
before the ID-JAG is consumed: a claim that is not a non-empty array of
objects is invalid_assertion; a type not registered for the JWT-bearer
grant (or no registry) is unknown_type; a shape problem is
malformed_entry; the registered hooks decide; and every granted entry
must equal a distinct signed entry as a JSON value, so a hook can drop
whole entries but never change or add one (server_error). The granted
entries go into the access token and the token response from the same
raw bytes, so large integers keep every digit. Narrowing inside an
entry is left to "Narrow authorization_details on token exchange and
refresh" (#6912).

Both redemption forms refuse the authorization_details parameter with
parameter_not_allowed, and the plain RFC 7523 grant keeps refusing the
claim. The hook sees the authenticated client, the granted resource,
the ID-JAG's sub, and a new Subject.ResolvedUser for a resolve issuer.
Registry.Parse reports ErrUnknownType so the two refusals differ. A
registry is now reachable with the JWT-bearer grant alone.

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 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.39777% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.97%. Comparing base (faa0076) to head (f47fbdd).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...erver/authorizationdetails/authorizationdetails.go 97.22% 2 Missing ⚠️
pkg/authserver/server/session/session.go 87.50% 2 Missing ⚠️
...ver/server/tokenexchange/multi_issuer_validator.go 92.85% 1 Missing ⚠️
...hserver/server/tokenexchange/redemption_details.go 98.63% 1 Missing ⚠️
pkg/authserver/server/tokenexchange/validator.go 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7290      +/-   ##
==========================================
+ Coverage   81.92%   81.97%   +0.04%     
==========================================
  Files         922      923       +1     
  Lines       93314    93556     +242     
==========================================
+ Hits        76451    76691     +240     
- Misses      16858    16860       +2     
  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.

Resolve the conflicts with the per-client lifespan and the MCP tool-call
type. The ID-JAG factory now applies both the client lifespans and the
authorization details registry, so drop the registry refusal and its
test case. The arch doc keeps both new paragraphs and states that an
ID-JAG's signed mcp_tool_call entry goes through the type's hook on
redemption.

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.

A few things that aren't anchored to a changed line:

  1. Rebase: "Add a per-client access token lifespan for ID-JAG redemption" (#7284) and "Add the MCP tool-call details type" (#7283) both landed since this branch was cut, and it no longer merges cleanly (docs/arch/17, factory.go, id_jag_handler.go, redeemer.go). Details inline on IDJAGIssuanceFactory.

  2. Release order: with "Add the MCP tool-call details type" (#7283) on main, toolcalldetails registers for both token exchange and jwt-bearer, so an embedder that registers it gets single-call tokens out of redemption as soon as this merges. The vMCP doesn't read authorization_details until "vMCP: accept an access token for the one call its authorization_details names, once" (#7062), so until then such a token is good for any call. Could the "Release order" section say that too: this PR, then #7062, then AS-1 signing the claim? Right now it only orders AS-1 vs AS-2.

  3. docs/arch/17-token-exchange-delegation.md:1554 (not in the diff): the check order for a resolve issuer is missing the two new steps. Something like: "client authentication and grant, the authorization_details parameter, assertion validation, jti, client binding, policy (resource), client audience, actor issuer, gate, resolution, actor policy, the authorization_details claim, consume, lifetime."

  4. docs/arch/17-token-exchange-delegation.md:1682 (not in the diff): the retry paragraph after the refusal table covers invalid_grant and access_denied but not the new code. Worth one sentence: an invalid_authorization_details refusal depends only on the signed details, so a re-issued ID-JAG with the same authorization_details gets the same answer; parameter_not_allowed goes away by dropping the parameter.

Comment thread pkg/authserver/config.go Resolved
Comment thread docs/authz.md Resolved
Comment thread pkg/authserver/config.go Resolved
rdimitrov and others added 2 commits November 25, 2026 13:24
Build the granted authorization_details from the signed entries a hook
keeps (Pending.GrantSubset), so the issued token carries the issuer's
bytes. A type whose hook keeps none of its entries is dropped; the
redemption is refused with empty_grant only when nothing is left. A
hook that returns a changed or added entry is still a server_error.
ErrNoEntries is removed and Pending.Grant is unchanged.

Keep the authorization_details claim raw when a session is decoded from
storage, refuse a repeated parameter with invalid_request, bound the
ID-JAG refusal WARN lines per (client or issuer, reason), require ID-JAG
redemption rather than any JWT-bearer issuer for registry reachability,
and record the resolved user on the redemption.

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
Keep the fields every grant fills on authorizationdetails.Request and
move the grant-specific ones into parts a hook checks for nil:
Exchange (actor, actor-token presence, requested token type, requested
scopes) on token exchange and Redemption (resolved user) on ID-JAG
redemption. ResolvedUser moves out of Subject. The MCP call hook now
grants only on ID-JAG redemption or on a token exchange for an ID-JAG,
and refuses a request with neither part.

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, all the earlier comments are addressed. GrantSubset handing back the signed bytes and empty_grant being decided once after merging are both nicer than what I asked for.

@rdimitrov
rdimitrov merged commit 8719e21 into main Nov 25, 2026
50 checks passed
@rdimitrov
rdimitrov deleted the as2-call-binding-4-as2-claim branch November 25, 2026 13:33
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
2 tasks
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.

2 participants