Skip to content

fix(authZ): extract enforcer logic#2553

Merged
migmartri merged 6 commits intochainloop-dev:mainfrom
migmartri:revisit-cas-backend-permissions
Nov 17, 2025
Merged

fix(authZ): extract enforcer logic#2553
migmartri merged 6 commits intochainloop-dev:mainfrom
migmartri:revisit-cas-backend-permissions

Conversation

@migmartri
Copy link
Member

This PR fixes #2551 by refactoring the Enforcer method to make sure it is always used in all parts of the application, not just the middleware.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
@migmartri migmartri requested review from javirln and jiparis November 15, 2025 23:23
@migmartri migmartri changed the title Revisit cas backend permissions fix(authZ): extract enforcer logic Nov 15, 2025
@@ -0,0 +1,86 @@
//
// Copyright 2025 The Chainloop Authors.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change.

It's basically a custom enforcer that knows not only about casbin but also about API-Tokens custom ACLs.

I created it in the biz layer since that way it can be used without the risk of package cycles.

I tried to do smth similar but by extending the current pkg/authz but that one is connected already referenced by both biz and data

Add comprehensive unit tests for the Enforce method in pkg/biz/authz.go
covering both API token and regular user authentication flows.

Test coverage includes:
- API token validation with invalid UUIDs
- Token not found scenarios
- Database error handling
- Policy matching (allowed/denied)
- Empty and nil policy handling
- Partial policy matches
- Multiple policy evaluation

Uses testify suite pattern with mocked APITokenRepo and real enforcer
instance for integration testing.

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev>
@migmartri
Copy link
Member Author

@jiparis ptal at this PR, it fixes an important bug

Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
@migmartri migmartri merged commit 9c9c55a into chainloop-dev:main Nov 17, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

the latest changes from casbin is causing API-tokens to fail in some operations

2 participants