fix(authZ): extract enforcer logic#2553
Merged
migmartri merged 6 commits intochainloop-dev:mainfrom Nov 17, 2025
Merged
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>
migmartri
commented
Nov 15, 2025
| @@ -0,0 +1,86 @@ | |||
| // | |||
| // Copyright 2025 The Chainloop Authors. | |||
Member
Author
There was a problem hiding this comment.
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>
Member
Author
|
@jiparis ptal at this PR, it fixes an important bug |
jiparis
reviewed
Nov 17, 2025
jiparis
reviewed
Nov 17, 2025
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
jiparis
approved these changes
Nov 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.