Repository navigation
Resolve ID-JAG subjects and issue marked tokens behind the gate - #7262
Conversation
A resolve issuer's ID-JAG carries an upstream_subject that has to become a local user before the marked token can be issued. Nothing did that mapping yet, and a mutable subject claim on the sign-in upstream would have let a user rename themselves into another user. Build a subject resolver from the first (sign-in) upstream and pass it to IDJAGIssuanceFactory, which refuses a resolve issuer without one. The handler resolves upstream_subject after the gate and before anything is consumed. The resolver alone decides which issuers and claims resolve and reports any other with the new subject.ErrNotConfigured, which the handler refuses as a foreign upstream_subject; a missing, unknown or unavailable subject gets the other documented errors. Keeping that decision in the resolver means a second issuer added to it later is not refused by a copy in the handler. Config validation now also refuses a resolve issuer whose first upstream uses a mutable subject claim, and the Okta sub warning is logged once at startup. The actor check is split in two. The issuer check stays before the gate; the actor policy now runs after resolution with the resolved local user, so a policy backed by a directory sees a user ID of this server rather than AS-1's subject. Both still refuse before the jti is used up. The gate still refuses every resolve redemption over HTTP, so none of this is reachable yet. To keep buildProvider under the complexity limit, the factory wiring moves into buildJWTBearerFactoriesForConfig. The parameter of the exported ValidateRuntimeSPIFFEBundleSourceType is renamed from subject to fieldPath, because the new subject package import in config.go shadowed it; its type and behaviour do not change. Refs #7246 Co-authored-by: Mecatl <[email protected]>
A resolved ID-JAG redemption has to produce a token the gateway can use to read the user's connections, and that token must not outlive a short window, since the marker lets its holder act as the user. Mark the redemption of a resolve issuer's resolved subject as delegated access. The session builder stamps the delegated-access marker on that token, and the lifetime step caps it at five minutes, applied after every other bound so none can lengthen it. Namespaced redemptions are unchanged. The gate still refuses every resolve redemption over HTTP, so no marked token is issued yet. The marked token's own iss is this server, so an act claim without an iss would be read as acted under this server's issuer. The token gets a copy of act with iss set to the ID-JAG issuer, the issuer the actor check used. An explicit iss, nested actors and the assertion's claims are left as they are. Refs #7246 Co-authored-by: Mecatl <[email protected]>
A DCR- or CIMD-registered client that is not resource-scoped is not narrowed by the client grant or client audience checks, so a marked token for it would be bounded only by the resource AS-1 names. Refuse those redemptions so every marked token has a resource bound on this server's side. Starting strict; loosening later does not break clients. Resolution now begins with a client check that refuses such a client with access_denied and the client_not_permitted reason, before the resolver is called or anything is consumed. The predicate moves into server.IsUnscopedDCRClient, which ValidateIDJAGClientAudience also uses so the two cannot drift. For the same reason a resolve redemption requires the ID-JAG's signed resource claim and takes the resource only from it. Without the claim the redemption is refused with invalid_assertion before the jti is used up; draft -06 section 4.4.1 lets the resource server require it. Namespaced redemptions keep the request-parameter fallback. Both checks are behind the closed gate and not reachable over HTTP. Refs #7246 Co-authored-by: Mecatl <[email protected]>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #7262 +/- ##
==========================================
+ Coverage 81.81% 81.87% +0.06%
==========================================
Files 914 915 +1
Lines 92619 92727 +108
==========================================
+ Hits 75773 75923 +150
+ Misses 16841 16799 -42
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.
Approve: the change sits at the right owners and nothing in it is reachable in production until the gate opens.
Design: Resolution lives in the ID-JAG handler plus subjectresolver, which owns the identity lookup against the sign-in upstream's provider-identity rows. It runs after the gate and before the assertion is consumed, so a refused redemption never burns the jti. The delegated-access marker and lifetime cap are applied last, and act.iss is filled on a copy so the assertion's own claims stay untouched. The only production caller of IDJAGIssuanceFactory is buildJWTBearerFactories, so the resolver wiring covers every path. Both config types route through the same resolve-issuer validation. On upgrade there is no HTTP-visible change while delegatedAccessEnabled is false. Go embedders get a new required resolver argument and ErrNotConfigured instead of ErrUnknown, and the PR body says so. Startup validation now rejects resolve issuers with a mutable subject_claim; this is safe because every resolve redemption is already refused by the gate.
Handler-level tests with the gate open are deferred to #7247, which is where they belong.
🤖 Reviewed with Claude Code
Summary
When the gateway's authorization server redeems an ID-JAG, it can't say which of its own users the assertion is for. The token's
subis always<ID-JAG iss>#<sub>, so the gateway can't find the user's stored connections and no token can name a real user. This change makes redemption map the ID-JAG'supstream_subjectto a local user and, when everything checks out, issue the delegated-access marker that lets the gateway read that user's connections.All of it sits behind the existing closed gate (
delegatedAccessEnabledis stillfalse), so nothing here is reachable over HTTP. Turning it on is "Delegated access: turn on subject resolution at ID-JAG redemption" (#7247).upstream_subjectto a local user through the sign-in upstream, after the gate and before the ID-JAG is consumed. The resolver decides which issuers and claims it accepts and reports any other with a newsubject.ErrNotConfigured, which the handler refuses as a foreignupstream_subject.act.isswith the ID-JAG's issuer when the assertion left it out, because the token's ownissis this server.resolveredemption from a DCR client that isn't resource-scoped, and require the ID-JAG's signedresourceclaim.resolveissuer whose first upstream uses a mutablesubject_claimsuch asemail.Closes #7246
Type of change
Test plan
task test)task test-e2e)task lint-fix)The gate is closed, so resolution is tested by calling
idJAGRedemptionandredeemer.completedirectly, with a mocked resolver. That covers each refusal (the resolver is not called, the ID-JAG stays unused, one Debug line with the reason), the actor policy receiving the resolved user, the lifetime cap, and a resolver with two providers resolving both through the handler. The only test throughHandleTokenEndpointRequestis the closed-gate one. Handler tests with the gate open belong with #7247.Changes
pkg/authserver/server/tokenexchange/id_jag_resolve.gopkg/authserver/server/tokenexchange/id_jag_handler.gosubject.Resolverpkg/authserver/server/tokenexchange/id_jag_actor.gocheckActorsplit intocheckActorIssuerandcheckActorPolicypkg/authserver/server/tokenexchange/redeemer.goact.issfillpkg/authserver/server/tokenexchange/subject_mode.goHasResolveIssuerpkg/authserver/server/audience.goIsUnscopedDCRClient, shared withValidateIDJAGClientAudiencepkg/authserver/subject/subject.go,pkg/authserver/subjectresolver/resolver.goErrNotConfigured; the resolver returns it for an issuer or claim it doesn't resolvepkg/authserver/server_impl.go,pkg/authserver/config.go,pkg/authserver/upstream/oidc.gosubject_claim; one default-claim constantdocs/arch/17-token-exchange-delegation.mdDoes this introduce a user-facing change?
Not over HTTP. While the gate is closed, every redemption from a
resolveissuer is still refused withaccess_deniedandsubject_unknown.subject_modecan only be set from Go by embedders, not from config files or the CRD.What an embedder sees:
IDJAGIssuanceFactorytakes a new requiredsubject.Resolverargument. Before, it took no resolver. Its only caller in this repository isbuildJWTBearerFactories.subjectresolver.Resolvereturns the newsubject.ErrNotConfiguredfor an issuer or claim it doesn't resolve. Before, it returnedErrUnknown. This change is its only caller.subject_mode: resolveis now refused at startup when the first upstream'ssubject_claimis a known mutable claim, or when a run config's first OIDC upstream has nooidc_config. Before, only a missing OIDC first upstream was refused. An Okta custom authorization server withsublogs one warning at startup.Implementation plan
Approved implementation plan
Three commits, in this order:
subject_claim.act.issfilled when absent.resourceclaim forresolveredemptions.Settled while reviewing: the resolver, not the handler, decides which issuer and claim are accepted; the factory takes the resolver as a required argument rather than an option; full-handler tests with the gate open wait for #7247.
Special notes for reviewers
The three commits can be read one at a time. This is a bit over the usual size (11 non-test files, about 470 changed lines) because the handler, the wiring and the config check have to land together to be tested.
Where this differs from the namespaced path, on purpose:
resolveredemption requires the ID-JAG's signedresourceclaim and takes the resource only from it. The namespaced path uses the claim when present and otherwise the request'sresourceparameter. The ID-JAG draft (-06, section 4.4.1) lets the resource server require the claim and refuse withinvalid_grant. A marked token lets its holder act as the user, so the resource should be a decision the issuer signed, not one the client picks. A ToolHive AS-1 always stampsresource.resolve(access_denied,client_not_permitted).ValidateIDJAGClientAudiencelets such a client through for namespaced redemptions. Nothing else narrows the resource of a marked token on this server's side for it. Starting strict doesn't break clients if it's loosened later.This also answers the question about what bounds a marked token's resource, raised on "Gate ID-JAG subject resolution behind a setting" (#7254). For a
resolveissuer there are no subject bindings, so the resource is bounded by the requiredresourceclaim (which must be a resource this server governs) and by the client's audiences or resource allowlist. Unscoped DCR clients are refused, so every marked token has a bound on this server's side.Known limits:
subject_unknown, the same answer the closed gate gives.subject.ValidateBindingClaim, which is not exhaustive.