Skip to content

Let Cedar read user claims the upstream asserts only in its ID token - #6054

Merged
tgrunnagle merged 13 commits into
mainfrom
feat-cedar-id-token-group-claims-6049
Nov 25, 2026
Merged

tgrunnagle merged 13 commits into
mainfrom
feat-cedar-id-token-group-claims-6049

Conversation

@JAORMX

@JAORMX JAORMX commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

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 produced an empty group set
and every principal in THVGroup::"..." policy denied for every user, with no
diagnostic beyond the has guard failing. Same shape as #5916 — a claim the upstream
does assert, in a token ToolHive already holds, that the authorizer never looked at.

profileClaimsFromIDToken = {name, email} is replaced by
idTokenClaimsNeverSupplemented, a closed deny-list of token-describing claims
(standardized and provider-specific), the delegated grant, and sub; every other
claim the pinned provider's id_token asserts is now admitted, still fill-only (the
access token always wins). Group and role claims come from one token as a unit: when
the access token asserts any claim group extraction reads (GroupClaimName,
RoleClaimName, or a default groups/roles/cognito:groups), the id_token
fills none of them. When it asserts none, they come from the id_token, which is
ToolHive's client registration's answer at the IdP, and the docs say to configure
group filters and app roles there.

Fixes #6049

This is wider than the issue scoped (an allow-list became a deny-list), and
id_token-sourced groups are only as fresh as the stored id_token; see "Special
notes".

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)

task lint-fix reports 0 issues and task test passes.

Two negative controls, because tests for a change that grants access have to prove
the grant rather than describe it:

  • Reverting the deny-list to the old {name, email} semantics fails the grant-path
    subtests. Critically, the security invariants pass
    identically in both configurations — so they bound the boundary rather than
    merely exercising the new code: toolhive_groups_ignored_when_upstream_configured,
    direct_groups_ignored_when_upstream_configured,
    id_token_token_describing_claims_are_never_filled_or_overwritten, and
    TestAuthorizeWithJWTClaims_PrincipalStaysUpstreamSourced.
  • Deleting the single "scope": {}, "scp": {} deny-list line fails the scope
    subtests (id_token_scope_does_not_permit among them), so that exclusion is
    load-bearing rather than decorative.
  • TestAuthorizeWithJWTClaims_GroupClaimsFromOneToken pins that an id_token-only
    groups neither hides nor overrides the access token's roles, that a configured
    group or role claim is not filled next to an access-token group claim (including a
    nested realm_access.roles), and that the id_token supplies them when the access
    token asserts none. TestGroupClaimsToWithhold pins the rule per claim shape.

Does this introduce a user-facing change?

Yes — it grants access that is currently denied. Only where primaryUpstreamProvider
is set, the pinned provider has a stored id_token, and the claim is one its access
token omits entirely
:

  1. Requests denied by a THVGroup/GroupEntityType policy because the provider
    asserts groups in the id_token only — tools/list goes from empty to populated,
    tools/call from 403 to 200. The widest case, and the reported one.
  2. The same for RoleClaimName, cognito:groups, and URI-style group claims.
  3. has-guarded gates on email_verified, acr/amr/auth_time and custom user
    claims the provider puts in the id_token only. (hd is not among them: Google's
    access tokens are opaque, and the opaque branch does not read the id_token.)

Unchanged: primaryUpstreamProvider empty; the opaque-token branch; any claim the
access token already asserts (fill-only); providers with no stored id_token; group,
role and scope claims on the ToolHive-issued token (still grant nothing); the
principal; the claims in idTokenClaimsNeverSupplemented; and every group and role
claim when the access token asserts any of them. Decisions can change in both
directions: a permit or forbid keyed on THVGroup or a supplemented claim can
start matching, a !(principal has claim_X) condition or unless clause can stop
matching, and a claim arriving with an unexpected type makes the policy error and the
request deny. docs/authz.md and the operator guide carry an upgrade note telling
operators to review permit and forbid rules. The supplement is logged at DEBUG, since it fires on
ordinary traffic for most OIDC providers.

