Repository navigation
Fix Cedar deny-all when upstream JWT lacks identity claims - #6022
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cedar authorization denied every request, for every user, on any workload whose
embedded auth server sits in front of an upstream IdP that issues JWT-shaped
access tokens without the identity claims policies reference — most commonly
email, which many OIDC providers assert only in theid_token.The chain: when the embedded auth server is active,
injectUpstreamProviderIfNeededforce-injects the first upstream as Cedar's
PrimaryUpstreamProvider(no opt-out),so
resolveClaimsread the principal's claims from the upstream access tokenonly. The opaque-token fallback added in #5147 is gated on
!looksLikeJWT, so awell-formed upstream JWT that simply lacks
emailnever fell back.principal has claim_emailwas false for everyone, so aforbid ... unlessdomaingate applied cleanly — no Cedar diagnostic, no warning logged,
tools/listemptyand
tools/call403. Audit logging reads the AS-issued token, so it kept reportingthe correct user and pointed investigations away from authorization. Upstreams with
opaque access tokens (Google, GitHub) hit the #5147 fallback and worked, which made
the breakage look provider-specific.
The provider does assert the claim — in its
id_token, which the auth serveralready stores alongside that provider's access token.
resolveClaimsnow supplements from the same provider'sid_token:nameand
emailfall back to it when the access token omits them. Access-token valuesalways win. Provenance is preserved, so
principal has claim_emailkeeps meaning"this upstream asserted an email".
multi-upstream chain its mirrored
name/emailbelong to the first configuredupstream, which need not be the pinned provider — see "Special notes".
subis never supplemented: it becomes the Cedar principal entity ID, whereCedar has no
has-style guard, so a missing access-tokensubfails closed withErrMissingPrincipalinstead of having a principal chosen for it.has-guarded policies still fail closed on claimsneither token carries — with two rate-limited WARNs distinguishing "access token
lacked profile claims, used the id_token" from "no id_token stored, will deny",
so the condition is diagnosable from logs alone (requested in the issue's comment).
One fix covers the CLI runner, operator and vMCP paths, since all three funnel
through
resolveClaims. The HTTP authorizer readsidentity.Claimsdirectly andhas no equivalent bug.
Fixes #5916
Type of change
Test plan
task test)task test-e2e)task lint-fix)Tests added:
TestSupplementProfileClaims— precedence, and the never-filled sets: theid_token's registered claims (
aud/exp/nonce/at_hash/azp),authorization-bearing claims, and
sub. Plus the no-mutation/no-alias contract.TestResolveClaimsUpstreamSupplement— the claim-source contract end to end,including that the ToolHive-issued token's mirrored email never leaks in (the
fixture uses a
leaked-from-as-token@…sentinel), that an expired id_tokenis still used, and that an unparsable one degrades to no-supplement rather than
failing the request.
TestAuthorizeWithJWTClaims_UpstreamJWTMissingIdentityClaim— the reporter'sexact policy pair against a JWT access token with no
email.TestAuthorizeWithJWTClaims_PrincipalStaysUpstreamSourced— aforbidkeyed onan upstream subject keeps matching, and a missing access-token
subfails closedeven though the id_token carries one.
TestIntegrationUpstreamJWTWithoutEmailClaim— the reported scenario through thefull authorization middleware, plus regression guards for the Fall back to request-token claims for opaque upstream tokens #5147 opaque-token
fallback and the tampered-JWT hard deny.
Both guarantees were verified by negative control, not just asserted: swapping the
supplement source back to the issued token fails 5 cases across the two packages
(including the integration reproducer), and adding
subback to the allowlistfails the principal guard.
task testis otherwise green — the three failures in my run (pkg/api×2,pkg/secrets/keyring×1) are pre-existing environment limitations in my sandbox(no container runtime, no keyring), confirmed by stashing the change and re-running.
Also clean over repeated
-raceruns (see thecaptureSlogWarnnote below).Changes
pkg/authz/authorizers/cedar/core.goresolveClaimssupplements profile claims from the provider's id_token via newsupplementFromIDToken/supplementProfileClaims+profileClaimsFromIDToken; two dedicated rate limiters for the new diagnosticspkg/authz/authorizers/cedar/core_test.gocaptureSlogWarnconcurrency-safepkg/authz/integration_test.godocs/operator/virtualmcpserver-kubernetes-guide.mdDoes this introduce a user-facing change?
Yes. Cedar policies referencing
emailornamenow work when the upstream IdPasserts them in its
id_tokenrather than its access token, instead of denyingevery request. Policies that already worked are unaffected: any claim the access
token asserts still wins, and group/role/scope claims plus the principal's
subare never substituted.
principal has claim_emailcontinues to mean "the pinnedupstream asserted an email".
Special notes for reviewers
Why the supplement source is the id_token and not the ToolHive-issued token.
The first version of this PR supplemented from the issued token, on the premise
that its mirrored values are copies of the upstream's. Research for @jhrozek's
review found that premise fails in a configuration we document:
validateChain(handler.go:346-353) requires an upstream chain to be "anon-empty, in-order, duplicate-free subsequence of the configured upstreams led
by the required first upstream".
userEmail = result.Email,callback.go:132-133); later legs carry those values forward
(
userEmail = pending.ResolvedUserEmail, callback.go:137). So the issued token'sname/emailalways belong to the first configured upstream.primaryUpstreamProvidermay name any upstream — the converter validatesmembership, not position, and the vMCP guide documents pinning explicitly.
With
[okta, github]andprimaryUpstreamProvider: github, the old versionsupplemented okta's email into a claim set the policy believes is github's, silently.
verifyChainIdentitykeeps it the same person, but a gate distinguishing acorporate from a personal IdP is exactly what gets subverted.
UpstreamIDTokensiskeyed by provider name and projected from the same credential bundle
(token.go:1265-1279), so provenance holds by construction.
No coverage lost, and no third tier. An OIDC upstream cannot log in without an
id_token (
upstream/oidc.go:313rejects it;openidis force-added at oidc.go:229),and name/email are extracted from that id_token into the issued token
(oidc.go:330) — so the reporter's provider supplies the identical value with better
attribution. It also can't vanish mid-session: a refresh omitting a rotated id_token
carries the original forward (service.go:181-183). Only an OAuth 2.0 upstream never
asked for
openidhas none, and there the claim genuinely isn't available from thatprovider, so absent-and-deny is honest — with a dedicated WARN. Dropping the issued
token entirely makes this less code than the version first reviewed.
expis deliberately not enforced on the id_token. It's read as a record ofwhat the upstream asserted at login, not presented as a credential. The "callers
MUST check exp" contract exists for RFC 8693 subject-token use, and the owning
service says so: "Enforcement belongs at the RFC 8693 token-exchange consumer"
(upstreamtoken/service.go:134);
xaa.go, the only current consumer, doesn't checkit either. Enforcing it here would be harmful —
RefreshTokenLifespandefaults to7 days (config.go:999) while id_tokens expire in minutes, so a policy would permit
early in a session and silently deny later. Pinned by
expired_id_token_is_still_used.Unrelated latent race fixed here out of necessity.
captureSlogWarninstalls acapturing handler through the process-global
slog.SetDefaultover a plainbytes.Buffer, so any parallel test can race the read — keeping the capturing testnon-parallel never prevented that. Adding a second
slog.Warnon a hot path made itreproducible under
-race(it does not reproduce on main). The buffer is nowmutex-guarded, and
TestStaleTHVGroupWarningkeys on its specific message ratherthan on the buffer being empty, since foreign records can legitimately land there.
Known inconsistency left for a follow-up, deliberately. The #5147 opaque-token
branch still falls back to the issued token's claims, so it retains the provenance
flaw fixed here — and its principal is ToolHive's internal user ID rather than the
upstream subject, so a rule keyed on
Client::"okta|alice"works with JWT accesstokens and silently doesn't with opaque ones. Unifying that branch on the id_token
would fix both but changes behaviour on a shipped path (Google/GitHub deployments),
so it wants its own PR; the current behaviour is pinned with a comment in
opaque_upstream_token_still_falls_back. Likewise: takinggroups/rolesfrom theid_token is provenance-legitimate now that the source is the same provider, but it
would newly grant requests that deny today.
Also out of scope: honoring
primaryUpstreamProvideronMCPServer/MCPRemoteProxywith an explicit opt-out (parity with #5199 forVirtualMCPServer), and the missing-upstream-token hard deny the issue flagsparenthetically, left fail-closed.
Generated with Claude Code