Skip to content

Add oauthproto/idjag with the XAA client and server rules - #7103

Merged
jhrozek merged 7 commits into
mainfrom
oauthproto-idjag
Nov 11, 2026
Merged

jhrozek merged 7 commits into
mainfrom
oauthproto-idjag

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The ID-JAG (Cross App Access) rules were spread through product code. The vMCP XAA client checked the IdP response inline, two validators each wrote the typ test that keeps an ID-JAG from being used as an access token, and someone who wants to learn how ToolHive does XAA had no single place to start. Add pkg/oauthproto/idjag: its doc.go walks through the flow in order with the draft sections, and it holds IsIDJAG (the shared typ test), FromExchange (the client's check of the IdP response, moved out of xaa.go) and ResourceClaim (reads the string-or-array resource claim and says whether it is well formed). The server-side jti and client_id binding checks stay inline in the redemption handler, where their only caller is.
  • The redemption handler shared one policy function with the plain RFC 7523 handler, which chose the resource and checked the subject binding in one step, and the assertion validator used the token endpoint as the only default audience without knowing which profile it was checking. The ID-JAG draft differs from RFC 7523 in exactly those two places, so aligning ID-JAG with the draft meant changing plain RFC 7523 too. Two refactor commits split that seam: each handler now chooses its own resource and passes its own default audiences. Nothing accepted or refused changes in them.
  • Log the ways an accepted ID-JAG departs from draft section 4.4.1, without refusing anything: several aud values, an aud that is not this server's issuer identifier, a malformed resource claim, and a requested resource that the claim does not name. The redemption handler has shipped since v0.50.0, so refusing these now could break deployments, and today nobody can tell which ones would be affected.
  • Two changes that only let requests through that were refused before (ID-JAG redemption: compare the requested resource with the assertion's resource claim, and decide the default when it is omitted #6892):
    • An ID-JAG redemption without a resource parameter uses the ID-JAG's resource claim when it holds a single value. Draft section 4.4 defines no resource parameter for redemption, and Okta's guide for resource authorization servers documents a redemption request with only grant_type, assertion and scope.
    • With no accepted_audiences configured, an ID-JAG may name this server's issuer identifier as aud, which is what draft section 4.4.1 requires and what Okta's guide tells resource servers to check, not only the token endpoint.
  • Name the RFC 8693 N_A token type and the issued_token_type member once, in oauthproto.

Refs #6898, #6892. This does not implement ID-JAG issuance.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe): refactoring and log-only diagnostics, plus two ID-JAG redemption changes that accept requests that were refused before

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint)

task lint reports 0 issues, including go vet ./.... Full task test passes except the pkg/container/docker tests that start real Squid and Envoy containers, which could not reach a Docker daemon on my machine and do not touch this code. On the final commit I also re-ran go test -race on pkg/authserver/..., pkg/oauthproto/... and the operator API, task docs-verify, task operator-manifests and task crdref-gen (no diff). Every commit builds and passes gocyclo on its own.

Changes

Commit What
Name RFC 8693 N_A and issued_token_type once TokenTypeNotApplicable and ParamIssuedTokenType instead of literals
Add oauthproto/idjag for the XAA client side New package with IsIDJAG and FromExchange; xaa.go, pkg/auth/token.go and the validator use it
Split resource choice from JWT-bearer policy checkAssertionMaxAge, requestedResource, checkSubjectBinding; no behaviour change
Let each handler set the default audience ValidateJWTBearerAssertion takes the default audiences from the handler; no behaviour change
Log ID-JAGs that depart from the draft Four log-only findings, idjag.ResourceClaim, arch doc
Default the ID-JAG resource to its claim ID-JAG handler only
Accept the issuer as ID-JAG audience ID-JAG handler only; comments on the RunConfig type and the CRD, regenerated swagger, SDK, CRD manifests and CRD API docs

Does this introduce a user-facing change?

Yes. Plain RFC 7523 JWT-bearer redemption does not change.

  • ID-JAG redemption without resource. Before: refused with invalid_request ("Exactly one resource parameter is required"). After: when the ID-JAG's resource claim holds one value ("a" or ["a"]), that value is used and goes through the same URI, subject-binding and client-audience checks as a requested one. No claim, several values, a malformed claim, an empty or repeated parameter: refused as before, with the same error.
  • One refusal changes its error. No resource parameter and a single claim value that is not an absolute URI. Before: invalid_request ("Exactly one resource parameter..."). After: invalid_target ("Resource must be an absolute URI"), the error a requested resource already gets for that.
  • ID-JAG aud = issuer. Before: with no accepted_audiences, only the token endpoint was accepted, so an ID-JAG whose aud is this server's issuer identifier was refused. After: both are accepted. A configured accepted_audiences list still replaces both defaults.
  • Startup warning. If this server's issuer identifier is also listed in allowed_audiences, the issuer is not accepted by default, because a resource access token must never pass as an assertion. The server starts and logs one WARN naming the issuer.
  • New log lines. ID-JAG departs from the draft; accepted for compatibility with issuer, client_id, finding (multiple_audiences, audience_not_issuer, resource_malformed, resource_not_covered) and, for audience_not_issuer, a hint. Only for requests that pass every check, replay and lifetime included. The first occurrence per assertion issuer and finding is a WARN, later ones are DEBUG. No subject, jti or claim values.
  • Two message texts. The vMCP XAA client's token_type error ended (draft §5.2) and now ends (draft §4.3.4), where the draft says it. The debug line for an IdP ID-JAG whose typ is not oauth-id-jag+jwt now reads ID-JAG typ header is not oauth-id-jag+jwt.

Special notes for reviewers

  • The departures are logged, not refused, on purpose; a strict mode, per issuer, is a separate decision that needs the logs first. The arch doc also lists two departures nothing logs: a public client identified only by client_id, and a cnf claim that no code reads.
  • The issuer default is skipped, not refused at startup, when the issuer is also a resource audience, so a configuration that starts today keeps starting.
  • Bind JWT-bearer resource to the assertion claim #7091 was closed; its idea (bind the resource to the ID-JAG's claim) is covered here in a form that does not touch plain RFC 7523 and does not refuse requests that work today.
  • Since the last review: idjag.Verify is gone (the binding check is back inline), the log runs only after replay and lifetime checks, the audience_not_issuer line carries a hint, and malformed resource claims are a finding of their own.
  • The commits read best in order.

@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 10, 2026 22:28
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 10, 2026
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.63946% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.07%. Comparing base (d702679) to head (d3cc5fa).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
.../authserver/server/tokenexchange/id_jag_handler.go 98.55% 1 Missing ⚠️
pkg/oauthproto/idjag/exchange.go 96.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7103      +/-   ##
==========================================
+ Coverage   80.93%   81.07%   +0.14%     
==========================================
  Files         867      873       +6     
  Lines       88888    89211     +323     
==========================================
+ Hits        71939    72326     +387     
+ Misses      16944    16880      -64     
  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.

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The refactor part keeps behaviour the same. The new departure logging has two correctness problems, and Verify adds indirection that buys nothing, so I'm commenting rather than approving.

Design:

  • Right placement. The client-side IdP response checks (FromExchange) and the typ predicate (IsIDJAG) now live in pkg/oauthproto/idjag. That fits: IsIDJAG replaces copies in pkg/auth/token.go and the validator, and the layout matches tokenexchange/jwtbearer.
  • Wrong placement. The client-binding rule (Verify) is a server-only redemption check with a single caller, IDJAGHandler, so moving it into oauthproto puts it one layer away from where it is used.
  • Scope. The departure logging is a separate feature that shares a PR with a refactor meant to change nothing, and it pushes the PR to about 15 non-test/doc files.

Findings

  1. The "accepted for compatibility" log can fire for a request that is then refused.

    • Where: pkg/authserver/server/tokenexchange/id_jag_handler.go:177. logDraftDepartures runs before consumeAssertion and the bounded-lifetime check.
    • Scenario: a replayed ID-JAG with aud = token endpoint is refused with invalid_grant. It still logs "accepted for compatibility", and since the WARN fires once per issuer and finding, that misleading line may be the only one the operator ever sees.
    • This contradicts docs/arch/17-token-exchange-delegation.md ("When it accepts one") and the function's own doc comment.
    • Fix: call it after the assertion is consumed and the lifetime check passes, and add a test for replay plus departure.
  2. With default config, every accepted ID-JAG triggers audience_not_issuer, and the log implies the IdP is at fault.

    • Where: id_jag_handler.go:233; the default comes from multi_issuer_validator.go:702.
    • With accepted_audiences empty, the validator accepts only aud == token endpoint. So a draft-conformant ID-JAG (aud == issuer) is rejected, and every one that is accepted is reported as a departure.
    • Our own client makes this certain: FromExchange requires aud to equal the requested audience exactly, so vMCP against a default ToolHive AS always trips it.
    • The message points the operator at the IdP when the fix is ToolHive config.
    • Fix: when this finding fires and accepted_audiences is empty, add a hint to the log line (e.g. "add the issuer identifier to jwt_bearer_grant.accepted_audiences"). Operators read logs, not arch docs.
  3. Verify adds a layer with nothing to share it.

    • Where: pkg/oauthproto/idjag/verify.go:62 and id_jag_handler.go:277-301.
    • The handler builds Presented/Expected structs, calls Verify, then maps the four sentinels back to the same fosite errors and hints that checkClientBinding produced inline.
    • The default: arm (id_jag_handler.go:299) can never run, because Verify only returns those four errors, unwrapped.
    • Fix: keep the binding check in the handler and have idjag/doc.go point to it.
  4. An empty or non-string resource claim is silently skipped.

    • Where: id_jag_handler.go:236-238. idjag.ResourceClaim returns nil for resource: [] or resource: [42], so the len(claimed) > 0 guard skips resource_not_covered.
    • The arch doc hunk says this case is logged.
    • Fix: fire whenever the claim is present and does not contain the requested resource, or say in the doc that malformed claims are ignored.
    • No test covers [].

Simpler alternative: Ship one PR with the constants, IsIDJAG, FromExchange, ResourceClaim and doc.go, and leave the binding check in the handler. Ship the departure logging separately, ideally after #7091 lands since it touches the same handler. Call the logging after the assertion is consumed, and include the remediation hint for audience_not_issuer.

🤖 Reviewed with Claude Code

jhrozek and others added 7 commits November 11, 2026 12:42
The token_type value N_A and the issued_token_type response member
were spelled as literals in the auth server handlers, the token
exchange client and the vMCP XAA strategy, and the refresh-token
handler kept its own private copy of N_A. The ID-JAG protocol code
that moves into oauthproto next needs one shared definition of
both, so the consumers and the issuer cannot drift apart.

Both names move to oauthproto next to the token type URNs. Wire
values and error text are unchanged.

Refs #6898

Co-authored-by: Mecatl <noreply@mecatl.dev>
The rules for an ID-JAG were spread through product code: the vMCP XAA
client checked the IdP response inline, and two validators each wrote
the typ test that keeps an ID-JAG from being used as an access token.
Someone who wants to learn how ToolHive does Cross App Access had no
single place to start.

This adds pkg/oauthproto/idjag. Its doc.go walks through the flow in
order: the RFC 8693 exchange at the IdP, then the RFC 7523 redemption.
The package has three functions. IsIDJAG is the typ test, and the two
validators now share it. FromExchange takes the token that the exchange
client returns and checks it against what was requested: the token
types, a parsable JWT, a single matching audience and, when one was
asked for, a matching resource. ResourceClaim reads the string-or-array
resource claim. FromExchange does not import the exchange client, so it
adds no import cycle. The XAA client calls it, and the package doc of
oauthproto gains a short reading guide.

What is accepted and refused does not change. Two diagnostic texts do:
the token_type error cited draft section 5.2 and now cites section
4.3.4, which is where the draft says it, and the debug line for a typ
header that is not the ID-JAG type has new wording, because it is now
logged from the library and not from the XAA client. The tests for the
XAA client keep passing, and a new table test pins each rule.

Refs #6898

Co-authored-by: Mecatl <noreply@mecatl.dev>
validateJWTBearerPolicy checked the assertion's age, chose the resource
from the request's single resource parameter, and checked the subject
binding, and both the plain RFC 7523 handler and the ID-JAG handler
called it. The ID-JAG profile needs to choose its resource differently
(the draft's resource claim), and doing that inside the shared function
would change plain RFC 7523 assertions too.

Split it into checkAssertionMaxAge, requestedResource and
checkSubjectBinding. Each handler calls them in the old order, and
errors and hints are unchanged. New handler tests pin that the age check
still runs before the resource check.

Refs #6892

Co-authored-by: Mecatl <noreply@mecatl.dev>
ValidateJWTBearerAssertion took the token endpoint and used it as the
only accepted audience when the issuer configures no
accepted_audiences. The validator cannot tell a plain RFC 7523
assertion from an ID-JAG, yet the ID-JAG draft (section 4.4.1) wants
this server's issuer identifier in aud, so the default has to come from
the handler that knows the profile.

Take the default audiences from the caller instead. Both handlers pass
the token endpoint, so nothing accepted or refused changes. Configured
accepted_audiences still take precedence, and an empty default is
refused as a programming error.

Refs #6892

Co-authored-by: Mecatl <noreply@mecatl.dev>
The ID-JAG handler accepts some assertions that the draft does not
allow: an aud with several values, an aud that is not this server's
issuer identifier, a malformed resource claim, and a request for a
resource that the resource claim does not name. Existing deployments
may depend on that, so refusing them now could break customers, and
today nobody can tell which deployments would be affected.

The handler now works out those departures once a request has passed
every check, including replay and the assertion lifetime, and logs each
one. A refused request logs nothing, so an "accepted" line is never
written for a replay. The first occurrence for an assertion issuer and
departure is a warning, and later ones are debug lines. A line carries
the issuer, the client ID and the name of the departure, never the
subject, the jti or a claim value. The aud line also carries a hint
naming jwt_bearer_grant.accepted_audiences, because with no configured
list the handler accepts only the token endpoint, so the fix is
usually in ToolHive's config rather than at the IdP.

idjag.ResourceClaim reads the resource claim and reports whether it is
well formed (draft section 3), so the handler can tell a malformed
claim from one that names another resource. FromExchange uses it
without changing what the client accepts.

What the handler accepts and refuses is unchanged. The architecture
doc lists the departures, and two more that nothing logs: a public
client identified only by client_id, and a cnf claim that no code
reads.

Refs #6898

Co-authored-by: Mecatl <noreply@mecatl.dev>
An ID-JAG redemption had to carry exactly one resource parameter, but
the ID-JAG draft (section 4.4) defines no resource parameter for
redemption, so a client that follows the draft and leaves it out got
invalid_request even when the ID-JAG itself names a single resource.

When the request has no resource parameter at all and the ID-JAG's
resource claim is well formed with exactly one value, use that value.
It goes through the same URI, subject-binding and client-audience
checks as a requested resource. Every other case keeps today's rule
and error: no claim, several values, a malformed claim, or an empty or
repeated parameter. Only requests that were refused before can now
succeed. One refused request changes its error: with no parameter and
a single claim value that is not an absolute URI, the answer is now
invalid_target ("Resource must be an absolute URI"), the error a
requested resource already gets, instead of invalid_request.

Plain RFC 7523 assertions are unchanged; a test pins that a resource
claim does not become a default there.

Refs #6892

Co-authored-by: Mecatl <noreply@mecatl.dev>
The ID-JAG draft (section 4.4.1) says an ID-JAG's aud is the resource
authorization server's issuer identifier. With no accepted_audiences
configured, ToolHive accepted only the token endpoint, so an ID-JAG
that follows the draft was refused unless the operator listed the
issuer by hand.

When the assertion issuer configures no accepted_audiences, the ID-JAG
handler now accepts this server's issuer identifier as well as the
token endpoint. A configured list still replaces both defaults, and
plain RFC 7523 assertions still accept only the token endpoint. This
is safe because an ID-JAG is already refused as an RFC 8693 subject
token and as an access token, and both values name this server. The
one exception: when the issuer identifier is also a resource audience
(allowed_audiences), the issuer stays out of the defaults, because an
access token minted for that resource must never pass as an assertion.
The server then logs one warning at startup instead of refusing to
start.

The audience_not_issuer hint for the empty-list case now says the
issuer is accepted and the IdP should use it. When the issuer is a
resource audience, audience_not_issuer is not logged at all, because
no IdP could fix it. The AcceptedAudiences comments on the RunConfig
type and the operator CRD describe the new defaults; swagger, the Go
SDK, the CRD manifests and the CRD API docs are regenerated from them.

Refs #6892

Co-authored-by: Mecatl <noreply@mecatl.dev>
@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 11, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-review of d3cc5fa: all four earlier findings are fixed and the new code looks correct, but the PR description no longer matches what the PR does, and the PR now mixes a refactor with changes to what the server accepts.

  1. Departure log fires for refused requests: resolved. logDraftDepartures now runs after consumeAssertion and assertionBoundedLifetime, and there are tests for replay, lifetime and client-audience refusals.
  2. audience_not_issuer fires on default config and blames the IdP: resolved. With accepted_audiences empty, the issuer is now accepted as aud. The log carries a hint that depends on the config, and the finding is suppressed when the issuer is also a resource audience.
  3. Verify adds a layer nothing shares: resolved. verify.go is deleted and checkClientBinding is back inline.
  4. Empty or non-string resource claim silently skipped: resolved. The new resource_malformed finding has a test row for each malformed shape.

Design: the PR is no longer a pure refactor. On the default config, the ID-JAG redemption handler now accepts the issuer identifier as aud. It also uses a single-valued resource claim when the request has no resource parameter. The plain RFC 7523 handler is unchanged. I traced both new defaults and found no hole:

  • TokenURL is always derived from Issuer, so accepting the issuer names the same server the token endpoint already named.
  • A resource taken from the claim still goes through ValidateAudienceURI, the subject binding and the client-audience check.
  • Each binding's AllowedResources must already sit inside AllowedAudiences.
  1. The PR body and type of change are now wrong.
    • The Summary still says "What the server accepts and refuses does not change". It also describes idjag.Verify, ticks refactoring plus log-only diagnostics, and refers to a conflict with #7091 (now closed).
    • The PR actually widens what the default config accepts (issuer as aud, and resource taken from the claim) and returns invalid_target for a claim taken as the default that is not an absolute URI.
    • It also changes the AcceptedAudiences CRD field description, with regenerated CRDs, swagger and SDK.
    • Scenario: release notes are built from PR bodies. Operators who upgrade would get no notice that ID-JAGs with aud set to the issuer are now accepted by default.
    • Fix: rewrite the Summary, Type of change, user-facing change and reviewer notes to match the current code.
  2. The scope is past the PR limits and mixes a refactor with behaviour changes.
    • About 16 non-test, non-generated files have changed, against a limit of 10.
    • Commits 1–2 (the idjag package move, meant to change no behaviour) sit in the same PR as the new acceptance rules in commits 3–7.
    • Scenario: reverting the issuer-as-aud default would also undo the package move.
    • Fix: split it. One PR for the refactor, and a second "ID-JAG draft conformance" PR for the behaviour changes.
  3. pkg/authserver/server/tokenexchange/jwt_bearer_handler.go:578: no test checks that the guard against the issuer also being a resource is wired up.
    • That guard only works if IDJAGIssuanceFactory passes config.AllowedAudiences into newIDJAGIssuanceHandler.
    • Every issuerIsResource test builds the handler directly with the list already filled in. The only factory test stops at an earlier error.
    • Scenario: a later refactor passes nil there. In a deployment where the issuer is also a resource audience, the issuer then quietly comes back as an accepted aud and the startup warning stops firing, with every test still green.
    • Fix: add a test that builds through IDJAGIssuanceFactory with AllowedAudiences containing the issuer. It should assert that the warning fires and that an assertion with aud set to the issuer is refused.

🤖 Reviewed with Claude Code

@jhrozek

jhrozek commented Nov 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review and the approval.

  1. Right, the body was still describing the old branch. I've rewritten it: the Summary leads with the two ID-JAG changes, Type of change no longer says refactoring only, and the user-facing section lists each change as before/after (issuer as aud by default, resource taken from a single-value claim, the invalid_target case, the startup warning, the new log lines). The Bind JWT-bearer resource to the assertion claim #7091 note is gone since it's closed.

  2. I'd like to keep it as one PR. The seven commits already keep the move and the seam refactors apart from the three behaviour commits, so each can be read and, if it comes to that, reverted on its own.

  3. Good catch, nothing pins that IDJAGIssuanceFactory passes AllowedAudiences through. I'll add the factory-level test (issuer in AllowedAudiences: the warning fires and an ID-JAG with aud set to the issuer is refused) in a small follow-up PR right after this one.

@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 11, 2026
@jhrozek
jhrozek merged commit d850354 into main Nov 11, 2026
80 of 81 checks passed
@jhrozek
jhrozek deleted the oauthproto-idjag branch November 11, 2026 14:46
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