Special notes for reviewers

1. The scope expansion — why an allow-list was replaced rather than extended. An
allow-list provably cannot work here: the claim carrying group membership is named by
the deployment (GroupClaimName/RoleClaimName) or by the IdP (Auth0/Okta URI-style
names), so any fixed list denies silently for names ToolHive does not choose — the
defect shape of both #5916 and #6049. Config-derived would cover the two configured
names and still miss the well-known defaults' relatives and per-tenant organization
claims, guaranteeing a third round.

Why the admitted group and role claims are safe to use: every major IdP computes them
per client or per audience (Entra per app registration, Okta per authorization server
and app, Auth0 per token in Actions, Keycloak through the client's role scope
mappings), so a group claim filled from the id_token is ToolHive's client
registration's answer rather than the resource API's. That is the model, stated
outright: when the access token carries no group or role claim, ToolHive's client
registration is authoritative, and operators configure group filters, app roles and
client scopes there. Because a deny-list fills anything it does not name, it covers
the provider-specific token-describing claims Entra, Okta, Auth0 and Keycloak emit
(ver, idtyp, appid, appidacr, azpacr, cid, gty, allowed-origins,
session_state, xms_cc, acrs) and RFC 9396 authorization_details, not only
the standardized names.

2. Precedence is fill-only, deliberately not union. Union looked attractive for
set-valued claims and is unsafe in the direction that matters: per-application claim
filtering (Okta group filters, Entra group-claim config) is applied when a token is
minted for a given audience, so the access token's group list is the provider's answer
to "which of this user's groups are relevant to this resource server". Unioning the
id_token's list — minted for ToolHive's own auth-server client — would restore groups
the provider deliberately withheld from this audience. Fill-only never contradicts or
extends a claim the access token asserts, with three documented consequences. First,
filling per claim would let one decision combine the resource API's groups with the
client's roles, and a filled default name could win the first-match default loop, so
group and role claims are filled as a unit (groupClaimsToWithhold): if the access
token asserts any claim group extraction reads, none of them is filled. Second, a
per-audience filter that matches nothing typically makes the provider omit the claim,
and the client registration's list then fills in. Third, Entra app roles in the
id_token are the user's roles on ToolHive's auth-server client. The second and third
are documented in docs/authz.md and the operator guide as configuration of the
client registration, rather than gated.

3. scope/scp are excluded. A claim asserting what a token may do is not
something a client registration can answer for another token. Concretely, granular and
incremental consent (Google granular permissions, Entra incremental consent) make
requested-minus-granted the normal case, and an id_token is minted from the
authorization request: client asks for Mail.ReadWrite, user grants only
Mail.Read, the access token carries the narrower grant, and supplementing would let
a claimset_scp.containsAny("Mail.ReadWrite") gate match authority the user
explicitly declined. Note this reverses an earlier position in this series — a prior
test named scope alongside groups as authorization-bearing — so it is a deliberate
change of stance. TestAuthorizeWithJWTClaims_ScopeStaysAccessTokenSourced pins it
end to end, and TestMergeIDTokenClaims pins the downscoped-consent case. The
RFC 8693 delegation claims act/may_act and RFC 9396 authorization_details are
excluded on the same grounds.

4. Freshness of id_token-sourced groups — the trade-off to weigh. The stored
id_token is deliberately used past exp (see Identity.UpstreamIDTokens);
enforcing exp would flip permit→deny mid-session for every user, not only a revoked
one. How stale it gets depends on the provider:

  • An expired id_token already triggers an upstream refresh even while the access
    token is valid (shouldRefreshForIDToken in upstreamtoken/service.go), and Entra,
    Okta, Auth0 and Keycloak return a new id_token on refresh when openid was
    requested, so for them filled groups track the provider at about the id_token's
    lifetime.
  • A provider that never rotates the id_token, or a failed refresh, leaves the old one
    in place for as long as the session is kept alive. refreshTokenLifespan is not a
    bound: fosite renews the refresh token's expiry on every refresh, so it limits only
    idle sessions.
  • Revoking a user's last group: Keycloak (and apparently Entra) omit groups when the
    user has none, so the refreshed access token has no group claim and the id_token is
    consulted. Both return a new id_token on that same refresh, which omits groups
    too, so nothing stale is filled. A stale list survives only where such a provider
    does not rotate the id_token or the refresh fails; keeping groups out of the
    id_token closes that case. Microsoft also advises against relying on an id_token from a refresh
    for authorization, so the Entra guidance prefers access-token claims.

