Commit 91ea013
committed
refactor: migrate Casbin to in-memory enforcer with database-stored token policies
Refactored the authorization system to improve performance and simplify architecture by moving from database-stored Casbin policies to an in-memory enforcer for role-based access control while storing API token policies directly in the database.
Benefits:
- Improved performance by eliminating database queries for role policy lookups
- Simplified architecture with clear separation between user RBAC and token ACL
- Reduced infrastructure dependencies by removing PostgreSQL adapter requirement
- More flexible token permissions management stored alongside token metadata
- Easier to reason about authorization flow with explicit dual enforcement model
Technical changes:
- Casbin now uses in-memory adapter for static role policies
- API token ACL policies stored in new policies JSONB field
- Added EnforceWithPolicies method for token-based authorization
- Migration populates existing tokens with default policies
- Updated middleware to route users and tokens to appropriate enforcement methods
- Removed database adapter dependencies and related sync logic
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>1 parent ed2e74b commit 91ea013
3 files changed
Lines changed: 218 additions & 0 deletions
File tree
- app/controlplane/pkg
- authz/middleware
- data/ent/migrate/migrations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments