Skip to content

Gate ID-JAG subject resolution behind a setting - #7254

Merged
jhrozek merged 2 commits into
mainfrom
as2-subject-mapping-1-config
Nov 23, 2026
Merged

jhrozek merged 2 commits into
mainfrom
as2-subject-mapping-1-config

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • An ID-JAG redemption always issues a token whose sub is <iss>#<sub>. When an issuer's ID-JAGs name a user in AS-2's own user table, that value is not a local user, so the gateway behind AS-2 can't find the user's connections. This PR adds the per-issuer setting that will select "resolve the subject to a local user". It does not add the resolution itself. That comes in later changes, and until then a code gate keeps resolve issuers closed.
  • Adds two Go-only (json:"-" yaml:"-") settings to JWTBearerGrantPolicy, mirrored on JWTBearerIssuerPolicyRunConfig and copied by applyJWTBearerPolicies, so embedders using inbound_grants reach them:
    • subject_mode: namespaced (the default) or resolve.
    • actor_issuers: the act.iss values to accept besides the ID-JAG's own iss. Nothing reads it at redemption yet; the actor checks use it next.
  • Startup refuses an unknown subject_mode, actor_issuers without resolve, resolve with subject_bindings, resolve on an issuer that accepts plain jwt_bearer assertions, and resolve without an OIDC first upstream. subject_bindings stays required for namespaced issuers. A resolve issuer skips the subject-binding check at redemption.
  • The unexported constant delegatedAccessEnabled (false) refuses every redemption from a resolve issuer with access_denied / subject_unknown. The refusal comes after the client-audience check and before the jti is consumed. The server logs one WARN at startup naming the affected issuers.

Closes #7244

Type of change

  • New feature

Test plan

  • Unit tests (task test): ran the same go test -race command the task uses, on pkg/authserver and pkg/authserver/server/tokenexchange, not the whole repo
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Changes

File Change
pkg/authserver/server/tokenexchange/subject_mode.go New: SubjectMode, the gate, the startup WARN and the per-issuer validation
pkg/authserver/server/tokenexchange/multi_issuer_validator.go The two fields, cloning, and the call into the new validation (bindings skipped for resolve)
pkg/authserver/server/tokenexchange/id_jag_handler.go Gate after the client-audience check, binding check skipped for resolve, WARN at construction
pkg/authserver/server/tokenexchange/jwt_bearer_handler.go Reuses refuseSubjectUnknown() for the binding refusal
pkg/authserver/inbound_grants.go Mirror fields and their copy through applyJWTBearerPolicies
pkg/authserver/config.go Refuse resolve without an OIDC first upstream, in RunConfig.Validate and Config.Validate
docs/arch/17-token-exchange-delegation.md Subject mode, the gate, the refusal table
*_test.go (4 files) Settings, refusals, copies, gate and its ordering

Does this introduce a user-facing change?

No for existing deployments. namespaced is the default and behaves exactly as before. Config files and the CRD can't set the new fields, so only Go embedders can. For an embedder that sets subject_mode: resolve:

  • Before: the field doesn't exist.
  • After: startup rejects invalid combinations with an error naming the issuer, and every redemption from that issuer returns 400 access_denied with subject_unknown. The ID-JAG is not consumed.

Special notes for reviewers

  • The gate is a constant, not a setting. No configuration can turn it on, because AS-2 can't see how the gateway behind it is wired, so no config check could prove the gateway enforces the delegated-access marker. The follow-up that adds resolution flips it.
  • Skipping the binding check for resolve issuers is safe only while the gate is closed. Nothing is issued from a resolve issuer in this build. The change that flips the gate must add resolution in the same change.
  • The OIDC-first-upstream check runs in two places on purpose. RunConfig.Validate runs before the runner registers with any upstream. A config that failed only later would leave an unused client registered at the provider on each restart with the default in-memory store. Config.Validate keeps the check for callers that build a Config directly.
  • A resolve issuer must list accepted_assertion_types as [id_jag] explicitly. Leaving it unset means both types, and only the ID-JAG handler has the gate.
  • actor_issuers is validated but not yet enforced. The docs say so.

AS-2 cannot be told that an issuer's ID-JAGs name a user in its own user
table: every redemption issues <iss>#<sub>, which is not a local user,
so the gateway cannot find that user's connections. This adds the
per-issuer setting that selects resolving the subject to a local user,
closed by a code gate until resolution itself lands.