The affected deployments currently deny everything, so for them this goes from
broken to working. The operator guide carries this as a Warning callout, and
docs/authz.md covers it too.

This also corrects a claim I wrote in #6036: Identity.UpstreamIDTokens said the
id_token's claims are "no staler than the alternative, since the profile claims
mirrored into the ToolHive-issued token are likewise captured once at login". True for
email; false for groups, because there is no issued-token alternative for those.

Interaction with #6052 (issue #6048): the two conflict at build time, not just in
a comment. #6052's claimsForOpaqueUpstreamToken loops over
profileClaimsFromIDToken, which this PR deletes, so whichever lands second will not
compile. The rules also differ: #6052 lets the id_token supply sub plus
{name, email} on the opaque path, while this PR fills everything except the
deny-list (never sub) on the JWT path. One rule for both paths is being settled in
the follow-up alongside the docs-website changes, as agreed in review; it also decides
the Google case from #6049, which is the opaque path.

The embedded auth server pins the first upstream on MCPServer, MCPRemoteProxy and
VirtualMCPServer. No thv run flag configures it, so only a hand-written
--from-config RunConfig reaches it from the CLI, and the upgrade notes cover the
operator paths.

Generated with Claude Code

@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Jul 27, 2026
@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 82.06%. Comparing base (44f7d63) to head (e0f3387).
⚠️ Report is 25 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6054      +/-   ##
==========================================
+ Coverage   81.88%   82.06%   +0.17%     
==========================================
  Files         915      927      +12     
  Lines       92769    93977    +1208     
==========================================
+ Hits        75966    77122    +1156     
- Misses      16798    16850      +52     
  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.

@JAORMX
JAORMX force-pushed the feat-cedar-id-token-group-claims-6049 branch from 4485b74 to 82c4f57 Compare July 28, 2026 07:15
@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 Jul 28, 2026
JAORMX and others added 2 commits November 24, 2026 06:59
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
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
@tgrunnagle
tgrunnagle force-pushed the feat-cedar-id-token-group-claims-6049 branch from 82c4f57 to d27057e Compare November 24, 2026 15:11

@tgrunnagle tgrunnagle 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.

Review

Bug fix for a deny-all: Cedar read group claims only from the pinned upstream's access token, so providers that assert groups in the id_token alone produced an empty group set. The fix replaces the {name, email} id_token allow-list with a closed, spec-derived deny-list (registered/token-describing claims, scope/scp, sub), fill-only, access token always wins. The provenance argument is sound — both tokens come from one credential bundle per provider (pkg/auth/token.go), the ToolHive-issued token is still not read on this path, and sub/scope/scp stay out. The deny-list is wider than #6049 scoped (hd, email_verified, acr/amr/auth_time, custom claims now also fill); that is a deliberate, documented choice the author has flagged for maintainer sign-off.

The weak point is the stated safety invariants rather than the mechanism: "fill-only can never contradict or extend the access token" does not hold once default group-claim selection is considered (id_token groups shadows access-token roles), nor when an audience filter yields an empty set and the claim is omitted. The first is a real permit/deny flip and should be fixed before merge.

The branch has been rebased onto current main, which added the sessionless-grant and opaque-token fallbacks and the thv_claim_source label; the doc text was reconciled so "the issued token is never a claim source" is scoped to the upstream:<provider> path.

Findings

