8000 Automatic Update of Ldap groups and Ldap group memberships during periodic sync · Issue #9609 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Automatic Update of Ldap groups and Ldap group memberships during periodic sync #9609

Description

@mposolda

Description

Updating groups and group memberships during periodic sync (or during manually triggered sync of the users) is not yet available in current Keycloak.

This is preventing from having Group synchronization working fine and fully supported between Keycloak and LDAP instance.

Discussion

No response

Motivation

Migrated from https://issues.redhat.com/browse/KEYCLOAK-19574

Details

Hopefully new store will help with having syncing of groups properly implemented as "Group Storage" .

Still the sync of groups and roles can have performance impact. Hence I think it will be good to keep the current behaviour by default (EG. sync users configured at the LDAP provider does NOT sync groups/roles from LDAP).

Also due the performance impact, I can imagine that customer may want to use different intervals for syncing users and for syncing groups/roles (EG. Sync users once per day, but sync groups/roles from LDAP once per week). So it will be good to have a way to configure for each group/role mapper separately how periodic sync should work (full sync VS sync only changed objects) . So I think will be good to have the options like

  • Periodic Full Sync
  • Full Sync Period
  • Periodic Changed Groups (Roles) Sync
  • Changed Groups (Roles) Sync Period available also for groups/roles.

If we still have mappers with the new store, it will be good to address this for both LDAP group mapper and LDAP role mapper (I understand we may have customer, who want only groups, but will be nice to address this also for roles, which are very similar and will be nice to have this consistent for both roles and groups).

Activity

  1. added
    area/storageStorage layer — JPA entities, database schemas, Liquibase migrations, caching
    and removed on Jan 20, 2022
  2. VGerris commented on Mar 3, 2022

    @VGerris

    I would like to add that the current implementation also seems to act upon the group settings when syncing users : when groups are added in Keycloak and the group mapping has 'Drop non-existing groups during sync' enabled, the groups never end up in LDAP and are also removed from Keycloak. So using Keycloak as the single point for users AND group management with an LDAP backend is not possible. If the option is disabled, groups removed in LDAP will not be removed in Keycloak, so currently one needs to choose between those.
    When wanting LDAP to be authorative ( my assumption ) the setting has to be enabled and groups can only be created directly in LDAP, requiring an LDAP client.

    As a side note, it seems Keycloak sends to requests to the LDAP server when creating a user - not sure if this is related, but in a load balanced dual master setup this causes issues when the load balancer is not set to sticky sessions ( the second call being faster sometimes then the sync operation ).

    It would be a great benefit if that could be part of any effort to improve this.

  3. scila1996 commented on Mar 8, 2022

    @scila1996

    +1

  4. kresnasatya commented on Jun 20, 2022

    @kresnasatya

    I have the same problem with sync user group membership from Keycloak to LDAP. So, the current solution we do is save in two place: Keycloak (by Keycloak REST admin API) and LDAP query in different methods.

  5. SchneiderMK commented on Aug 31, 2022

    @SchneiderMK

    Having the same issue. Are there any updates, ETA?

  6. kikolouro commented on Sep 21, 2022

    @kikolouro

    Same issue here.

  7. robodrome commented on Sep 27, 2022

    @robodrome

    Same issue. The reason why I wanted to try out KeyCloak is to have one (easy) single point of user administration. Are we doing something wrong? Or is this a genuine bug/missing feature?

  8. plevart commented o 8000 n Jun 8, 2023

    @plevart

    Hi,

    Let me describe my observations of the behavior in the latest (21.1.1) Keycloak.

    We are trying to use Active Directory as a source for Users and Groups. We configured:

    • "Active Directory" as a LDAP vendor (provider)
    • UNSYNCED as Edit mode
    • Subtree as Search scope for users
    • Import users: ON
    • Sync Registrations: OFF
    • Batch size: 200
    • Pagination: ON

    We want users to be administered only in Active Directory and just want to propagate all their changes to Keycloak. This works. We synchronize ~15000 users this way and their data gets updated periodically.

    We also added one or two group-ldap-mapper mappers and configured them to synchronize a subset of groups from LDAP. The settings of such mapper are:

    • Preserve Group Inheritance: ON (we make sure groups that are synchronized don't have multiple inheritance)
    • Ignore Missing Groups: ON
    • Mode: READ_ONLY (we also tried with IMPORT which is "...Read-only LDAP mode where group mappings are retrieved from LDAP just at the time when user is imported from LDAP", but then we don't get updated memberships which is what this issue is all about, I think)
    • Drop non-existing groups during sync: ON

    So this seems to work, although to be totally sure, we need some more testing.

    One thing that doesn't work as expected is the following:

    We explicitly specified "Preserve Group Inheritance: ON" in group-ldap-mapper and we do get groups in a (single inheritance) hierarchy from LDAP properly connected in Keycloak, but user group memberships are nevertheless flattened, meaning if we have group A and a child group B, then when there is a user U that is a member of group B in LDAP, this user becomes member of group B in Keycloak and of group A in Keycloak. This is unnecessary flattening of memberships which is perhaps necessary when the group-ldap-mapper specifies "Preserve Group Inheritance: OFF", but in case this is ON, should not be happening.

    Above striked-out claim might be unfounded. I was mislead by the "Members" tab on the Groups display. When a particular Group is selected on the left-side tree-like browser, the list of group Members on the Members tab is shown and that list includes, as the last column, Membership - display of all Groups a particular user is member of. That list seems to include transitive Memberships. The list of users does not include users that are transitive members of selected group unless "Include sub-group users" checkbox is checked.

    OTOH, when watching the details view for a particular User, the "Groups" tab shows groups where that user is direct member and also some (but not all) groups where it is a transitive member of. When the "Direct membership" checkbox is unchecked, the list shows all groups the user is transitive member of. So these two views (direct User members of a Group vs. direct Group membership of a User) are at least inconsistent.

  9. wrathinmind commented on Mar 15, 2024

    @wrathinmind

    same issue
    Keycloak 22.0.5
    JVM: 17.0.6 (Red Hat, Inc. OpenJDK 64-Bit Server VM 17.0.6+10-LTS)
    OS: Linux 5.14.0-381.el9.x86_64 amd64

  10. oculos commented on May 30, 2024

    @oculos

    Is there any traction on this? I feel that due the lack of a proper group sync, deleting a group on keycloak does not delete it in ldap, so the group will always reappear.

  11. tsaarni commented on Sep 10, 2024

    @tsaarni
    Contributor

    @mposolda I'm curious what is missing from groups periodic sync in detail?

    When I configure periodic sync (whether it's full sync or sync of changed users), it seems that in addition to syncing users, there is also a call to LDAPStorageProviderFactory.syncMappers(). This triggers calls to either GroupLDAPStorageMapper.syncDataFromFederationProviderToKeycloak() or RoleLDAPStorageMapper.syncDataFromFederationProviderToKeycloak(), depending on which mapper is in use.

    I notice that a search is performed on the LDAP server, and groups or role mappings appear to be updated.

  12. pedroigor commented on Dec 20, 2024

    @pedroigor
    Contributor

    Looks like we have two different issues here?

    Do you agree? Asking because we might want to work on them separately because the second one has been being discussed in the past with some attempts to fix the problem. For instance, #29206.

  13. removed
    kind/featureCategorizes a PR related to a new feature
    on Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/storageStorage layer — JPA entities, database schemas, Liquibase migrations, cachingkind/enhancementCategorizes a PR related to an enhancementteam/core-iam

    Fields

    Value

    None yet

    Effort

    None yet

    Votes

    18

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0