-
-
Notifications
You must be signed in to change notification settings - Fork 61
refactor(server)!: cleanup authorization boilerplate #199
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
57dd3ed
to
310cdca
Compare
feel free to close PR if you don't find it useful |
Definitely sounds/looks useful! I can review the code tomorrow. One thing to note here, you can add fixture tests to test the new behavior. |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #199 +/- ##
==========================================
- Coverage 70.23% 70.16% -0.08%
==========================================
Files 11 11
Lines 598 610 +12
==========================================
+ Hits 420 428 +8
- Misses 178 182 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks for the reference! I took a look at fixtures and think it makes sense to add new fixtures for not-exposed endpoints ( Otherwise I have mostly kept the behavior and there is coverage of the main cases. Except probably one more case, which hasn’t been covered before: if There are unit tests ofc, but I’ll add fixtures a bit later for all these cases! |
I think it makes sense. We can mention this in the changelog as breaking.
The intention was to require tokens to delete files on the server. Do you think we should change that?
Yeah, this is intended. Do you think we should have an empty list of tokens for allowing access? It is not a big deal imo.
I saw a derive macro on the endpoints that we want to protect but can you tell me how that works? Also it would be nice to get some information in terms of which version of Actix do you support, what are the plans for the future (will there be any breaking changes) etc.
Great! Just let me know if you have problems / need guidance while adding them. |
Not sure, the main confusion is that we have So I think we can keep it as is, probably improve the documentation related to the
I thought more about explicit configuration flag, like
Actually it works pretty straightforward:
async fn endpoint(details: AuthDetails) -> HttpResponse {
if details.has_authority(TokenType::Auth) {
// body of our function
} else {
// error we want to see, defaults to `Forbidden`
}
} But we can write it manually as well
Recently I've delivered a huge update and I'd say it's likely long-term vision of API. As part of that update I also switched to Current macro-syntax flexible enough and should fit a lot of cases, including ABAC & RBAC, for example, you can combine the conditions in Rust-friendly way, using // snippet from examples
#[actix_web_grants::protect(any("ADMIN", expr = "user.is_super_user()"), ty = "Role")]
async fn admin_or_super_user(user_id: web::Path<i32>, user: web::Data<User>) -> HttpResponse {
HttpResponse::Ok().body("some secured response")
} So I don't expect the breaking changes in the near future, and if they would be - it will be major (semver) update without breaking existing applications, and with back-porting the changes if they're compatible & makes sense. |
I've added fixtures, it looks pretty clear to me, thanks! Some not related observations:
I think would be nice to ensure it works on any platform, or provide fast way to run it with docker for example. |
Makes sense - would you be interested in making a PR to update README.md about this?
👍🏼
Thanks for the explanation! It is more clear now.
Aye that's me! Let me know if you need help with any configuration.
Wow that's nice!
Alright, sounds good. |
LGTM! Just one last thing. I usually put the user-facing changes in the changelog so I guess the only things that have changed are:
Do we need to mention something else in the changelog? |
In that case I think these two are enough, I'll update the changelog entry |
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.
Thanks!
Description
404
instead of403
(they literally not intended to be exposed) - the only breaking change, can be extracted to separate PRHashSet
instead ofVec
to check tokensactix-web-grants
to protect endpointsErrorHandlers
to log unauthorized errors instead of in-placehost
handling & etcMotivation and Context
I came across
rustypaste
and decided to check the code a little & play locally with it. As a result, some of the authorization rules were not obvious to me. For example:delete_tokens
- hides the endpointauth_tokens
- allows the access (btw, is it intended? because sound like a bug)So I decided to do a little refactoring, which I hope you find useful.
Another part of the changes is the introduction of actix-web-grants - this is a small but quite flexible library, with which it will also be easy to change the rules, for example, switch to RBAC/ABAC or something else (actually I'm maintainer of the library, so it's may be subjective)
How Has This Been Tested?
Mostly by current test-coverage, I kept the same behavior, except
403
->404
Changelog Entry
Types of Changes
Checklist: