-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor validate token create #97
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
Conversation
4fb2f1e to
2e0f8a7
Compare
a528a98 to
513a287
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #97 +/- ##
==========================================
- Coverage 69.20% 68.86% -0.35%
==========================================
Files 113 113
Lines 9629 9626 -3
==========================================
- Hits 6664 6629 -35
- Misses 2259 2297 +38
+ Partials 706 700 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
513a287 to
b71fa70
Compare
b71fa70 to
bdb3139
Compare
bdb3139 to
897e95e
Compare
…into refactor-validate-token-create
|
Error messages look good. One thing I'm still missing is the information which tenant or project some requested role is not allowed for. E.g. if I request editor role for two projects and it's denied for one of them, I'd like to know which one. |
This would be possible if we also add the deniedSubjects to the list of errors instead of returning early after the deniedRoles are found. |
Yes, maybe as a map role -> project/tenant. |
Will try |
| }, | ||
| wantErr: true, | ||
| wantErrMessage: `permission_denied: requested project: "00000000-0000-0000-0000-000000000000" is not allowed`, | ||
| wantErrMessage: `permission_denied: requested roles: [PROJECT_ROLE_EDITOR] are not allowed with your current token`, |
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.
Maybe to make it clearer that the permissions are actually compared with the permissions from the database and not the contents of the requesting token?
| wantErrMessage: `permission_denied: requested roles: [PROJECT_ROLE_EDITOR] are not allowed with your current token`, | |
| wantErrMessage: `permission_denied: requested roles: [PROJECT_ROLE_EDITOR] are not allowed with your current user permissions`, |
pkg/service/token/token-service.go
Outdated
| } | ||
| // Now calculate meaningful error messages. | ||
| // First map the denied methods to roles which could access these methods. | ||
| for _, method := range deniedMethods { |
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.
I am not sure if we should attempt to map permissions back to roles. 😅
- This function would look really simple without the "reverse lookup". For this package I think it's beneficial that the code strives to be as simple as it gets.
- An early return with the first found problem is resource-efficient and it should be enough for a user to figure out the problem with his request quite quickly. I assume 90% of the use-cases are not as complex and people want to create an API token for a specific project for example. When you have a UI, this will not even show invalid input parameters for the requests. For CLI or CI scenarios, when it says "MachineCreate is not allowed on project-a with your current user permissions" it should be pretty clear what needs to be done by the user. Having the correct role probably resolves all the other problems that this function would return. Of course, there can be more complex scenarios but I don't think it will be incredibly time-consuming for a user to identify and resolve the problems even if you do not present him with the complete information.
- I hope that at some point we have dynamic roles (e.g. a role that's called "metal-core" and has a set of methods that comes with it). The static roles that come from the API definitions are not enough in this case and this introduces another place that needs to be adapted when implementing this feature.
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.
Agreed.
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.
Simplified, shift responsibility back to the user which wants to create/update a token for the sake of much simpler validation logic.
Description
Use tokenpermissions to validate the token create/update/refresh call.