Repository navigation
Extract the shared JWT-bearer redemption tail - #7249
Conversation
The ID-JAG handler held a whole plain JWT-bearer handler and reached into its fields, and both handlers kept their own copy of the steps after their checks. Per-client lifespans, the signed authorization_details claim and subject mapping all change those steps, and with one copy each lands once. A new unexported redeemer holds the replay consumer, the fosite config and the token helper. Each handler keeps its own checks, validator, token endpoint and policy map filtered by its assertion type, builds a redemption value, and calls the redeemer to finish and to issue the token. The redeemer does not embed the construction dependencies, so the unfiltered trusted issuer list stays out of reach at request time. The constructors validate every dependency first, so the runtime guards for a half-built handler and the test-only plain constructor go. No response, error text or log line changes. Co-authored-by: Mecatl <[email protected]>
rdimitrov
left a comment
There was a problem hiding this comment.
Approve. This is a behaviour-preserving extraction and I found no regression.
Design: The post-validation tail (consume the assertion, cap the lifetime, install the session and audience, issue the token) is one invariant, and it now lives in a single unexported redeemer. Each handler keeps its own front half (matching, client checks, validation, policy lookup, refusal mapping). IDJAGHandler no longer borrows a whole JWTBearerHandler and reaches into its fields. The redeemer is a named field rather than an embedded type, so no fosite handler methods are promoted. No wire, CRD, config or exported-API change on upgrade. The removed nil guards are unreachable because issuanceDeps.validate() rejects those cases first. Check order, replay key and purpose, and error mapping are unchanged for both handlers. The only reorder is the ID-JAG draft-departure log, which still runs only on success.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7249 +/- ##
==========================================
- Coverage 81.66% 81.66% -0.01%
==========================================
Files 903 904 +1
Lines 91738 91829 +91
==========================================
+ Hits 74915 74988 +73
- Misses 16818 16836 +18
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
The plain RFC 7523 JWT-bearer handler and the ID-JAG handler each kept their own copy of the steps that run after their checks: consume the assertion, cap the token lifetime at the assertion's expiry, build the session, set the granted audience, and issue the token. On top of that,
IDJAGHandlerheld a whole*JWTBearerHandlerascoreand reached into its fields (h.core.policies,h.core.consumer,h.core.config,h.core.validator, ...) to reuse them.Several planned changes touch exactly those steps, so with two copies each of them would have to be written twice:
authorization_detailson the assertion: a registry hook has to run on the claim before the assertion is consumed, and the result has to land in the issued token. Before this PR, that is one edit in each handler's tail plus each of the two session builders. After it, one step at the top ofredeemer.complete, and one newredemptionfield.redemptionfields that the ID-JAG front half fills in. Before, they would go throughnewIDJAGSessionandh.core.assertionBoundedLifetime.redeemer.assertionBoundedLifetime, which both handlers now call, instead of a field on the plain handler that the ID-JAG handler reads throughcore.What changed:
redeemer(redeemer.go) holding the replay consumer, the fosite config and the token helper.completeruns consume, lifetime, client replacement (plain only), audience and session.populateissues the token.redemptionvalue and calls the redeemer.IDJAGHandlerno longer holds aJWTBearerHandler, andnewIssuanceCoreis gone. The redeemer does not keep the construction inputs, so the unfiltered trusted issuer list is not reachable at request time.issuanceDeps.validate()first. That removes the runtime guards for a half-built handler ("The JWT-bearer grant is not fully configured.", "JWT-bearer token issuance is not configured."), which could no longer be reached, and the test-only constructornewJWTBearerHandler.No response, error text, status, replay key or log line changes.
Type of change
Test plan
pkg/authserver/server/tokenexchange/...andpkg/authserver)task test-e2e)task lint-fix)The tests for the shared steps moved into
redeemer_test.go. They still run through each handler'sHandleTokenEndpointRequestandPopulateTokenEndpointResponse, not against the redeemer directly. A gomock consumer pins the exact replay purpose, issuer, key and expiry per handler. They also cover a few things that were not tested before:act;jtireplay key;*fosite.AccessRequest.Changes
redeemer.goredeemer,redemption, and the consume, lifetime, session and populate steps moved from the plain handlerjwt_bearer_handler.gonewJWTBearerHandler,newIssuanceCore, the embeddedHandleHelperand the nil guardsid_jag_handler.gocore;newIDJAGSessionfolded into the redeemerissuance_deps.gocheckValidatorAndEndpointinlined intovalidate(), same errors and orderdocs/arch/17-token-exchange-delegation.mdredeemer.goandissuance_deps.goamong the key filesSpecial notes for reviewers
issuanceDeps. Embedding would put the unfiltered trusted issuer list one field away from both handlers at request time. Filtering that list per assertion type is what keeps ajwt_bearer-only issuer out of the ID-JAG grant, and the reverse.redemption.syntheticClientIDis one field, not a flag plus an ID, so the session'sclient_idcannot disagree with the client on the request. When it is set (plain), the request's client is replaced. When it is empty (ID-JAG), the authenticated client is used.