-
Notifications
You must be signed in to change notification settings - Fork 18
Update SecurityIdentity to list owned Permissions and allow simpler permission checks #57
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
base: main
Are you sure you want to change the base?
Update SecurityIdentity to list owned Permissions and allow simpler permission checks #57
Conversation
…permission checks
michalvavrik
left a comment
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 kinda said it all in my comments in quarkusio/quarkus#43717. I can't think of anything else to comment here.
FWIW idea to add addPermission to the QuarkusSecurityIdentity.Builder is brilliant.
src/main/java/io/quarkus/security/identity/SecurityIdentity.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Michal Vavřík <43821672+michalvavrik@users.noreply.github.com>
FroMage
left a comment
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.
Seems like a good idea.
|
@michalvavrik Michal, I've totally missed Steph approved, what should we do here, I'm assuming you are OK with keeping a method allowing to list current permissions. I can drop the methods for checking them, it can be done later, but indeed, letting users list posessed permissions seems useful, similarly to what users can do with |
Honestly, I am still worried that users will consider following interchangeable: (it's metacode, don't take it literately please). Because that is what we ourselves do in Quarkus, we mostly (if not always) use If you said in the |
|
Sorry Michal, I did not quite get your concern about the interchangeable code above, it does look interchangeable to me or did I miss something ? |
I don't know, it quite hard for me to explain it because I am not sure where we disagree. I can try again, I hope I am not repeating myself and it is useful: is not interchangeable because you can do for example this: If users or Quarkus or Quarkiverse extensions add these checkers, they are not |
|
Thanks @michalvavrik I'll think about your comment and reply a bit later, this PR is not essential for the next release |
So, like I said before, Just because a permission checker method exists, it does not mean we should not allow users check what permissions the identity owns. We have users like the one in #quarkusio/quarkus#50827 (reply in thread) who are trying to workaround the fact they can't get a list of owned Permissions which is not a good experience.
Your example, may or may not produce the same output, the list of permissions is just a list of permissions, we don't give any guarantees that iterating over them must produce the same result that some extension's permission checker returns, in scope of that extension checking permissions can mean an entirely different thing to what it means in scope of user's code. So, I don't really see why users must not use permissions just because some other part of the system registers a permission checker.
IMHO there is no risk, but what I can do is I can add a note to highlight your point, that checking |
|
I think we are going in the circle, my opinion didn't change even after reading your comments. All I am asking you to do is to update javadoc of Anyway, I agree that risk is small, my suggestions are about clarity. So I'd suggest that you rebase this PR on the current main and if you disagree, it can go in. Just get review of committers in addition to what I said. Thanks |
|
ad quarkusio/quarkus#50827 - I have no idea why it would be useful, it sounds to me like users want to do custom checks using our API. If they have their own permissions, they can store it as identity attributes. I don't know in which scenario their request makes a sense. |
michalvavrik
left a comment
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.
As everything was already said.
|
@michalvavrik Sure, I know I can merge as I have an approval from @FroMage , but it is important to me we reach some consensus. I believe you look at it from the functional point of view, why would someone want to have a look at the list of permissions if they can register a permission checker. But this is not equivalent in terms of the user experience at the Now, with roles, they can do Arguably, the permission checker registration should not have been added at all, as it brings the user element into a So like I said, because I appreciate your concern, I'll add a relevant note |
Permission checker in terms of the So what introduces link between There is nothing more to be said, I read your opinions and I respect them. Let's move on. |
|
According to API, roles needs to be resolved beforehand. But permissions checks are asynchronous, which helps us to perform non-blocking checks and you cannot do it with |
|
@michalvavrik Sorry, I know we kind of completed the discussion, but I missed
Sure, I mean, we already have the existing
Risk of exactly what ? And yes, I will clarify that
Again, you are talking about functional stuff, API needs to let users just to see a list of permissions. In fact they can do it now, for ex, if they were mapped from
Or with the PR: |
Risk that users believe that
I don't know enough about Keycloak Authorizer to recognize you are right :-) Just so that it is not lost in all the text: I think
Thank you for your patience. |
I'll make sure it is clearly stated that the former only works with registered permission checkers
Believe it or not, for simple cases, I found it, a few times, awkward having to register a function checker that does exactly what I can do with checking a permission directly - but this point brings a functional angle. So as suggested earlier, irrespective of how a permission is actually checked, a list of the identity permissions is just one of the properties of the SecurityIdentity instance - it can be useful to iterate over them not only for the purpose of checking them, but some metrics, etc. I'll let you know once I update the PR, appreciate your feedback. Thanks |
I believe you. I always look what I have done before.
Alright. |
The main purpose of this PR is to make it possible to simplify the way
@PermissionAllowedare enforced by default at the Quarkus level.At the Quarkus level, when no (recently introduced)
@PermissionCheckeris used, the only way for users to have@PermissionAllowedchecks enforced is basically do these checks themselves by registering a customSecurityidentityAugmentorand adding a custom permission checker function:For example (from the Quarkus docs):
Where the users need to correctly write the permission checker function making sure it is permission which is meant to be associated with the identity is used to call
implies, not the required one... And there is no way to check onSecurityIdentitywhich permissions it owns.@FroMage and @michalvavrik worked out a plan to make it easier to implement such functions, but IMHO users should be totally shielded from having to write such checkers. We do not ask users to manually write role checks, and we should not ask them to do it for permissions. They can do if they really want to, but it should be avoidable.
The above code should look like this:
And Quarkus Security will do the required checks itself, by checking
SecurityIdentity#getPermissions()added in this PR.See also quarkusio/quarkus#43717