-
Notifications
You must be signed in to change notification settings - Fork 44
fix(authZ): extract enforcer logic #2553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(authZ): extract enforcer logic #2553
Conversation
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
| @@ -0,0 +1,86 @@ | |||
| // | |||
| // Copyright 2025 The Chainloop Authors. | |||
There was a problem hiding this comment.
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>
|
@jiparis ptal at this PR, it fixes an important bug |
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
This PR fixes #2551 by refactoring the
Enforcermethod to make sure it is always used in all parts of the application, not just the middleware.