fix(ers): fix direct entitlements silently dropped on token-identifier decisions - #3908
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughChangesThe change centralizes supported direct-entitlement claim keys. Token-chain processing now requires ERS hydration when these claims are present. Unit and BDD tests cover entitlement preservation and permit or deny decisions. Direct entitlement hydration
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The PR makes a localized correction to direct entitlement handling on token-identifier decisions with corresponding test updates; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Client
participant JustInTimePDP
participant ERS
Client->>JustInTimePDP: submit token chain
JustInTimePDP->>JustInTimePDP: detect direct-entitlement claim
JustInTimePDP->>ERS: hydrate resolved chain
ERS-->>JustInTimePDP: return representation with entitlements
JustInTimePDP-->>Client: evaluate action as PERMIT or DENY
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 4 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
There was a problem hiding this comment.
Pull request overview
Fixes a regression in the access decision flow where direct entitlements present on JWT claims were silently dropped when decisions were made via token identifiers (token → entity chain shortcut path), and adds regression coverage across unit + BDD tests.
Changes:
- Force ERS hydration when resolved token-chain claims include direct-entitlements claim keys so entitlements are preserved on entity representations.
- Add unit tests to verify hydration is triggered and that both
direct_entitlementsanddirectEntitlementsclaim keys are handled. - Add BDD scenarios + step support to mint JWTs with direct entitlements and exercise the token-identifier decision path.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests-bdd/go.mod |
Adds a direct dependency on lestrrat-go/jwx/v2 for JWT minting in BDD steps. |
tests-bdd/features/direct-entitlements.feature |
Adds BDD regression scenarios for token-based direct-entitlement permit/deny behavior. |
tests-bdd/cukes/steps_directentitlements.go |
Implements a new step to mint/store JWTs with direct entitlements for token-identifier decisioning. |
service/internal/access/v2/just_in_time_pdp.go |
Detects direct-entitlement claim keys on resolved token-chain claims and forces ERS hydration to avoid dropping entitlements. |
service/internal/access/v2/just_in_time_pdp_test.go |
Adds unit regression tests asserting hydration is required/preserved for both claim-key variants. |
service/entityresolution/claims/v2/entity_resolution.go |
Centralizes the supported direct-entitlements claim keys and uses them during parsing. |
Suppressed comments (1)
service/internal/access/v2/just_in_time_pdp.go:445
- Hydration is forced whenever the direct-entitlements claim key exists, even if direct entitlements are disabled (or the claim is present but empty). That can introduce an extra ERS ResolveEntities call for tokens that won’t use direct entitlements. Consider gating this on the PDP’s
allowDirectEntitlementsflag (and possibly checking for a non-empty list) to avoid unnecessary RPCs.
// Direct entitlements are carried inline on the claims. Taking the no-rehydrate
// shortcut here would silently drop them, so defer to ERS whenever the claim is present.
if key, ok := directEntitlementClaimKey(&claimsStruct); ok {
return nil, fmt.Errorf("%w: entity %s carries %q claims", errResolvedTokenChainRequiresHydration, chained.GetEphemeralId(), key)
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
|
Proposed Changes
Fixes a regression in the access decision flow where direct entitlements present on JWT claims were silently dropped when decisions were made via token identifiers (token → entity chain shortcut path), and adds regression coverage across unit + BDD tests.
Changes:
direct_entitlementsanddirectEntitlementsclaim keys are handled.Checklist
Testing Instructions
Summary by CodeRabbit
direct_entitlementsanddirectEntitlementsclaim formats.PERMITand mismatched actions returnDENY.