Repository navigation
Let Cedar read user claims the upstream asserts only in its ID token - #6054
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
4485b74 to
82c4f57
Compare
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
82c4f57 to
d27057e
Compare
tgrunnagle
left a comment
There was a problem hiding this comment.
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.mdstill describes a "profile-claim" id_token supplement (docs/authz.md:671): the claim-source table saysupstream:<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
task test— the cedar and authz packages should pass.- Mixed-key group extraction: configure
PrimaryUpstreamProviderwith noGroupClaimName, an access token carryingroles: ["admin"]and an id_token carryinggroups: ["eng"], and a policypermit ... when { principal in THVGroup::"admin" }. On this branch it denies; it should permit. - Negative control for the scope exclusion: delete the
"scope": {}, "scp": {}line fromidTokenClaimsNeverSupplementedand confirmid_token_scope_does_not_permitfails. - Run against a real OIDC upstream (e.g. Okta with groups in the ID token only) and confirm a
THVGrouppolicy now permits,thv_claim_sourceisupstream:<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.
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]>
|
Addressed in 64c8833 (review-body finding, |
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]>
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]>
tgrunnagle
left a comment
There was a problem hiding this comment.
Review
The two commits since the last review close both medium findings:
defaultGroupClaimsToWithholdnow exempts onlyGroupClaimName.- It triggers on the same test extraction applies, so a null or scalar default no longer withholds the others.
resolveClaims,docs/authz.mdand the operator guide document the Entra app-role limit.- The wording, wrapping and test comments flagged earlier are fixed.
TestDefaultGroupClaimsToWithholdpins 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
RoleClaimNamedisplacing access-tokenroles(core.go): onlyGroupClaimNameis exempt; pinned bydefault_named_role_claim_does_not_displace_access_token_rolesandTestDefaultGroupClaimsToWithhold. - Entra
rolesper 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 theDecodeStringArrayLenienttest 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/customGroupClaimNamecoverage (core_test.go):roleClaimNamecolumn andTestDefaultGroupClaimsToWithhold. - 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
task testandtask lint-fixpass.- Over-withhold: add
RoleClaimName: "roles", access{groups: ["eng"]}, id_token{roles: ["admin"]}with aTHVGroup::"admin"permit toTestAuthorizeWithJWTClaims_DefaultGroupClaimSelection. Today it denies; withholding only names ordered before the selected default would permit, whiledefault_named_role_claim_does_not_displace_access_token_roleskeeps passing. - Deliberately break the trigger: replace the
DecodeStringArrayLenientcheck with key presence and confirmnull_default_withholds_nothingandscalar_default_withholds_nothingfail. - Re-add
a.roleClaimNameto the exemption and confirmdefault_named_role_claim_is_not_exemptanddefault_named_role_claim_does_not_displace_access_token_rolesfail.
Reviewed by dev:review-pr (finders: correctness, readability, documentation). Generated with Claude Code.
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]>
tgrunnagle
left a comment
There was a problem hiding this comment.
Incremental review of 0399120 (since a35aec9)
0399120 settles all 8 LOW/INFO findings from the previous round.
defaultGroupClaimsToWithholdnow withholds only the default names ordered before the access token's first list-valued default, still minusGroupClaimName.- The withhold matches the first-match default loop in
authorizeWithClaims, so filling from theid_tokencan 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.0throughv0.68.0range is correct: the name/email supplement first shipped inv0.41.0, andv0.68.0is 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
left a comment
There was a problem hiding this comment.
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]inconcepts/cedar-policies.mdxtelling 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.mdxtroubleshooting 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.mdxand_partials/_auth-troubleshooting.mdxall 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.
jhrozek
left a comment
There was a problem hiding this comment.
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.
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]>
|
On the review body (6047270207):
|
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]>
jhrozek
left a comment
There was a problem hiding this comment.
Thanks, all addressed; the unit rule for group claims is a nice fix. Re-approving.
* 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]>
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_tokenproduced an empty group setand every
principal in THVGroup::"..."policy denied for every user, with nodiagnostic beyond the
hasguard failing. Same shape as #5916 — a claim the upstreamdoes assert, in a token ToolHive already holds, that the authorizer never looked at.
profileClaimsFromIDToken = {name, email}is replaced byidTokenClaimsNeverSupplemented, a closed deny-list of token-describing claims(standardized and provider-specific), the delegated grant, and
sub; every otherclaim the pinned provider's
id_tokenasserts is now admitted, still fill-only (theaccess 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 defaultgroups/roles/cognito:groups), theid_tokenfills none of them. When it asserts none, they come from the
id_token, which isToolHive'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 storedid_token; see "Specialnotes".
Type of change
Test plan
task test)task lint-fix)task test-e2e)task lint-fixreports 0 issues andtask testpasses.Two negative controls, because tests for a change that grants access have to prove
the grant rather than describe it:
{name, email}semantics fails the grant-pathsubtests. 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, andTestAuthorizeWithJWTClaims_PrincipalStaysUpstreamSourced."scope": {}, "scp": {}deny-list line fails the scopesubtests (
id_token_scope_does_not_permitamong them), so that exclusion isload-bearing rather than decorative.
TestAuthorizeWithJWTClaims_GroupClaimsFromOneTokenpins that anid_token-onlygroupsneither hides nor overrides the access token'sroles, that a configuredgroup or role claim is not filled next to an access-token group claim (including a
nested
realm_access.roles), and that theid_tokensupplies them when the accesstoken asserts none.
TestGroupClaimsToWithholdpins the rule per claim shape.Does this introduce a user-facing change?
Yes — it grants access that is currently denied. Only where
primaryUpstreamProvideris set, the pinned provider has a stored
id_token, and the claim is one its accesstoken omits entirely:
THVGroup/GroupEntityTypepolicy because the providerasserts groups in the id_token only —
tools/listgoes from empty to populated,tools/callfrom 403 to 200. The widest case, and the reported one.RoleClaimName,cognito:groups, and URI-style group claims.has-guarded gates onemail_verified,acr/amr/auth_timeand custom userclaims the provider puts in the id_token only. (
hdis not among them: Google'saccess tokens are opaque, and the opaque branch does not read the
id_token.)Unchanged:
primaryUpstreamProviderempty; the opaque-token branch; any claim theaccess 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 roleclaim when the access token asserts any of them. Decisions can change in both
directions: a
permitorforbidkeyed onTHVGroupor a supplemented claim canstart matching, a
!(principal has claim_X)condition orunlessclause can stopmatching, and a claim arriving with an unexpected type makes the policy error and the
request deny.
docs/authz.mdand the operator guide carry an upgrade note tellingoperators to review
permitandforbidrules. The supplement is logged at DEBUG, since it fires onordinary 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-stylenames), 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_tokenis ToolHive's clientregistration'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 9396authorization_details, not onlythe 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
groupswith theclient's
roles, and a filled default name could win the first-match default loop, sogroup and role claims are filled as a unit (
groupClaimsToWithhold): if the accesstoken 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_tokenare the user's roles on ToolHive's auth-server client. The second and thirdare documented in
docs/authz.mdand the operator guide as configuration of theclient registration, rather than gated.
3.
scope/scpare excluded. A claim asserting what a token may do is notsomething 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 onlyMail.Read, the access token carries the narrower grant, and supplementing would leta
claimset_scp.containsAny("Mail.ReadWrite")gate match authority the userexplicitly declined. Note this reverses an earlier position in this series — a prior
test named
scopealongsidegroupsas authorization-bearing — so it is a deliberatechange of stance.
TestAuthorizeWithJWTClaims_ScopeStaysAccessTokenSourcedpins itend to end, and
TestMergeIDTokenClaimspins the downscoped-consent case. TheRFC 8693 delegation claims
act/may_actand RFC 9396authorization_detailsareexcluded on the same grounds.
4. Freshness of
id_token-sourced groups — the trade-off to weigh. The storedid_tokenis deliberately used pastexp(seeIdentity.UpstreamIDTokens);enforcing
expwould flip permit→deny mid-session for every user, not only a revokedone. How stale it gets depends on the provider:
id_tokenalready triggers an upstream refresh even while the accesstoken is valid (
shouldRefreshForIDTokeninupstreamtoken/service.go), and Entra,Okta, Auth0 and Keycloak return a new
id_tokenon refresh whenopenidwasrequested, so for them filled groups track the provider at about the
id_token'slifetime.
id_token, or a failed refresh, leaves the old onein place for as long as the session is kept alive.
refreshTokenLifespanis not abound: fosite renews the refresh token's expiry on every refresh, so it limits only
idle sessions.
groupswhen theuser has none, so the refreshed access token has no group claim and the
id_tokenisconsulted. Both return a new
id_tokenon that same refresh, which omitsgroupstoo, so nothing stale is filled. A stale list survives only where such a provider
does not rotate the
id_tokenor the refresh fails; keeping groups out of theid_tokencloses that case. Microsoft also advises against relying on anid_tokenfrom a refreshfor 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.mdcovers it too.This also corrects a claim I wrote in #6036:
Identity.UpstreamIDTokenssaid theid_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
claimsForOpaqueUpstreamTokenloops overprofileClaimsFromIDToken, which this PR deletes, so whichever lands second will notcompile. The rules also differ: #6052 lets the
id_tokensupplysubplus{name, email}on the opaque path, while this PR fills everything except thedeny-list (never
sub) on the JWT path. One rule for both paths is being settled inthe 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,MCPRemoteProxyandVirtualMCPServer. Nothv runflag configures it, so only a hand-written--from-configRunConfig reaches it from the CLI, and the upgrade notes cover theoperator paths.
Generated with Claude Code