Skip to content

Gate ID-JAG by issuer assertion types - #6678

Merged
jhrozek merged 1 commit into
mainfrom
worktree-idjag-issuer-optin
Nov 22, 2026
Merged

jhrozek merged 1 commit into
mainfrom
worktree-idjag-issuer-optin

Conversation

@jhrozek

@jhrozek jhrozek commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A trusted issuer with the RFC 7523 JWT-bearer grant enabled also accepts ID-JAG assertions, and there is no way to say "this issuer is only for ID-JAG" or "only for plain assertions". Trusting an issuer for one form silently trusts it for the other, including cross-app-access delegation.
  • Add a per-issuer acceptedAssertionTypes list: jwt_bearer, id_jag, or both. Leaving it out accepts both, exactly as before, so existing deployments do not change.
  • The plain and ID-JAG handlers now filter issuers independently. An issuer that excludes a form gets the usual "issuer is not enabled for this grant" rejection for it. Both handlers stay registered whenever the grant is enabled, so that rejection stays precise.
  • When id_jag is listed explicitly, startup checks that this server's own issuer identifier, which is what the draft puts in an ID-JAG's aud, will be accepted: a configured acceptedAudiences must include it, and an empty list accepts it by default.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing — regenerated CRDs, API reference, swagger and the SDK with task operator-manifests, task crdref-gen and task docs; ran task sdk-test and the unit tests of pkg/authserver/..., cmd/thv-operator/api/... and cmd/thv-operator/pkg/controllerutil, which pass.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Changes

File Change
cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go Adds assertion-type CRD schema and documentation.
cmd/thv-operator/api/v1beta1/zz_generated.deepcopy.go Regenerates deep-copy support.
cmd/thv-operator/pkg/controllerutil/authserver.go Projects assertion types into runtime configuration.
cmd/thv-operator/pkg/controllerutil/authserver_inbound_grants_test.go Covers canonical configuration projection.
cmd/thv-operator/pkg/controllerutil/authserver_test.go Covers legacy configuration projection.
deploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_mcpexternalauthconfigs.yaml Regenerates external-auth CRD schema.
deploy/charts/operator-crds/files/crds/toolhive.stacklok.dev_virtualmcpservers.yaml Regenerates VirtualMCPServer embedded-auth schema.
deploy/charts/operator-crds/templates/toolhive.stacklok.dev_mcpexternalauthconfigs.yaml Regenerates Helm-wrapped external-auth CRD.
deploy/charts/operator-crds/templates/toolhive.stacklok.dev_virtualmcpservers.yaml Regenerates Helm-wrapped VirtualMCPServer CRD.
docs/arch/17-token-exchange-delegation.md Documents assertion-type trust and shared-binding behavior.
docs/operator/crd-api.md Regenerates CRD API reference.
docs/server/docs.go Regenerates server OpenAPI documentation.
docs/server/swagger.json Regenerates server OpenAPI contract.
docs/server/swagger.yaml Regenerates server OpenAPI contract.
pkg/authserver/inbound_grants.go Carries assertion types through canonical inbound-grant normalization.
pkg/authserver/inbound_grants_test.go Covers normalized assertion-type configuration.
pkg/authserver/server/tokenexchange/id_jag_handler.go Filters ID-JAG issuer policies and updates factory documentation.
pkg/authserver/server/tokenexchange/id_jag_handler_test.go Covers ID-JAG issuer filtering and bound redemption.
pkg/authserver/server/tokenexchange/jwt_bearer_handler.go Filters plain-assertion issuer policies.
pkg/authserver/server/tokenexchange/multi_issuer_validator.go Defines assertion types and validates runtime ID-JAG configuration.
pkg/authserver/server/tokenexchange/multi_issuer_validator_test.go Covers assertion-type and ID-JAG audience validation.
pkg/authserver/server_impl.go Registers assertion handlers only when an issuer opts into the matching type.
pkg/authserver/server_test.go Covers handler-factory gating.
sdk/go/client/client_test.go Bumps the published schema count for the new schema.
sdk/go/client/oas_json_gen.go Regenerates SDK JSON types.
sdk/go/client/oas_schemas_gen.go Regenerates SDK schemas.
sdk/go/client/oas_validators_gen.go Regenerates SDK validation.
sdk/go/openapi.json Regenerates SDK OpenAPI contract.
sdk/go/openapi.yaml Regenerates SDK OpenAPI contract.

