Advanced Claim to Group Mapper resolves group by path rather than ID
See original GitHub issueDescribe the bug
#8467 implemented an OIDC provider mapper along with the frontend logic necessary for selecting a group. However, it stores the group reference as a serialized path rather than by an ID. This is problematic because group names are neither stable nor unique.
Version
17.0.1
Expected behavior
The mapper should store a group by its ID and continue to function after a group is renamed. This aligns with how Group polices are stored and evaluated.
Actual behavior
The user is assigned to the first occurrence of a group with a matching name, and error is thrown when the group is renamed or moved somewhere else in the hierarchy.
There’s additionally an unintentional null pointer exception due to an additional bug where the IdentityBrokerException
should be thrown:
https://github.com/keycloak/keycloak/blob/bde274465096bf04e65ec07a21fdea7b73efe921/services/src/main/java/org/keycloak/broker/oidc/mappers/AbstractClaimToGroupMapper.java#L83-L85
How to Reproduce?
No response
Anything else?
It seems like groups are only ever resolved by path when importing groups externally, i.e. where the external name informs the name of the group on Keycloak. Since this mapper explicitly configures a target group from a picker UI, I don’t think this behavior is appropriate.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Hi,
one of our customers also stumpled upon this issue.
Their main problem is that the login fails when the group does not (no longer) exist. Furthermore, they would like to have the following behavior when a group is changed in a way affecting the mapper:
I see the following options to address this issue:
Option 1)
Just change the mapper that it doesn’t fail the login anymore - just log a warning or an error instead. This could be done a) in every case, or b) just when it is configured by means of an additional config option “proceedOnFailure”.
Option 2)
In addition to 1), change the group reference of the mapper to a group ID instead of a group path. In this case, it would be nice to adjust the mapper UI so that the group path is shown in addition to the group ID.
Option 3)
Also includes 1), but in contrast to 2), the group reference remains to be “group path”. In order to handle the move and renaming of groups, a new GroupPathChangeEvent (or even more generic GroupChangeEvent) is introduced, which will be triggered in case of a corresponding group change. (This event interface could be added to org.keycloak.models.GroupModel, there is already a GroupRemovedEvent.) An event handler, which changes the affected mapper data, would be registered (once for all mapper instances) in AbstractClaimToGroupMapper#postInit - or does someone suggest a more appropriate place?
Maybe someone else suggests an additional option?
Regardless of the chosen option, it makes sense to adjust the ClaimToRoleMapper and AdvancedClaimToRoleMapper to behave in a symmetric way.
What do you think (especially the maintainers)?
@mposolda Thanks for your response. I will update the PR in the next days.