Skip to content

Having policies of different types leads to incorrect evaluation #42830

Closed as not planned

Description

@yumaks24

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:

Image Image Image

Then I added the role policy and 2 permissions again. Here are the screenshots of the settings:

Image Image Image

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.)

Image

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.

Image Image

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?

  1. Upgrade from 26.0.5 to 26.3.3.
  2. Enable the FGAP v2 mechanism.
  3. First create only one policy, e.g., a user or role policy as described above.
  4. Check that everything works fine, all the scopes correctly function.
  5. 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

  1. added
    kind/bug
    on Sep 22, 2025
  2. added
    area/admin/fine-grained-permissions
    on Sep 22, 2025
  3. pedroigor commented on Sep 23, 2025

    @pedroigor
    Contributor

    @yumaks24 Do the users have the role set in the role policy?

  4. self-assigned this
    on Sep 23, 2025
  5. yumaks24 commented on Sep 23, 2025

    @yumaks24
    Author

    @yumaks24 Do the users have the role set in the role policy?

    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.

    Image
  6. 24 remaining items

  7. yumaks24 commented on Oct 8, 2025

    @yumaks24
    Author

    @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?

  8. pedroigor commented on Oct 8, 2025

    @pedroigor
    Contributor

    But why didn't my setup work?

    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.

    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?

    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 Users type permission with both view and map-roles scope, they share the same constraint/policy.

  9. keycloak-github-bot commented on Oct 8, 2025

    @keycloak-github-bot

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/admin/fine-grained-permissionskind/bugteam/core-iam

Type

Fields

No fields configured for bug.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions