Skip to content

Source Cedar claims from the upstream ID token for opaque access tokens - #6052

Open
JAORMX wants to merge 2 commits into
mainfrom
fix-cedar-opaque-claim-source-6048
Open

JAORMX wants to merge 2 commits into
mainfrom
fix-cedar-opaque-claim-source-6048

Conversation

@JAORMX

@JAORMX JAORMX commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Cedar resolved policy claims along two different paths depending on whether the
pinned upstream's access token happened to be JWT-shaped, and the two disagreed
about both the claim source and the principal. The JWT branch (fixed in #6022/#6036)
reads that provider's access token plus its id_token; the opaque branch — the
!looksLikeJWT fallback from #5147 — read the ToolHive-issued token instead.

Two silent consequences, both fixed here:

  • The principal was not the upstream subject. On the opaque path the AS-issued
    sub is ToolHive's internal user ID (a UserResolver UUID), so
    forbid(principal == Client::"okta|alice", ...) matched with a JWT-issuing upstream
    and silently did not with an opaque-token one. Cedar has no has-style guard in
    the principal position, so there was no diagnostic.
  • Profile claims were misattributed in multi-upstream chains. The claims the auth
    server mirrors into its own token always come from the first configured upstream
    (validateChain pins chain[0] to upstreams[0]; only the first leg resolves
    identity), which need not be the provider primaryUpstreamProvider names.

The opaque branch now reads the pinned provider's id_token
(identity.UpstreamIDTokens[provider]), admitting sub plus the same
profileClaimsFromIDToken allowlist the JWT branch uses — so both paths carry that
provider's provenance and the principal is the upstream subject either way.

Fixes #6048

Type of change

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

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • E2E tests (task test-e2e)

New: TestResolveClaimsOpaqueUpstreamToken (id_token supplies principal + profile;
claims outside the allowlist not admitted; expired id_token still used; id_token
without sub leaves the principal absent; no id_token and unparsable id_token both
fall back) and TestAuthorizeWithJWTClaims_OpaqueUpstreamTokenPrincipal (end to end:
a banned upstream subject is forbidden, i.e. the principal really is the upstream
subject; an id_token without email denies rather than using the AS-issued value).
Plus toolhive_groups_ignored_when_upstream_token_is_opaque, extending the existing
issued-token invariant to the newly-changed branch.

All pinned security tests pass unchanged: authorization_bearing_claims_are_not_filled,
toolhive_groups_ignored_when_upstream_configured,
direct_groups_ignored_when_upstream_configured,
TestAuthorizeWithJWTClaims_PrincipalStaysUpstreamSourced,
tampered_upstream_jwt_still_denies.

task lint-fix 0 issues; codespell clean; go test -race ./pkg/authz/... ./pkg/auth/...
clean; task test shows only three failures that are pre-existing sandbox limitations
(pkg/api TestNewServer_ReadTimeoutConfigured and TestSecurityHeaders — no
container runtime; pkg/secrets/keyring TestCompositeProvider_RealProviders — no
keyring).

Does this introduce a user-facing change?

Yes, and it is a behaviour change on a shipped path — please read the three points
below before merging.

1. The Cedar principal changes on opaque-token deployments. It becomes
Client::"<upstream-subject>" instead of Client::"<ToolHive internal UUID>". Any
policy keyed on the UUID form stops matching. That is unlikely to be deliberate —
nobody sensibly writes a policy against a random UUID — but it is a real migration
consideration.

2. This does NOT fix every opaque-token upstream, and a release note saying
"Google and GitHub are fixed" would be half wrong.
The fix needs a stored
id_token:

  • Google (OIDC, opaque ya29.* access token, has an id_token) — fixed.
  • GitHub as type: oauth2 (opaque gho_*, never an id_token) — keeps the old
    behaviour permanently. Identity carries no record of an OAuth-2.0-only provider's
    upstream subject at all: Subject/PlatformUserID are the internal user ID,
    Name/Email are the first upstream's mirror, Groups is never populated by
    middleware, and UpstreamIDTokens has no entry. The subject exists in storage as
    UpstreamSubject but is consumed only inside the auth server and never projected
    onto Identity. Making that case work needs that projection, which is a wider
    change to pkg/auth and is filed separately.

So the no-id_token case is not an edge case — it is the GitHub-OAuth-app
configuration in our own operator guide's multi-upstream example. It therefore keeps
the identity.Claims fallback rather than failing closed: failing closed would deny
every request on those deployments with no configuration an operator could change to
recover, recreating exactly the #5916 deny-all trap #6022 removed. A rate-limited
WARN names the provider and the consequence, and the documented remedy is to request
the openid scope for that upstream.

3. claim_client_id, claim_iss, claim_aud and claim_exp are no longer
visible to policies on the opaque path.
The old path handed Cedar the whole
AS-issued claim set — client_id from session.New, plus fosite's iss/aud/exp/
iat/jti. A rule referencing claim_client_id silently stops matching. This
removes an asymmetry rather than creating one: the JWT branch never surfaced the
AS-issued client_id either. Worth knowing it was arguably a trap before — an
RFC 9068 upstream access token can carry its own client_id, which is the auth
server's client registration at the upstream, not the calling MCP client, so on the
JWT branch a claim_client_id == "vscode" rule could find a different value under
the same name
. The opaque path was the only place that claim meant what a policy
author would assume. It fails toward deny (principal has claim_client_id becomes
false), and the guide's upgrade note points at gating on the upstream subject or a
claim the upstream asserts instead.

Special notes for reviewers

Why sub is taken from the id_token here when #6036 forbids supplementing it.
#6036's rule is that sub must never be supplemented — it becomes the Cedar
principal entity ID, and Cedar offers no has-guard there, so a missing access-token
sub must fail closed. On this branch there is no access-token sub to override:
the claim set is replaced, not supplemented, and the source is the pinned
provider's own id_token, which is the correct provenance and the whole point of the
issue. An id_token that omits sub leaves the key absent, so
AuthorizeWithJWTClaims still fails closed with ErrMissingPrincipal — pinned by a
test.

Why only sub + profileClaimsFromIDToken, not the whole id_token body. Keeping
the same allowlist on both branches means #6049 (group claims from the id_token)
widens them together as one deliberate release decision, and nothing this PR does
grants access that #6049 is meant to decide. Taking the whole body would newly admit
groups/scope on the opaque path only — an inconsistency in the opposite direction
from the one this PR removes.

Interaction with #6049. That branch also touches resolveClaims, but only its
doc comment; the !looksLikeJWT branch body is untouched there, so whichever lands
second needs a comment-block rebase only.

Generated with Claude Code

@codecov

codecov Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.27%. Comparing base (33023da) to head (8a1e5a1).
⚠️ Report is 616 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6052      +/-   ##
==========================================
+ Coverage   72.26%   72.27%   +0.01%     
==========================================
  Files         722      724       +2     
  Lines       75138    75367     +229     
==========================================
+ Hits        54296    54474     +178     
- Misses      16980    17010      +30     
- Partials     3862     3883      +21     

☔ 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.

JAORMX and others added 2 commits July 28, 2026 10:14
With the embedded auth server active, Cedar resolved claims from two
sources depending on an accident of the pinned upstream's access token
format. A JWT access token gave claims from that upstream, so the Cedar
principal was the upstream subject. An opaque one (Google's ya29.*,
GitHub's gho_*) hit the #5147 fallback and gave the claims of the token
ToolHive itself issued, so the principal became ToolHive's internal user
UUID and `forbid(principal == Client::"okta|alice", ...)` silently stopped
matching. In a multi-upstream chain the same fallback attributed the FIRST
configured upstream's profile to the pinned provider, since that is whose
name/email the auth server mirrors.

Read the pinned provider's own id_token on that branch instead. It supplies
the principal `sub` plus the profileClaimsFromIDToken allowlist that already
governs the JWT path, so both paths now admit the same claim names from the
same provider and session, and widening the allowlist widens them together.
Claims outside it stay out: an id_token's iss/aud/nonce describe the token
rather than the user, and admitting more here than on the JWT path would
recreate the inconsistency being removed.

`sub` is not being supplemented in the sense the JWT path forbids: an opaque
token asserts nothing, so there is no access-token `sub` to override, and an
id_token that omits `sub` still fails closed with ErrMissingPrincipal rather
than borrowing the auth server's subject. `exp` is not enforced, as for the
existing supplement — the token records what the upstream asserted at login,
and rejecting it once expired would flip a policy from permit to deny
mid-session.

A pure OAuth 2.0 upstream never asked for the `openid` scope has no id_token
at all (GitHub OAuth apps are the common case) and no other record of that
provider's subject exists in the identity. For that configuration alone the
ToolHive-issued token's claims are still used, which is what shipped before:
failing closed would deny every request on those deployments with nothing an
operator could configure to recover, so the weaker attribution is the lesser
harm. A rate-limited WARN names the provider and the consequence.

Fixes #6048

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y5WXPQr5Da9Cox2nZWhg6n
Narrowing the opaque branch to the pinned provider's id_token also drops the
claims only the ToolHive-issued token carried: `client_id` (session.New) plus
fosite's `iss`/`aud`/`exp`/`iat`/`jti`. A policy gating tool access on
`claim_client_id` therefore stops matching, which an operator needs told
rather than left to discover.

This removes an asymmetry rather than creating one: the JWT branch never
exposed those claims either, since this auth server's client_id appears in
neither the upstream access token nor its id_token, and a `client_id` an
upstream access token does assert is the auth server's own registration at
that upstream rather than the calling MCP client. It also fails toward deny,
as `principal has claim_client_id` becomes false.

State it in the resolveClaims contract and in the operator guide's upgrade
note, and pin it with a case asserting `client_id` reaches Cedar from neither
token. The unit test's ToolHive-issued claim set now matches what
claimsToIdentity actually produces — `client_id` present, `tsid` filtered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y5WXPQr5Da9Cox2nZWhg6n
@JAORMX
JAORMX force-pushed the fix-cedar-opaque-claim-source-6048 branch from 4a99b16 to 8a1e5a1 Compare July 28, 2026 07:14
@github-actions github-actions Bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jul 28, 2026
tgrunnagle added a commit that referenced this pull request Nov 24, 2026
The note said skipping the id_token was deliberate, but #6052 proposes
reading it on this branch. State the current behavior and where the
change is tracked instead.

Addresses #6054 review comments:
- INFO pkg/authz/authorizers/cedar/core.go:797 (4682119205): opaque-path deviation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tgrunnagle added a commit that referenced this pull request Nov 25, 2026
…6054)

* Let Cedar see group claims from the upstream id_token

Cedar read group and role claims from the pinned upstream's access token
only, so a provider that asserts group membership in its id_token — common
where groups are a profile-scope claim — produced an empty group set and
every `principal in THVGroup::"..."` policy denied for every user.

because widening the supplement newly grants requests that deny. This is
that change. Provenance is what makes it safe: since #6036 the supplement
source is the same provider's id_token, so a group read from it is asserted
by the same IdP that issued the access token.

The supplement is inverted from an allow-list of {name, email} to a
deny-list of claims that describe the id_token rather than the user
(registered/OIDC token claims) plus `sub`, which is the Cedar principal.
An allow-list cannot work here: the group claim's name is chosen by the
deployment via GroupClaimName/RoleClaimName or by the IdP as a URI-style
name, so any fixed list denies silently for names ToolHive does not choose
— the defect shape of #5916 and #6049 both. Inverting also settles `hd`
and custom namespaced claims in the same pass.

Precedence is unchanged and stays fill-only rather than union: an access
token asserting a partial group list keeps exactly that list, because
per-audience claim filtering means that list is the provider's answer for
this resource server.

The ToolHive-issued token is still never a claim source, so a group on it
still grants nothing.

Fixes #6049

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y5WXPQr5Da9Cox2nZWhg6n

* Keep scope out of the id_token supplement

Group and role claims are facts about the user, so either of the pinned
provider's tokens may report them. `scope`/`scp` are not: they assert the
authority a particular token carries, and the only authority at issue is
the presented access token's. Where a provider emits `scope` in an id_token
at all — non-standard — it may echo what the client requested rather than
what the user granted, and granular consent makes those differ routinely,
so supplementing it could satisfy a scope gate on authority the access
token does not carry.

Excluding them by name is effective rather than cosmetic, because unlike a
group claim name these are standardised (RFC 8693/9068 `scope`, Entra
`scp`). The argument that retired the allow-list for groups does not
transfer.

Also records the shortest form of the deny-list argument: the access-token
branch already admits every claim with no allow-list, so an allow-list on
the id_token alone was an asymmetry between two tokens at the same trust
level, and inverting it restores parity rather than widening a boundary.

Promotes the group-revocation window to a callout in the operator guide.
Groups sourced from an id_token are login-time facts, so revocation may not
propagate until the session ends (7d default) rather than within an
access-token lifetime.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y5WXPQr5Da9Cox2nZWhg6n

* Keep default group selection on the access token

The id_token supplement fills claims one at a time, but default group
extraction takes the first of groups/roles/cognito:groups. An access
token asserting roles paired with an id_token asserting groups let the
id_token's list win and hid the access token's roles. Once the access
token asserts any default group claim, the other default names are no
longer filled; a name configured as GroupClaimName or RoleClaimName
still is.

Addresses #6054 review comments:
- HIGH pkg/authz/authorizers/cedar/core.go:941 (4682119027): id_token groups displace access-token roles in default extraction

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Tighten the id_token supplement and its tests

Filling from the id_token is now the designed path, so its log line
drops to DEBUG instead of warning on ordinary traffic. The deny-list
gains the token-type, token-binding and delegation claims its own
categories already describe. The pure merge is renamed so it no longer
differs from its caller by one word, the opaque-token fallback gets a
test proving it ignores the id_token, and a duplicate scp case goes.

Addresses #6054 review comments:
- LOW pkg/authz/authorizers/cedar/core.go:843 (4682119152): supplement WARN fires on the normal path
- LOW pkg/authz/authorizers/cedar/core.go:910 (4682119137): deny-list omits token-describing claims
- LOW pkg/authz/authorizers/cedar/core.go:925 (4682119125): near-identical function names
- LOW pkg/authz/authorizers/cedar/core_test.go:2874 (4682119064): no opaque-path id_token guard
- LOW pkg/authz/authorizers/cedar/core_test.go:2270 (4682119167): test comment contradicts its case
- LOW pkg/authz/authorizers/cedar/core_test.go:2279 (4682119177): duplicate scp case

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Document the id_token supplement and its limits

docs/authz.md still described a profile-claim supplement; it now has a
section on what the id_token can fill, what it never fills, and the
limits of fill-only: default group selection, empty per-audience
filters, and login-time group freshness. The operator guide and code
comments drop the claim that fill-only can never widen what the access
token asserts, describe the change per deployment shape instead of
calling it no regression, and state the contract in present tense
without retelling the allow-list history. The opaque-token branch now
says why it skips the id_token.

Addresses #6054 review comments:
- MEDIUM docs/authz.md:671 (review body): stale profile-claim row
- MEDIUM pkg/authz/authorizers/cedar/core.go:712 (4682119042): empty audience filter widening
- LOW pkg/authz/authorizers/cedar/core.go:915 (4682119053): repeated rationale
- LOW docs/operator/virtualmcpserver-kubernetes-guide.md:735 (4682119083): "not a regression" overstated
- LOW pkg/authz/authorizers/cedar/core.go:668 (4682119097): history-narrating doc comment
- LOW pkg/authz/authorizers/cedar/core.go:724 (4682119114): change-relative wording
- INFO docs/operator/virtualmcpserver-kubernetes-guide.md:707 (4682119193): emoji heading
- INFO pkg/authz/authorizers/cedar/core.go:797 (4682119205): opaque-path deviation

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Point the opaque-branch note at #6048

The note said skipping the id_token was deliberate, but #6052 proposes
reading it on this branch. State the current behavior and where the
change is tracked instead.

Addresses #6054 review comments:
- INFO pkg/authz/authorizers/cedar/core.go:797 (4682119205): opaque-path deviation

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Withhold default-named role claims from the id_token

RoleClaimName is read in addition to the default group loop, not
instead of it, so exempting a default-named role claim from the
withhold let the id_token's value win that loop and hide the access
token's roles. Only GroupClaimName is exempt now. The withhold also
triggers on the check extraction applies, so a null or scalar default
claim in the access token, which extraction skips, no longer withholds
the others.

Addresses #6054 review comments:
- MEDIUM pkg/authz/authorizers/cedar/core.go:877 (4682669168): default-named RoleClaimName displaces access-token roles
- LOW pkg/authz/authorizers/cedar/core.go:871 (4682669196): withhold trigger does not match extraction
- LOW pkg/authz/authorizers/cedar/core_test.go:2931 (4682669239): no RoleClaimName or custom GroupClaimName coverage

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Name the app-role limit and tidy supplement docs

Entra scopes roles to the token's audience app, so an id_token's roles
are the auth-server client's, not the resource API's; filling them can
grant roles the user holds only on the client. resolveClaims, the
authz page and the operator guide now say so with the remedies. The
rest is wording: present tense in the guide with a Migration callout
for forbid rules, CRD spellings in authz.md, the role-claim exemption
change, and re-wrapped comments.

Addresses #6054 review comments:
- MEDIUM pkg/authz/authorizers/cedar/core.go:704 (4682669184): Entra roles are per app registration
- LOW pkg/authz/authorizers/cedar/core.go:959 (4682669212): stale safe-direction pointer
- LOW pkg/authz/authorizers/cedar/core.go:904 (4682669226): 'These' reads as delegation claims
- LOW pkg/authz/authorizers/cedar/core_test.go:2006 (4682669253): change-relative wording
- LOW pkg/authz/authorizers/cedar/core_test.go:1717 (4682669266): ragged test comments
- LOW docs/operator/virtualmcpserver-kubernetes-guide.md:759 (4682669283): release-relative list
- LOW docs/operator/virtualmcpserver-kubernetes-guide.md:748 (4682669297): repeated sentence
- INFO docs/authz.md:707 (4682669306): CRD claim-name spellings
- INFO docs/operator/virtualmcpserver-kubernetes-guide.md:682 (4682669319): overlong line
- INFO pkg/authz/authorizers/cedar/core.go:717 (4682669328): overlong line

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Withhold only defaults ordered before the selected

A default group claim ordered after the access token's selected default
cannot win the first-match loop, so withholding it only dropped
legitimate id_token fills, such as a RoleClaimName of "roles" next to an
access-token "groups".

Addresses #6054 review comments:
- LOW pkg/authz/authorizers/cedar/core.go:879 (4683405287): withhold only names before the selected default
- LOW pkg/authz/authorizers/cedar/core.go:696 (4683405306): "yields groups", not "present"
- LOW pkg/authz/authorizers/cedar/core_test.go:3066 (4683405319): scalar end-to-end, non-string list and object cases
- LOW docs/authz.md:718 (4683405335): state when app roles fill; drop the remedy that cannot apply
- LOW docs/authz.md:706 (4683405355): name the list-only trigger
- LOW docs/operator/virtualmcpserver-kubernetes-guide.md:773 (4683405370): name the release boundary
- INFO pkg/authz/authorizers/cedar/core.go:924 (4683405383): refill comments
- INFO docs/operator/virtualmcpserver-kubernetes-guide.md:688 (4683405395): rewrap bullet

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Take group and role claims from one token

Filling group and role claims from the id_token one claim at a time let
a single decision combine the resource API's answer with ToolHive's
client registration's: the access token's groups with the id_token's
roles, or, with a group claim name configured, the id_token's list
replacing the access token's roles as the group set. Now, when the
access token asserts any claim group extraction reads, the id_token
fills none of them; when it asserts none, the id_token supplies them
all, which keeps the #6049 case working.

Addresses #6054 review comments:
- pkg/authz/authorizers/cedar/core.go:652 (4686436974): fill group and role claims as a unit

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Never fill provider token-describing claims

The id_token supplement is a deny-list, so a token-describing claim
missing from it is filled silently. Add the ones Entra ID, Okta, Auth0
and Keycloak emit that fit the existing categories: token version and
type (ver, idtyp), the requesting client and how it authenticated
(appid, appidacr, azpacr, cid, gty, allowed-origins), session and
capability claims (session_state, xms_cc, acrs), and RFC 9396
authorization_details alongside scope.

Addresses #6054 review comments:
- pkg/authz/authorizers/cedar/core.go:951 (4686437012): add the missing token-describing claims

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Frame id_token claims as the client registration's

Group and role claims are computed per client or audience at every major
IdP, so a claim filled from the id_token is ToolHive's client
registration's answer, not a parity with the access token. Say that
outright and turn the Entra app-role and empty-filter notes into
configuration guidance.

The freshness text was wrong in both directions: an expired id_token
already triggers a refresh, and the refresh-token lifespan renews on
every refresh, so it bounds only idle sessions. Describe the real
windows, including providers that omit an empty groups claim, and
Microsoft's advice on refreshed id_tokens.

Also drop hd from the newly usable claims (Google access tokens are
opaque, so that path never reads the id_token) and add an upgrade note
to docs/authz.md for MCPServer and MCPRemoteProxy users.

Addresses #6054 review comments:
- pkg/authz/authorizers/cedar/core.go:652 (4686436974): client registration is authoritative
- pkg/authz/authorizers/cedar/core.go:719 (4686436985): correct the freshness window
- pkg/authz/authorizers/cedar/core.go:786 (4686436994): drop hd from the newly usable claims
- review body (6047270207): upgrade note in docs/authz.md

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Correct last-group revocation and version range

Keycloak and Entra rotate the id_token on the same refresh, so a revoked
last group leaves no stale list unless rotation or the refresh fails.
The id_token fill misses v0.69.x, so the upgrade notes cover through
v0.69.1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Trey <[email protected]>

@ChrisJBurns ChrisJBurns left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Possibly important · security — The docs recommend adding openid to pure OAuth 2.0 upstreams, which makes an unvalidated id_token the source of the Cedar principal (docs/operator/virtualmcpserver-kubernetes-guide.md:54)

    For a pure OAuth 2.0 upstream, convertOAuth2Token (pkg/authserver/upstream/oauth2.go:270) stores any id_token it finds in the token response. It checks nothing: not the signature, iss, aud or nonce. The user identity is resolved separately from userinfo, and the id_token's sub is never compared with that subject. With this PR, claimsForOpaqueUpstreamToken (core.go:740) makes that unchecked sub the Cedar principal. The docs recommend this exact setup ("Requesting the openid scope … is what fixes it").

    Recommendation: Either add a caveat that id_tokens from OAuth 2.0 (non-OIDC) upstreams are not validated, or point operators to configure such providers as OIDC upstreams so the id_token is verified. Better still, check the id_token sub against the session's recorded upstream subject before using it as the principal, and fall back or deny if they differ.

}
return parseUpstreamJWTClaims(idToken)
}()
if err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly important · security — A stored id_token that fails to parse silently switches the Cedar principal to ToolHive's internal user ID (fails open)