# Severity Finding Location Raised by
1 HIGH id_token groups displaces the access token's own roles/cognito:groups in default group extraction pkg/authz/authorizers/cedar/core.go:941 security, correctness
2 MEDIUM docs/authz.md still describes a "profile-claim" id_token supplement docs/authz.md:671 documentation
3 MEDIUM Fill-only does not preserve per-audience group withholding when the filtered list is empty pkg/authz/authorizers/cedar/core.go:698-712 security
4 LOW Same rationale restated in several doc comments pkg/authz/authorizers/cedar/core.go:915 readability
5 LOW No regression guard that the opaque fallback ignores the stored id_token pkg/authz/authorizers/cedar/core_test.go:2874 tests
6 LOW "Not a regression" / "unaffected" overstates the change docs/operator/virtualmcpserver-kubernetes-guide.md:729-735 documentation
7 LOW Doc comment narrates the allow-list history and the PR itself pkg/authz/authorizers/cedar/core.go:660-668 readability
8 LOW Change-relative wording in comments, tests and docs pkg/authz/authorizers/cedar/core.go:724 readability
9 LOW supplementFromIDToken vs supplementFromIDTokenClaims pkg/authz/authorizers/cedar/core.go:925 readability
10 LOW Deny-list omits other token-describing claims pkg/authz/authorizers/cedar/core.go:898-910 security
11 LOW Supplement WARN fires on the normal path pkg/authz/authorizers/cedar/core.go:843 holistic
12 LOW Test comment says fill-only "is not enough" where it is pkg/authz/authorizers/cedar/core_test.go:2268-2270 readability
13 LOW Authorizer-level scope case duplicates existing coverage pkg/authz/authorizers/cedar/core_test.go:2271-2279 tests, readability
14 INFO Emoji heading inside a blockquote docs/operator/virtualmcpserver-kubernetes-guide.md:707 readability
15 INFO Opaque-token branch still skips the id_token; state the deviation pkg/authz/authorizers/cedar/core.go:797 correctness
16 INFO Issue asked for the authorization-bearing test to stay unchanged pkg/authz/authorizers/cedar/core_test.go:1722 scope

Additional findings

  • [MEDIUM] docs/authz.md still describes a "profile-claim" id_token supplement (docs/authz.md:671): the claim-source table says upstream:<provider> claims come from the access token "with the profile-claim id_token supplement where it applies". The code now fills any non-excluded claim, groups and roles included. The fill-only precedence, the empty-filter boundary and the group-revocation window are documented only in the operator guide, though the CLI path reaches the same code. Update the row and add a short section (or link) on what the id_token can supply and the login-time staleness of id_token-sourced groups.

How to test

  1. task test — the cedar and authz packages should pass.
  2. Mixed-key group extraction: configure PrimaryUpstreamProvider with no GroupClaimName, an access token carrying roles: ["admin"] and an id_token carrying groups: ["eng"], and a policy permit ... when { principal in THVGroup::"admin" }. On this branch it denies; it should permit.
  3. Negative control for the scope exclusion: delete the "scope": {}, "scp": {} line from idTokenClaimsNeverSupplemented and confirm id_token_scope_does_not_permit fails.
  4. Run against a real OIDC upstream (e.g. Okta with groups in the ID token only) and confirm a THVGroup policy now permits, thv_claim_source is upstream:<provider>, and an opaque-token upstream (Google/GitHub) behaves as before.

Reviewed by dev:review-pr (finders: correctness, readability, security, tests, documentation, scope discipline). Generated with Claude Code.

Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
@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 24, 2026
tgrunnagle and others added 3 commits November 24, 2026 07:27
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]>
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]>
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]>
@tgrunnagle

Copy link
Copy Markdown
Collaborator

Addressed in 64c8833 (review-body finding, docs/authz.md:671): the upstream:<provider> row no longer says "profile-claim supplement". It links to a new Claims from the upstream id_token section covering what can be filled, what never is, fill-only precedence, default group selection, the empty-filter boundary, and login-time freshness. The CLI path now has the same documentation as the operator guide.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/L Large PR: 600-999 lines changed labels 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]>
@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 24, 2026
tgrunnagle and others added 2 commits November 24, 2026 08:32
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]>
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]>
@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 24, 2026

