Repository navigation
fix(auth): honor admin carve-outs on bearer-session permission checks - #1492
Conversation
Service.HasPermission (the bearer-session auth path) granted the three money-spending verbs carved out for separation of duties (execute, approve-any, and retry-any on purchases; issue #923) to any admin:* holder, unconditionally. AuthContext.HasPermission already enforced the carve-out, so the two paths disagreed: a bare Administrators-group member could execute or approve-any purchases through the bearer path while being correctly denied through the auth-context path. Wire permissionsAllow through the same adminCarvedOuts map so admin falls through to the explicit-permission check for the carved-out verbs instead of short-circuiting, mirroring AuthContext.HasPermission. Also updates TestGroupOnlyAuthz_AdminEquivalence, which asserted the pre-fix (buggy) behavior for execute:purchases and approve-any:purchases, to match the intended carve-out semantics. Closes #1454.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
…#1492) Service.HasPermission (the bearer-session auth path) granted the three money-spending verbs carved out for separation of duties (execute, approve-any, and retry-any on purchases; issue #923) to any admin:* holder, unconditionally. AuthContext.HasPermission already enforced the carve-out, so the two paths disagreed: a bare Administrators-group member could execute or approve-any purchases through the bearer path while being correctly denied through the auth-context path. Wire permissionsAllow through the same adminCarvedOuts map so admin falls through to the explicit-permission check for the carved-out verbs instead of short-circuiting, mirroring AuthContext.HasPermission. Also updates TestGroupOnlyAuthz_AdminEquivalence, which asserted the pre-fix (buggy) behavior for execute:purchases and approve-any:purchases, to match the intended carve-out semantics. Closes #1454.
Summary
Fixes a security bug where the bearer-session permission-check path (
Service.HasPermission/permissionsAllowininternal/auth/service_group.go) granted the three money-spending verbs carved out for separation of duties (execute:purchases,approve-any:purchases,retry-any:purchases; see #923) to any holder of theadmin:*wildcard permission, unconditionally.AuthContext.HasPermission(internal/auth/types.go) already enforced this carve-out via theadminCarvedOutsmap, falling through to the explicit-permission check for those three verbs instead of short-circuiting onadmin:*. The bearer-session path (permissionsAllow) never got the same treatment, so the two authorization paths disagreed: a bare Administrators-group member (no explicit Purchaser-group grant) was correctly deniedexecute:purchasesviaAuthContext.HasPermissionbut incorrectly allowed it viaService.HasPermission/permissionsAllow.Fix
Wire
permissionsAllowthrough the sameadminCarvedOutsmap so it mirrorsAuthContext.HasPermission's logic exactly:admin:*still short-circuits to allow for everything except the three carved-out verbs, for which it falls through to the explicit-permission check below (fails closed, never defaults to allow).Also updates
TestGroupOnlyAuthz_AdminEquivalence, a pre-existing test that asserted the old (buggy) behavior — that a bare admin holdsexecute:purchasesandapprove-any:purchases— to assert the correct carve-out semantics instead, consistent withTestAdminWildcardCarveOutsintypes_test.go.Note on issue linkage
This PR was scoped as closing "#1454", but verification shows GitHub #1454 is an already-merged, unrelated PR (
fix(api): gate empty-account history rows on ownership + enforce API-key constraints on money paths). No open issue matching this specific bearer-session/AuthContext inconsistency was found in a search of open issues or the adversarial-review tracker (#1448). Flagging this so the correct tracking issue can be confirmed or filed; not claiming a closing reference here to avoid a false link.Test plan
go build ./...cleango vet ./...cleango test ./internal/auth/...— 603 passedgo test ./...(full repo) — 5900 passed, 38 packagesinternal/auth/...— 0 issuesgocyclo -over 10on changed files — cleanTestService_HasPermission/admin-only_user_is_denied_the_carved-out_purchase_verb,TestService_HasPermissionForConstraintsAPI/admin-only_user_is_denied_execute:purchases...,TestGroupOnlyAuthz_AdminEquivalence) confirmed to fail against the pre-fix code and pass after restoring the fix