Repository navigation
Add oauthproto/idjag with the XAA client and server rules - #7103
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
rdimitrov
left a comment
There was a problem hiding this comment.
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 thetyppredicate (IsIDJAG) now live inpkg/oauthproto/idjag. That fits:IsIDJAGreplaces copies inpkg/auth/token.goand the validator, and the layout matchestokenexchange/jwtbearer. - Wrong placement. The client-binding rule (
Verify) is a server-only redemption check with a single caller,IDJAGHandler, so moving it intooauthprotoputs 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
-
The "accepted for compatibility" log can fire for a request that is then refused.
- Where:
pkg/authserver/server/tokenexchange/id_jag_handler.go:177.logDraftDeparturesruns beforeconsumeAssertionand the bounded-lifetime check. - Scenario: a replayed ID-JAG with
aud= token endpoint is refused withinvalid_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.
- Where:
-
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 frommulti_issuer_validator.go:702. - With
accepted_audiencesempty, the validator accepts onlyaud == 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:
FromExchangerequiresaudto 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_audiencesis empty, add a hint to the log line (e.g. "add the issuer identifier tojwt_bearer_grant.accepted_audiences"). Operators read logs, not arch docs.
- Where:
-
Verifyadds a layer with nothing to share it.- Where:
pkg/oauthproto/idjag/verify.go:62andid_jag_handler.go:277-301. - The handler builds
Presented/Expectedstructs, callsVerify, then maps the four sentinels back to the same fosite errors and hints thatcheckClientBindingproduced inline. - The
default:arm (id_jag_handler.go:299) can never run, becauseVerifyonly returns those four errors, unwrapped. - Fix: keep the binding check in the handler and have
idjag/doc.gopoint to it.
- Where:
-
An empty or non-string
resourceclaim is silently skipped.- Where:
id_jag_handler.go:236-238.idjag.ResourceClaimreturns nil forresource: []orresource: [42], so thelen(claimed) > 0guard skipsresource_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
[].
- Where:
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
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>
dd0dd18 to
d3cc5fa
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
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.
- Departure log fires for refused requests: resolved.
logDraftDeparturesnow runs afterconsumeAssertionandassertionBoundedLifetime, and there are tests for replay, lifetime and client-audience refusals. audience_not_issuerfires on default config and blames the IdP: resolved. Withaccepted_audiencesempty, the issuer is now accepted asaud. The log carries a hint that depends on the config, and the finding is suppressed when the issuer is also a resource audience.Verifyadds a layer nothing shares: resolved.verify.gois deleted andcheckClientBindingis back inline.- Empty or non-string
resourceclaim silently skipped: resolved. The newresource_malformedfinding 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:
TokenURLis always derived fromIssuer, 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
AllowedResourcesmust already sit insideAllowedAudiences.
- 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, andresourcetaken from the claim) and returnsinvalid_targetfor a claim taken as the default that is not an absolute URI. - It also changes the
AcceptedAudiencesCRD 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
audset 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.
- The Summary still says "What the server accepts and refuses does not change". It also describes
- 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
idjagpackage 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-
auddefault 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.
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
IDJAGIssuanceFactorypassesconfig.AllowedAudiencesintonewIDJAGIssuanceHandler. - Every
issuerIsResourcetest 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
audand the startup warning stops firing, with every test still green. - Fix: add a test that builds through
IDJAGIssuanceFactorywithAllowedAudiencescontaining the issuer. It should assert that the warning fires and that an assertion withaudset to the issuer is refused.
- That guard only works if
🤖 Reviewed with Claude Code
|
Thanks for the re-review and the approval.
|
Summary
typtest 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. Addpkg/oauthproto/idjag: itsdoc.gowalks through the flow in order with the draft sections, and it holdsIsIDJAG(the sharedtyptest),FromExchange(the client's check of the IdP response, moved out ofxaa.go) andResourceClaim(reads the string-or-arrayresourceclaim and says whether it is well formed). The server-sidejtiandclient_idbinding checks stay inline in the redemption handler, where their only caller is.audvalues, anaudthat is not this server's issuer identifier, a malformedresourceclaim, and a requestedresourcethat 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.resourceparameter uses the ID-JAG'sresourceclaim when it holds a single value. Draft section 4.4 defines noresourceparameter for redemption, and Okta's guide for resource authorization servers documents a redemption request with onlygrant_type,assertionandscope.accepted_audiencesconfigured, an ID-JAG may name this server's issuer identifier asaud, which is what draft section 4.4.1 requires and what Okta's guide tells resource servers to check, not only the token endpoint.N_Atoken type and theissued_token_typemember once, inoauthproto.Refs #6898, #6892. This does not implement ID-JAG issuance.
Type of change
Test plan
task test)task test-e2e)task lint)task lintreports 0 issues, includinggo vet ./.... Fulltask testpasses except thepkg/container/dockertests 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-rango test -raceonpkg/authserver/...,pkg/oauthproto/...and the operator API,task docs-verify,task operator-manifestsandtask crdref-gen(no diff). Every commit builds and passes gocyclo on its own.Changes
TokenTypeNotApplicableandParamIssuedTokenTypeinstead of literalsIsIDJAGandFromExchange;xaa.go,pkg/auth/token.goand the validator use itcheckAssertionMaxAge,requestedResource,checkSubjectBinding; no behaviour changeValidateJWTBearerAssertiontakes the default audiences from the handler; no behaviour changeidjag.ResourceClaim, arch docDoes this introduce a user-facing change?
Yes. Plain RFC 7523 JWT-bearer redemption does not change.
resource. Before: refused withinvalid_request("Exactly one resource parameter is required"). After: when the ID-JAG'sresourceclaim 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.resourceparameter 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.aud= issuer. Before: with noaccepted_audiences, only the token endpoint was accepted, so an ID-JAG whoseaudis this server's issuer identifier was refused. After: both are accepted. A configuredaccepted_audienceslist still replaces both defaults.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.ID-JAG departs from the draft; accepted for compatibilitywithissuer,client_id,finding(multiple_audiences,audience_not_issuer,resource_malformed,resource_not_covered) and, foraudience_not_issuer, ahint. 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,jtior claim values.token_typeerror ended(draft §5.2)and now ends(draft §4.3.4), where the draft says it. The debug line for an IdP ID-JAG whosetypis notoauth-id-jag+jwtnow readsID-JAG typ header is not oauth-id-jag+jwt.Special notes for reviewers
client_id, and acnfclaim that no code reads.idjag.Verifyis gone (the binding check is back inline), the log runs only after replay and lifetime checks, theaudience_not_issuerline carries a hint, and malformedresourceclaims are a finding of their own.