Repository navigation
Gate ID-JAG by issuer assertion types - #6678
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6678 +/- ##
==========================================
+ Coverage 81.58% 81.59% +0.01%
==========================================
Files 898 898
Lines 91550 91580 +30
==========================================
+ Hits 74690 74729 +39
+ Misses 16855 16846 -9
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aron-muon
left a comment
There was a problem hiding this comment.
Ran this branch through the same calibrated environment used to verify #6677 (whole-repo task targets, with a known baseline of 12 packages that fail identically on pristine main for environment reasons — workloads tmp-path tests, a pkg/api/v1 panic, network-dependent retriever, etc.):
task test: only the 12 baseline packages fail; zero new failures. Alltokenexchangetests pass, including the new filtering/gating coverage. (The socket-path failure your test plan mentions didn't reproduce here, consistent with it being a tmpdir-length environment issue.)task lint: two real findings that will fail the Lint job —lll(>130 chars) on both newAcceptedAssertionTypesfield lines:pkg/authserver/inbound_grants.go:43(137 chars)pkg/authserver/server/tokenexchange/multi_issuer_validator.go:160(134 chars)
On the design: agreed that accepting ID-JAGs implicitly wherever a jwt-bearer policy exists widened the issuer trust decision without an explicit opt-in — #6677 consciously piggybacked on the existing policy to avoid new config surface, and this is the right correction. The fail-loud config validation (accepted_audiences must include the AS issuer when id_jag is enabled) also matches what we hit in practice: our live Okta deployment already carries the bare issuer URL in acceptedAudiences because Okta mints the JAG aud from the resource connection's audience field, so real-world configs pass this check naturally.
Two observations, neither blocking:
-
Upgrade note worth a line in the release notes: a deployment that enabled ID-JAG under #6677's behavior (ours is presumably the only one) silently loses it on upgrade until
accepted_assertion_types: [jwt_bearer, id_jag]is added. For deployments running dev images on released charts, the new CRD field is pruned by the apiserver until the next chart release ships updated CRDs — so the practical migration there is "hold the image pin until the chart lands, or hand-apply the updated CRDs." Fine for us, just worth stating so nobody debugs a silentinvalid_grantregression. -
Diagnostics regression at the no-opt-in boundary: when no issuer accepts
id_jag, the bound handler isn't registered at all, so a recognizedoauth-id-jag+jwtassertion falls through to fosite's genericinvalid_request("...redirect_uri..." boilerplate) — the exact hard-to-diagnose failure mode that motivated #6676 (open question 3 there). The constructor's at-least-one-issuer requirement is why registration is gated, so one option is relaxing that requirement for the bound handler specifically: registered-with-empty-policies would reject with its precise "issuer is not enabled for this grant" hint instead. Happy to leave that as a follow-up either way.
The shared-subject-bindings consequence being documented rather than split per-type seems right for now — splitting bindings per assertion type would double the config surface for a case nobody has yet.
|
Note for when I pick this back up (it now conflicts with main):
|
3bf8c24 to
0dc7d94
Compare
0dc7d94 to
731ddde
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
I looked at upgrade impact and correctness. The gating itself looks right: each handler filters issuers through IssuersAcceptingAssertionType, and both handlers stay registered when their policy map is empty, so an excluded form gets the precise "issuer is not enabled" rejection. The explicit-id_jag audience check doesn't fire when the field is unset, so existing configs keep starting. One blocker-level question before merge:
1. The default for an omitted acceptedAssertionTypes disagrees between the code and the PR body.
- Code: both types.
effectiveAssertionTypes(pkg/authserver/server/tokenexchange/multi_issuer_validator.go), the CRD field doc inmcpexternalauthconfig_types.go, the generated CRDs anddocs/arch/17-token-exchange-delegation.mdall say that omitted means bothjwt_bearerandid_jagare accepted. The tests pin the same thing ("unset assertion types keep prior behavior"). - PR body: plain only. The Summary, the user-facing section and your later note all say omitted means plain
jwt_beareronly. The user-facing section says "Existing omitted configuration continues to accept only plain RFC 7523 JWT-bearer assertions", which is not what the code does. - What follows:
- As written, nothing breaks on upgrade. But the stated motivation ("trusting an issuer for plain JWT-bearer should not silently accept ID-JAGs") is only met when an operator sets
[jwt_bearer]. It is opt-in hardening, not a changed default. - If you flip the default to plain-only as your note plans, every deployment that redeems ID-JAGs today (shipped in v0.50.0) gets
invalid_grantafter upgrade. That lasts until it addsid_jagand puts the AS issuer inacceptedAudiences, because the explicit-id_jagstartup check then applies. So some configs will also fail to start, not just reject requests. That needs the release note and upgrade steps @aron-muon asked for. The arch doc ("upgrading changes nothing"), the CRD field doc and theredeems_id_jagWARN wording would need updating too.
- As written, nothing breaks on upgrade. But the stated motivation ("trusting an issuer for plain JWT-bearer should not silently accept ID-JAGs") is only met when an operator sets
- Suggested fix: pick one default and make the code, CRD docs, arch doc and PR body agree on it.
2. Merge conflicts. The branch conflicts with main, which is about 30 commits ahead and touches pkg/authserver/server_impl.go. After rebasing, regenerate the CRDs, swagger and SDK files, then re-check that buildJWTBearerFactories is still the only place the factories get registered.
Nothing else material. Leaving this as a comment because of item 1.
A trusted issuer configured for the JWT-bearer grant accepts both plain RFC 7523 assertions and ID-JAG cross-app-access assertions. Trusting an issuer for service-account assertions therefore also trusts it as an IdP for a different resource owner, and trusting an IdP for ID-JAG also lets its other signed JWTs be redeemed on the credential-free plain path. Add AcceptedAssertionTypes (jwt_bearer|id_jag) to JWTBearerGrantConfig and use it to filter each handler's issuer policies independently, so an operator can restrict an issuer to one form. Nil and empty values keep accepting both forms, so existing deployments, including ID-JAG users since v0.50.0, behave as before; invalid runtime values are rejected. When id_jag is listed explicitly, startup fails unless this authorization server's issuer is accepted as an assertion audience: a configured AcceptedAudiences must include it, and an empty list must not coincide with the issuer also being an allowed audience, which drops the default. Both forms share subject bindings, so the CRD and runtime documentation make clear that a binding also authorizes credential-free plain JWT-bearer redemption whenever jwt_bearer is accepted. Co-authored-by: mecatl <noreply@mecatl.dev>
731ddde to
539f10d
Compare
rdimitrov
left a comment
There was a problem hiding this comment.
Re-review of 539f10d: still approve. Every earlier finding is resolved or withdrawn, and the new changes have no significant problem.
- Default for omitted
acceptedAssertionTypesvs PR body: resolved. "Omitted means both" is kept, and the PR body now says so. Nothing changes on upgrade. - Merge conflicts with main: resolved. The branch is rebased on v0.67.1, CRDs/swagger/SDK are regenerated, and
buildJWTBearerFactoriesis still the single registration point. llllint on the two field lines (aron-muon): resolved, both lines carry//nolint:lll.- Upgrade/release-note concern (aron-muon): withdrawn. It assumed a plain-only default; with "both" as the default, no ID-JAG deployment loses anything.
- Generic
invalid_requestwhen no issuer acceptsid_jag: resolved. Both handlers stay registered with empty policy maps, and the error now reads "issuer is not enabled for this grant".
Design: unchanged. Per-issuer acceptedAssertionTypes is the right owner, the default is applied in Go, and the two handlers filter independently and route on the typ header, so an issuer limited to one type cannot be redeemed through the other. The only functional change since our review is the explicit-id_jag audience rule: a non-empty acceptedAudiences must include this server's issuer, and an empty list fails startup only if the issuer is also in allowed_audiences, which drops main's issuer-by-default audience. This only fires when id_jag is listed explicitly, so existing configs are unaffected. It is checked at reconcile time and at startup.
Two PR-body nits, not blocking: the Changes table says handlers are registered only when an issuer opts in, but the code always registers both. The Test plan boxes for unit tests and linting are unchecked.
🤖 Reviewed with Claude Code
Summary
acceptedAssertionTypeslist:jwt_bearer,id_jag, or both. Leaving it out accepts both, exactly as before, so existing deployments do not change.id_jagis listed explicitly, startup checks that this server's own issuer identifier, which is what the draft puts in an ID-JAG'saud, will be accepted: a configuredacceptedAudiencesmust include it, and an empty list accepts it by default.Type of change
Test plan
task test)task test-e2e)task lint-fix)task operator-manifests,task crdref-genandtask docs; rantask sdk-testand the unit tests ofpkg/authserver/...,cmd/thv-operator/api/...andcmd/thv-operator/pkg/controllerutil, which pass.API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.gocmd/thv-operator/api/v1beta1/zz_generated.deepcopy.gocmd/thv-operator/pkg/controllerutil/authserver.gocmd/thv-operator/pkg/controllerutil/authserver_inbound_grants_test.gocmd/thv-operator/pkg/controllerutil/authserver_test.godeploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_mcpexternalauthconfigs.yamldeploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_virtualmcpservers.yamldeploy/charts/operator-crds/templates/toolhive.stacklok.dev_mcpexternalauthconfigs.yamldeploy/charts/operator-crds/templates/toolhive.stacklok.dev_virtualmcpservers.yamldocs/arch/17-token-exchange-delegation.mddocs/operator/crd-api.mddocs/server/docs.godocs/server/swagger.jsondocs/server/swagger.yamlpkg/authserver/inbound_grants.gopkg/authserver/inbound_grants_test.gopkg/authserver/server/tokenexchange/id_jag_handler.gopkg/authserver/server/tokenexchange/id_jag_handler_test.gopkg/authserver/server/tokenexchange/jwt_bearer_handler.gopkg/authserver/server/tokenexchange/multi_issuer_validator.gopkg/authserver/server/tokenexchange/multi_issuer_validator_test.gopkg/authserver/server_impl.gopkg/authserver/server_test.gosdk/go/client/client_test.gosdk/go/client/oas_json_gen.gosdk/go/client/oas_schemas_gen.gosdk/go/client/oas_validators_gen.gosdk/go/openapi.jsonsdk/go/openapi.yamlDoes this introduce a user-facing change?
Yes, and it is opt-in. Existing configuration behaves as it does today.
Before: an issuer with
jwtBearerGrantalways accepted both plain RFC 7523 assertions and ID-JAGs, and an operator could not choose.After: with
acceptedAssertionTypesomitted, the same. With[id_jag]or[jwt_bearer], the issuer is limited to that form, and the other form is refused withinvalid_grant("issuer is not enabled for this grant"). Listingid_jagexplicitly makes startup fail when a configuredacceptedAudienceslacks this server's own issuer identifier, or whenacceptedAudiencesis empty and the issuer is also listed inallowed_audiences(a resource), because the default that accepts the issuer is dropped in that case.Two smaller changes follow from the same code:
redeems_id_jag) now appears when an issuer acceptsid_jag, not whenever the grant is enabled. With the default setting the two are the same.Special notes for reviewers
acceptedAudiencesalready accepts this server's issuer for ID-JAGs, so the startup check only fires for a configured list that lacks the issuer, or for the issuer-as-resource case above. The check looks at configuration only; request-time audience matching is unchanged.subjectBindingsare shared by both forms. A binding added for an ID-JAG's subject also permits that subject on the plain JWT-bearer grant, where client authentication can be skipped, wheneverjwt_beareris accepted. List only[id_jag]to avoid that.tokenexchange.IssuersAcceptingAssertionType), not as a CRD default. A CRD default would be written into every stored object and make "explicitly listed" true for all of them, and deployments that do not use Kubernetes never see CRD defaults.