Repository navigation
Description
Before reporting an issue
- I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
Area
admin/fine-grained-permissions
Describe the bug
I was testing how I can solve the following task using the FGAP v2 mechanism and spotted that having policies of different types leads to incorrect logic in evaluation.
The task is to give particular users the ability to see and manage only a particular client and be able to map roles of that client to other users in the realm without the ability to edit them.
First, I created a user policy and 2 permissions (of users and clients types). Before I added any other policies it worked fine. Users added to this policy were able to see, manage and map-roles of their client to other users. I tested it by myself. Needless to say that users who were added to this policy had the query-clients and query-users roles. Here are the screenshots of the policy and permissions settings:
Then I added the role policy and 2 permissions again. Here are the screenshots of the settings:
After that if I log as users from user or roly policy I'm not able to map roles anymore. Other scopes work fine, I still can see and manage only the selected client and view all users in the realm. However, no matter what I'm trying to assign, client or realm roles it says that there are no roles to assign. See the attached screenshot. (Btw, the text is incorrect in case you're trying to assign the client role since it's the same as if were trying to assing the realm role, I highlighted it.)
We debugged it and it looks like that if there's a user policy it will be evaluated first as a top logic in the hierarchy of the policy model. So instead of applying only one policy when a particular users accesses a particluar object, Keycloak checks all the exisiting policies by every level: user, role, group and because of that neither user nor role policy works correctly. If I delete any of the created policies the remaining one will work correctly.
Also, the evaluation mechanism lies in case I'm checking what scopes my test users have. For example, my user with the role "roles-manager" of the "artest" client can see and manage its client, however, the evaluation mechanism says the opposite.
The same situation is with other scopes. What can be the reason for this?
Version
26.3.3
Regression
- The issue is a regression
Expected behavior
Having several policies of different types doesn't cause errors in evaluation.
Actual behavior
Having only one policy doesn't cause any errors. In case policies of different types are added, the evaluation mechanism incorrectly evaluates accesses.
How to Reproduce?
- Upgrade from 26.0.5 to 26.3.3.
- Enable the FGAP v2 mechanism.
- First create only one policy, e.g., a user or role policy as described above.
- Check that everything works fine, all the scopes correctly function.
- Add a policy of another type and check the accesses again. Some scopes will stop working, e.g., as it was with my tests when map-roles and map-roles-composite scopes stopped functioning.
Anything else?
No response
Activity
pedroigor commentedon Sep 23, 2025
@yumaks24 Do the users have the role set in the role policy?
yumaks24 commentedon Sep 23, 2025
Basically, I have 3 test users. 2 of them (yumaks2 and yumaks4) don't have the "roles-manager" role associated with the role policy since they are mentioned in the user policy. But the remaining one (yumaks3, see the screenshot below) has the "roles-manager" role.
24 remaining items
yumaks24 commentedon Oct 8, 2025
@pedroigor thank you, this setup works for me! I also adjusted several things for my convenience and so far everything looks good. But why didn't my setup work? Also, is it a bug that you need to create separate user permissions with the "view" and "map-roles" scopes however it could be just one permission? It looks a bit more complicated than it could be, wdyt?
pedroigor commentedon Oct 8, 2025
I think it was because you have the policies conflicting with each other when using a single permission. Or perhaps because the permissions you created were conflicting with each other. Not sure. It would be better to ask you for the realm config, similar to what I did, since the beginning.
Not a bug, but I agree we might have a UX issue here. If you had issues doing that by yourself, is because we should improve to make things easier.
You can have a single
Userstype permission with bothviewandmap-rolesscope, they share the same constraint/policy.keycloak-github-bot commentedon Oct 8, 2025
Thanks for reporting this issue. However, after review this is not considered a valid issue, or has been recently resolved.
As the issue is not valid it will be automatically closed.