feat: enforce PAT scope on permission checks#1446
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR introduces PAT (Personal Access Token) scope-checking support into the authorization flow. It extends the server dependency wiring to pass Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
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 |
Pull Request Test Coverage Report for Build 22948289905Details
💛 - Coveralls |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
core/resource/service_test.go (1)
159-200: Add explicit PAT lookup failure-path coverage.Please add a case where PAT scope is allowed but
patSvc.GetByIDreturns an error, soCheckAuthzerror propagation fromresolvePATUseris locked by tests.core/resource/service.go (1)
322-348: Defer user-subject resolution until after scope filtering in batch path.
buildBatchRelationsresolves subjects for all checks up front. For explicit PAT subjects, this can trigger unnecessaryGetByIDcalls for checks that are later scope-denied.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a9b92753-7be8-4c79-8833-15efa96866a5
📒 Files selected for processing (16)
cmd/serve.gocore/authenticate/mocks/authenticator_func.gocore/resource/mocks/authn_service.gocore/resource/mocks/config_repository.gocore/resource/mocks/org_service.gocore/resource/mocks/pat_service.gocore/resource/mocks/project_service.gocore/resource/mocks/relation_service.gocore/resource/mocks/repository.gocore/resource/service.gocore/resource/service_test.gocore/userpat/mocks/repository.gocore/userpat/service.gocore/userpat/userpat.gointernal/store/postgres/userpat_repository.gotest/e2e/regression/pat_test.go
Description
When a request is authenticated with a Personal Access Token, permission checks now verify that the PAT's assigned roles cover the requested permission before checking the user's own permissions. This applies to:
CheckResourcePermission)BatchCheckPermission)IsAuthorized)CheckFederatedResourcePermission) where the subject is an explicit app/pat principal.Changes
CheckAuthzthat runs before the user permission check. If the PAT scope denies the permission, the request is rejected without querying user permissions.BatchCheckthat batch-checks scope for all items first, then only runs user permission checks for scope-allowed items.GetByIDto PAT repository and service for resolving explicit PAT subjects in federated checks.cmd/serve.go.Tests
CheckResourcePermission,BatchCheckPermission,IsAuthorizedandCheckFederatedResourcePermission.core/resource/service_test.gocovering: non-PAT check, PAT scope allowed, PAT scope denied, PAT scope allowed but user denied, explicit PAT subject allowed, explicit PAT subject denied, batch check with PAT scope allowed, batch check with PAT scope denied.test/e2e/regression/pat_test.gocovering six scenarios: org viewer + scoped project viewer, org owner with inherited project access, org viewer + all projects, billing manager role, interceptor enforcement returning PermissionDenied, and federated check with explicit PAT subject. All 26 sub-tests pass against real Postgres and SpiceDB.