Two Go-only (json:"-") settings on JWTBearerGrantPolicy, mirrored on
JWTBearerIssuerPolicyRunConfig and copied by applyJWTBearerPolicies so
embedders using inbound_grants reach them: subject_mode (namespaced, the
default, or resolve) and actor_issuers (act.iss values accepted besides
the ID-JAG's own iss). Config files and the CRD cannot set them.

Startup refuses an unknown subject_mode, actor_issuers without resolve,
resolve with subject_bindings, resolve on an issuer that accepts plain
jwt_bearer assertions, and resolve without an OIDC first upstream.
subject_bindings stays required for namespaced issuers only. A resolve
issuer skips the subject-binding check at redemption.

The unexported constant delegatedAccessEnabled (false) refuses every
redemption from a resolve issuer with access_denied / subject_unknown
after the client-audience check and before the jti is consumed, and the
server logs one WARN at startup naming the affected issuers. Namespaced
issuers are unchanged.

Refs #7244

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 23, 2026 19:57
@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Nov 23, 2026
rdimitrov
rdimitrov previously approved these changes Nov 23, 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.

Approve: the config surface and the closed gate are in the right places, and nothing changes for existing deployments.

Design: Per-issuer policy lives in JWTBearerGrantPolicy and its validation, and redemption lives in IDJAGHandler, so putting SubjectMode and ActorIssuers there is the right owner. The gate refuses resolve before the jti is consumed. It also checks policy.SubjectMode directly, so it holds even if an embedder skips config validation, and the plain jwt_bearer handler can't reach a resolve issuer because validation forces the accepted type to id_jag. The new fields are Go-only (json:"-") and default to namespaced, so no CRD, RunConfig or API shape changes on upgrade. The first-upstream check runs from both RunConfig.Validate and Config.Validate, before upstream registration.

Non-blocking: for resolve issuers, checkIDJAGPolicy skips the whole binding check, including the per-resource one, and the subject is still built as <iss>#<sub>. The delegatedAccessEnabled constant is the only thing preventing issuance in that state. The follow-up that flips it must add resolution and the resource check in the same change. A comment at the early return saying so would help. The title says "behind a setting", but the gate is a constant.

🤖 Reviewed with Claude Code

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.79%. Comparing base (4475f45) to head (359135c).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...kg/authserver/server/tokenexchange/subject_mode.go 93.54% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7254      +/-   ##
==========================================
+ Coverage   81.66%   81.79%   +0.13%     
==========================================
  Files         904      913       +9     
  Lines       91840    92576     +736     
==========================================
+ Hits        74999    75727     +728     
- Misses      16836    16844       +8     
  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.

The OIDC-first-upstream check added to RunConfig.Validate took its
cyclomatic complexity to 16, over the linter's limit of 15. Move the
check into a small method.

Also say at the binding-check skip for resolve issuers that the change
which opens the gate must add resolution and a per-resource check, as
the review asked.

Co-authored-by: Mecatl <[email protected]>
@github-actions github-actions Bot added size/L Large PR: 600-999 lines changed and removed size/L Large PR: 600-999 lines changed labels Nov 23, 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 359135c: still approve.

The new commit only moves the resolve-issuer upstream check out of RunConfig.Validate into a validateResolveIssuers helper to lower its complexity, and adds the comment at the SubjectModeResolve early return in checkIDJAGPolicy. The call keeps its position (after validateTrustedIssuers, before validateSPIFFEClientIDsNotDelegates), takes the same arguments and returns the error unwrapped, so behaviour is unchanged. The comment accurately records that resolve skips the binding check and that delegatedAccessEnabled = false is the only thing blocking issuance, so whoever opens the gate must add resolution and the per-resource check in the same change.

The one failing CI check is Test Go Code on TestDCRRecheckTick_KeepsCurrentClientOnFailure (pkg/authserver/runner/dcr_recheck_test.go), which this PR doesn't touch; it looks like a timing flake. #7172 addresses that test.

🤖 Reviewed with Claude Code

@jhrozek
jhrozek merged commit a77ba4c into main Nov 23, 2026
57 of 58 checks passed
@jhrozek
jhrozek deleted the as2-subject-mapping-1-config branch November 23, 2026 21:16
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Delegated access: subject mapping setting and code gate for ID-JAG issuers

2 participants