@tgrunnagle tgrunnagle 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.

Review

The two commits since the last review close both medium findings:

  • defaultGroupClaimsToWithhold now exempts only GroupClaimName.
  • It triggers on the same test extraction applies, so a null or scalar default no longer withholds the others.
  • resolveClaims, docs/authz.md and the operator guide document the Entra app-role limit.
  • The wording, wrapping and test comments flagged earlier are fixed.
  • TestDefaultGroupClaimsToWithhold pins the rule against each claim-name configuration.

The default group claim can no longer be displaced in any configuration, and no #6049 fill (groups only in the id_token) is withheld.

What remains is low severity. The withhold now covers more than it needs to: it also blocks a default-named role claim that sits after the access token's selected default, so it can't win the loop. That costs a legitimate configured fill, and it fails closed. The rest are documentation precision (the app-role caveat's precondition, "asserts" vs. a list, the Migration release boundary), one stale comment, a test gap for the null/scalar path, and two wrapping nits.

The scope-signoff thread on the inverted test stays open for a maintainer. Its existing threads carry it, so it is not re-raised here.

Findings

# Severity Finding Location Raised by
1 LOW Withholding every default name drops role fills that cannot displace anything pkg/authz/authorizers/cedar/core.go:879 correctness
2 LOW resolveClaims says default selection takes the first name "present" pkg/authz/authorizers/cedar/core.go:696 readability
3 LOW The null/scalar trigger change has no end-to-end test, and two value shapes are untested pkg/authz/authorizers/cedar/core_test.go:3066 correctness
4 LOW Entra app-role caveat states the fill unconditionally; one remedy cannot help a user without a resource role docs/authz.md:718 documentation
5 LOW "Asserts any of" is broader than the withhold rule docs/authz.md:706 documentation
6 LOW Migration callout's release boundary cannot be mapped to a version docs/operator/virtualmcpserver-kubernetes-guide.md:773 documentation, readability
7 INFO Comment refill left ragged lines pkg/authz/authorizers/cedar/core.go:924 readability
8 INFO Line widened by the "usually" edit docs/operator/virtualmcpserver-kubernetes-guide.md:688 readability
9 INFO Issue asked for this test to stay unchanged; the PR inverts it (still open; existing threads) pkg/authz/authorizers/cedar/core_test.go:1722 scope

Resolved since the last review

  • Default-named RoleClaimName displacing access-token roles (core.go): only GroupClaimName is exempt; pinned by default_named_role_claim_does_not_displace_access_token_roles and TestDefaultGroupClaimsToWithhold.
  • Entra roles per app registration (core.go, docs/authz.md, guide): documented as a third fill-only consequence with remedies.
  • Withhold trigger vs. extraction (core.go): trigger uses the DecodeStringArrayLenient test extraction applies.
  • Stale "safe direction" pointer (core.go): now "See resolveClaims for the rationale and its limits."
  • "These" referent in the delegated-grant bullet (core.go): rewritten; map-literal comments cut to labels.
  • Overlong freshness paragraph (core.go): re-flowed.
  • No RoleClaimName/custom GroupClaimName coverage (core_test.go): roleClaimName column and TestDefaultGroupClaimsToWithhold.
  • Change-relative wording (core_test.go, authz.md, core.go): rewritten.
  • Ragged test comments (core_test.go): re-wrapped.
  • Release-relative deployment-shape list (guide): present tense, with a Migration callout.
  • Repeated "What to do" sentence (guide): removed.
  • Claim-name spellings (authz.md): both Cedar-config and CRD names given.
  • Overlong deny-list line (guide): re-wrapped.

How to test

  1. task test and task lint-fix pass.
  2. Over-withhold: add RoleClaimName: "roles", access {groups: ["eng"]}, id_token {roles: ["admin"]} with a THVGroup::"admin" permit to TestAuthorizeWithJWTClaims_DefaultGroupClaimSelection. Today it denies; withholding only names ordered before the selected default would permit, while default_named_role_claim_does_not_displace_access_token_roles keeps passing.
  3. Deliberately break the trigger: replace the DecodeStringArrayLenient check with key presence and confirm null_default_withholds_nothing and scalar_default_withholds_nothing fail.
  4. Re-add a.roleClaimName to the exemption and confirm default_named_role_claim_is_not_exempt and default_named_role_claim_does_not_displace_access_token_roles fail.

Reviewed by dev:review-pr (finders: correctness, readability, documentation). Generated with Claude Code.

Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread docs/authz.md Resolved
Comment thread docs/authz.md Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
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]>
@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 24, 2026

