quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.79k stars 2.68k forks source link

Add support for Roles with permissions #12219

Closed smsajid closed 1 year ago

smsajid commented 4 years ago

Description Quarkus currently supports only role based security check. Need a mechanism to add permissions to roles and allow security check with permissions as well. A role can have permissions 'perm1', 'perm2', etc. Permissions can be dynamically added to roles. This allows more flexibility in security implementation and roles can be dynamically created by application.

Similar to @RolesAllowed, add annotation @PermissionsAllowed and other config based security settings.

sberyozkin commented 4 years ago

@smsajid is it related, #10988 ? Please also prototype some example (some test token content, etc) so that it become more obvious what your proposal is about

smsajid commented 4 years ago

Yea, looks like #10988 is similar proposal. I searched for an existing proposal to comment on. Wondering how I missed this. My proposal is inspired by http://shiro.apache.org/authorization.html as I have worked with shiro before and found it very powerful.

MarcusBiel commented 3 years ago

Any news here? PING.

drubio-tlnd commented 3 years ago

Any update on this topic ? I did something similar in order to check entitlements, authorities etc. as it's done with @RolesAllowed with a custom interceptor but this could be a useful feature

MarcusBiel commented 3 years ago

The issue is now over one year old (taking into account the original ticket I used to report it). Still no update?

mklueh commented 2 years ago

Hi ✌️

michalvavrik commented 1 year ago

I found this issue while doing research on #10988 - I suggest that I impl. #10988 and give config option to link role with permissions. Everyone fine with that? ETA: end of January

sberyozkin commented 1 year ago

@michalvavrik Hi Michal, I've asked for the clarification in #10988

michalvavrik commented 1 year ago

Hi @sberyozkin ,

re https://github.com/quarkusio/quarkus/pull/31345#issuecomment-1469750220, I re-read your comments, most importantly this one https://github.com/quarkusio/quarkus/issues/10988#issuecomment-1371145067. It is clear that we can map roles to permissions on HTTP security policy level, but this configuration is exclusively used for path matching HTTP security policy. As you know, path matching security policy is applied before JAX-RS layer comes into action, therefore any role/permission set via this configuration properties won't ever be checked by the security annotations like @RolesAllowed or @PermissionsAllowed.

If path is secured for certain role, and the role has permissions, than there is no point using the annotation on resource method as the security check will be successful in 100 %. Can you give me a quick hint how are users going to use such a link? You don't need to go to the details of solution, just a line that shows me a way.

Thank you

michalvavrik commented 1 year ago

Now that I'm working on it, I also mentioned second important reason why it should be part of the Quarkus Security. Most of Auth config is now moving to the runtime (fingers crossed - https://github.com/quarkusio/quarkus/pull/31800), adding this mapping to the vertx-http extension means I either have to add security identity agumentor even when there is no mapping, or make this mapping build time only. While if I put it to the Security extension, I could make IdentityProviderManagerCreator synthetic bean and only add this buildin permission agumentor only when needed. Sure, there are other patterns, but still would be most elegant.

sberyozkin commented 1 year ago

@michalvavrik

As you know, path matching security policy is applied before JAX-RS layer comes into action, therefore any role/permission set via this configuration properties won't ever be checked by the security annotations like @RolesAllowed or @PermissionsAllowed.

Sure so the same way RBAC can be enforced at the HTTP security policy level without using @RolesAllowed we'd enforce the permission based access control without @PermissionAllowed, so when, in the HTTP security policy, its role mapping config, we say this or that role implies this or that permission then it will activate the permission check implicitly.

What do you think ? HttpSecurityPolicy is there to let users avoid relying on the annotation but setting everything in the configuration, kind of similar to the keycloak authorization approach where you set the scopes in the configuration and it just worked without PermissionAllowed

michalvavrik commented 1 year ago

Alright @sberyozkin , that's perfectly fine solution. I completely misunderstood you previously. Thanks!

michalvavrik commented 1 year ago

Actually, now that I think about it, it makes perfect sense.

sberyozkin commented 1 year ago

Thanks @michalvavrik, indeed, if someone chooses using PermissionAllowed then they can use the current approach, with SecurityIdentityAugmentor, but with the policy configuration, they can do the annotation free control by associating roles with permissions.

But I wonder, should HttpSecuriry Policy configuration also allow specifying permissions only without mapping them to roles. For example, AuthConfig#Map<String, PolicyConfig> rolePolicy which allows linking specific policies to specific roles and I suppose it is in PolicyConfig where we will map roles to permissions.

But lets say we use OIDC and HTTP securitty policy config and the policy is authenticated (no RBAC) and OIDC maps a token scope claim to String Permissions. That means we might also (additionally) need to have AuthConfig#Map<String, PermissionConfig> permissionPolicy which in this case will link authenticated policy with a set of permissions, perhaps I can look into this specific update as part of the OIDC enhancement after you finish with this issue

michalvavrik commented 1 year ago

I'm going in the similar direction (basically I just put everything into PolicyConfig), but I'll open PR in next days and we can discuss it there. It is always easier to describe what is wrong/what should change than to design something from scratch. Glad we see it roughly similar, thanks @sberyozkin .

michalvavrik commented 1 year ago

@sberyozkin I iterated into this (still coding, no PR):

Please feel free to suggest changes, raise your objections, whatever :-)