claimsForOpaqueUpstreamToken handles "id_token stored but unparsable" the same way as "no id_token" and falls back to the ToolHive-issued claims. In that case the principal becomes Client::"<internal-uuid>". A forbid(principal == Client::"<upstream-subject>", …) rule, which the new docs say now matches on this path, stops matching, and a broad permit applies. The only signal is one rate-limited WARN. This goes against the file's own rule for a malformed JWT-shaped access token (core.go:670-673: "preserve the deny … so a tampered upstream JWT cannot bypass policy"). The docs (guide lines ~4

Recommendation: Keep the fallback only for errNoUpstreamIDToken. When an id_token is present but cannot be parsed, return an error so the request is denied, the same as the JWT-shaped branch. Change the unparsable_id_token_falls_back_to_the_toolhive_issued_claims test to expect a deny.

"error", err)
})
a.logClaimKeys("token-fallback", requestClaims)
return requestClaims

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly important · maintainability · pre-existing — The issue's own multi-upstream example (okta + github, github pinned) is still not fixed

Issue #6048's second consequence uses upstreamProviders: [okta, github] with primaryUpstreamProvider: github and shows okta's email being attributed to github. GitHub never has an id_token, so claimsForOpaqueUpstreamToken returns requestClaims whole for this exact setup. Okta's mirrored email and name still reach Cedar as if github had asserted them, and the principal is still the internal UUID. The PR fixes Google-style OIDC providers but leaves the issue's motivating example unchanged.

Recommendation: In the fallback, consider keeping only sub from requestClaims (the principal has to come from somewhere) and dropping name/email. Profile claims would then fail toward deny instead of carrying the wrong provider's identity, which is how the JWT path already behaves with no id_token. If the current choice stays, record in the PR and release note that the okta+github case from #6048 is deliberately left unresolved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cedar claim source and principal differ between JWT and opaque upstream access tokens

2 participants