@tgrunnagle tgrunnagle 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.

Incremental review of 0399120 (since a35aec9)

0399120 settles all 8 LOW/INFO findings from the previous round.

  • defaultGroupClaimsToWithhold now withholds only the default names ordered before the access token's first list-valued default, still minus GroupClaimName.
  • The withhold matches the first-match default loop in authorizeWithClaims, so filling from the id_token can no longer displace the default the access token selected.
  • The docs, the Go comments and the new tests all agree on that rule.
  • The Migration callout's v0.41.0 through v0.68.0 range is correct: the name/email supplement first shipped in v0.41.0, and v0.68.0 is the latest release. Bump the upper bound if another release ships before this merges.

This round reports MEDIUM or higher only, and nothing reached that bar.

One intended trade-off is worth knowing. Take a RoleClaimName that is a default name ordered after the access token's selected default, for example roles next to an access-token groups. The id_token's roles is now filled and joins the groups through the role-claim union. In Entra those are the client app's roles. resolveClaims and both docs say so, and role_claim_ordered_after_selected_default_fills covers it.

Status Finding
Resolved Withholding every default name dropped role fills that could not displace anything
Resolved resolveClaims said "present" instead of "yields groups"
Resolved Scalar end-to-end test and non-string-list/object shapes
Resolved Entra app-role caveat precondition and remedy
Resolved "Asserts any of" broader than the rule
Resolved Migration callout's release boundary
Resolved Ragged comment refill; overlong guide line
Still open (existing threads) Scope wider than #6049 inverts authorization_bearing_claims_are_not_filled. A maintainer needs to sign off.

@jhrozek jhrozek 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.

Could you also do a docs-website PR for this, landing with or before the release? Today every page there says Cedar reads claims from the access token, and a few now send people the wrong way:

  • guides-vmcp/embedded-auth-server-vmcp.mdx "Select the primary upstream provider" says Cedar reads the first upstream's access token, and reads as a vMCP-only knob. In practice the first upstream is auto-selected for MCPServer and MCPRemoteProxy too, the id_token fill applies on all of them, and there's no way to turn it off. That's worth saying, plus one :::info[Changed in vX.Y] in concepts/cedar-policies.mdx telling people to review both permit and forbid rules before upgrading (the site allows exactly one of those for silent behaviour changes). The same upgrade note belongs in docs/authz.md here; right now only the vMCP operator guide has one, and MCPServer/MCPRemoteProxy users won't read that.
  • integrations/vmcp-okta.mdx troubleshooting says the Org authorization server can only put groups in the ID token. That's the case this PR fixes, so it should become a supported option next to "Step 4: add a groups claim to the access token".
  • concepts/cedar-policies.mdx "How it works", reference/authz-policy-reference.mdx "Principal attributes", integrations/vmcp-idp-overview.mdx and _partials/_auth-troubleshooting.mdx all say to look at the access token for groups.

For the new content: the "client registration is authoritative" framing fits a new subsection under "Upstream identity provider claims" in cedar-policies.mdx (with an Entra note on the app registration page, and a Keycloak line there since it has no page); the refresh window fits "Automatic token refresh" in concepts/embedded-auth-server.mdx, which already describes the id_token-triggered refresh; and the "expect claims to appear" authoring advice fits "Designing secure policies", plus "Claim type mapping" and "How groups are resolved" in the policy reference. That last bit should cover that decisions can flip both ways, not just through forbid: !(principal has claim_X) and unless conditions stop matching, a claim arriving with an unexpected type (numbers become decimals, email_verified as a string) makes the policy error and the whole request is denied, and with group_claim_name set the id_token's list can replace the access token's roles as the group set.