Does this introduce a user-facing change?

Yes, and it is opt-in. Existing configuration behaves as it does today.

Before: an issuer with jwtBearerGrant always accepted both plain RFC 7523 assertions and ID-JAGs, and an operator could not choose.

After: with acceptedAssertionTypes omitted, the same. With [id_jag] or [jwt_bearer], the issuer is limited to that form, and the other form is refused with invalid_grant ("issuer is not enabled for this grant"). Listing id_jag explicitly makes startup fail when a configured acceptedAudiences lacks this server's own issuer identifier, or when acceptedAudiences is empty and the issuer is also listed in allowed_audiences (a resource), because the default that accepts the issuer is dropped in that case.

Two smaller changes follow from the same code:

  • The startup error "JWT-bearer issuance requires at least one enabled trusted issuer" is gone for each handler. A configuration where every issuer excludes one form now starts, and requests for that form are rejected as above.
  • The startup warning about blanket self-issued token exchange (redeems_id_jag) now appears when an issuer accepts id_jag, not whenever the grant is enabled. With the default setting the two are the same.

Special notes for reviewers

  • An empty acceptedAudiences already 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.
  • subjectBindings are 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, whenever jwt_bearer is accepted. List only [id_jag] to avoid that.
  • The default is applied in Go (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.

@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Sep 17, 2026
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.36066% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 81.59%. Comparing base (2d33d6b) to head (539f10d).

Files with missing lines Patch % Lines
cmd/thv-operator/pkg/controllerutil/authserver.go 91.66% 1 Missing ⚠️
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.
📢 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.

@aron-muon aron-muon 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.

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. All tokenexchange tests 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 new AcceptedAssertionTypes field 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:

  1. 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 silent invalid_grant regression.

  2. Diagnostics regression at the no-opt-in boundary: when no issuer accepts id_jag, the bound handler isn't registered at all, so a recognized oauth-id-jag+jwt assertion falls through to fosite's generic invalid_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.

@jhrozek

jhrozek commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Note for when I pick this back up (it now conflicts with main):

@jhrozek
jhrozek force-pushed the worktree-idjag-issuer-optin branch from 3bf8c24 to 0dc7d94 Compare October 30, 2026 15:41
@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 Oct 30, 2026
@jhrozek
jhrozek force-pushed the worktree-idjag-issuer-optin branch from 0dc7d94 to 731ddde Compare October 30, 2026 15:52
@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 Oct 30, 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.

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 in mcpexternalauthconfig_types.go, the generated CRDs and docs/arch/17-token-exchange-delegation.md all say that omitted means both jwt_bearer and id_jag are 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_bearer only. 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_grant after upgrade. That lasts until it adds id_jag and puts the AS issuer in acceptedAudiences, because the explicit-id_jag startup 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 the redeems_id_jag WARN wording would need updating too.
  • 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>
@jhrozek
jhrozek force-pushed the worktree-idjag-issuer-optin branch from 731ddde to 539f10d Compare November 21, 2026 20:40
@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 21, 2026
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 21, 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 539f10d: still approve. Every earlier finding is resolved or withdrawn, and the new changes have no significant problem.

  1. Default for omitted acceptedAssertionTypes vs PR body: resolved. "Omitted means both" is kept, and the PR body now says so. Nothing changes on upgrade.
  2. Merge conflicts with main: resolved. The branch is rebased on v0.67.1, CRDs/swagger/SDK are regenerated, and buildJWTBearerFactories is still the single registration point.
  3. lll lint on the two field lines (aron-muon): resolved, both lines carry //nolint:lll.
  4. Upgrade/release-note concern (aron-muon): withdrawn. It assumed a plain-only default; with "both" as the default, no ID-JAG deployment loses anything.
  5. Generic invalid_request when no issuer accepts id_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

@jhrozek
jhrozek merged commit b29650b into main Nov 22, 2026
49 checks passed
@jhrozek
jhrozek deleted the worktree-idjag-issuer-optin branch November 22, 2026 09:38
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.

3 participants