One question: concepts/backend-auth.mdx says the embedded auth server is Kubernetes-only, but the runner also pins the first upstream for thv run. Is the CLI path meant to be supported? If not, the upgrade note can stick to the operator paths.

Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
Comment thread pkg/authz/authorizers/cedar/core.go Resolved
jhrozek
jhrozek previously approved these changes Nov 24, 2026

@jhrozek jhrozek 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.

Approving — the behaviour's right and the code's well tested. If it's cheap, it'd be good to fix the freshness text and add the deny-list entries here before merging; the docs-website changes and the client-registration framing can go in a follow-up docs PR, and the #6052 overlap can be settled there.

tgrunnagle and others added 3 commits November 25, 2026 08:05
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]>
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]>
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]>
@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 25, 2026
@tgrunnagle

Copy link
Copy Markdown
Collaborator

On the review body (6047270207):

  • docs-website: the draft is Document Cedar claims filled from the upstream ID token docs-website#1376. It covers every page you listed, using the placements you suggested:

    • the :::info[Changed in v0.69.0] in cedar-policies.mdx, telling readers to review permit and forbid rules;
    • the client-registration subsection, with a Keycloak line, plus the Entra note;
    • the refresh window under "Automatic token refresh";
    • "Expect claims to appear" in "Designing secure policies";
    • "Claim type mapping" and "How groups are resolved";
    • the Okta, IdP-overview and troubleshooting fixes.

    It's meant to land with or after the release.

  • Upgrade note in docs/authz.md: added in 69b200b, written for MCPServer and MCPRemoteProxy as well as vMCP. It lists the changes in both directions: negations and unless clauses can stop matching, type errors deny the request, and a configured group claim can become the group set when the access token has no group or role claim.

  • thv run: no CLI flag configures the embedded auth server. The only way to reach it from the CLI is a hand-written --from-config RunConfig, so I don't treat it as a supported path. The upgrade notes cover the operator paths only.

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]>
@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 25, 2026

@jhrozek jhrozek 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.

Thanks, all addressed; the unit rule for group claims is a nice fix. Re-approving.

@tgrunnagle
tgrunnagle merged commit a0e21c6 into main Nov 25, 2026
48 checks passed
@tgrunnagle
tgrunnagle deleted the feat-cedar-id-token-group-claims-6049 branch November 25, 2026 19:22
tgrunnagle added a commit to stacklok/docs-website that referenced this pull request Nov 25, 2026
* Document id_token claim fill for Cedar policies

Cedar now fills claims the upstream access token omits from the same
provider's id_token (stacklok/toolhive#6054). Update the pages that said
Cedar reads the access token only, frame ToolHive's client registration
as authoritative for those claims, and add the upgrade, freshness and
policy-authoring guidance.

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

* Rewrite id_token claim docs to the style guide

Keep the fill rules in one place on the Cedar concepts page and link to
it from the guides, trim the how-to notes to what the reader acts on,
and replace bolded bullet lists with prose.

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

* Address docs review of id_token claim pages

Target v0.70.0, correct the last-group revocation warning for providers
that rotate the ID token, require Always for Okta ID-token groups, and
add the type-error upgrade risk and decimal example.

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

* Document Okta Org AS and tighten fill scope

Addresses #1376 review comments:
- vmcp-okta.mdx (4700454933): give the real reason for a custom
  authorization server and document the Org authorization server
- embedded-auth-server.mdx (4700454941): name the client refresh that
  renews refreshTokenLifespan
- cedar-policies.mdx (4700454951): forbid rules can start matching
- cedar-policies.mdx (4700454960): the fill needs an ID token and a JWT
  access token

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

Cedar cannot see group claims that the upstream asserts only in its id_token

3 participants