Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 2 min read

When Keycloak's LDAP Sync Runs Past a User Deleted in the Directory

Keycloak 26.7.4: after a user was deleted in LDAP, the full sync reported "0 imported users, 2 updated users", the users count stayed 3, and the next admin search removed it with no admin event. When It Runs โ€” Run Repo

Keycloak 26.7.4: after a user was deleted in LDAP, the full sync reported "0 imported users, 2 updated users", the users count stayed 3, and the next admin search removed it with no admin event.

When It Runs โ€” Run Report #RR14 ยท Testing what infrastructure actually does.

Provider ยท Component: Keycloak ยท LDAP user federation with Import users on โ€” what happens in Keycloak's local database to a user who is deleted in LDAP: through a full and a changed-users sync, and when the user is next looked up, with "Remove invalid users during searches" at its default

Versions tested: measured โ€” Keycloak 26.7.4 (the latest release as of 2026-09-28; 26.7.5, 26.8.0, 26.8.1 and 26.8.2, released on 2026-09-30, 2026-10-01, 2026-10-13 and 2026-11-05, were not measured), a single version, against one LDAP server, 389 Directory Server 3.1 (the project's container image, digest-pinned). source-read โ€” the LDAP provider (LDAPStorageProviderFactory.java, LDAPStorageProvider.java), SynchronizationResult.java, UserStorageManager.java, UserStorageProviderModel.java and the admin console's LDAP pages at the same tag. The reports quoted below are from Keycloak 23.0.4 and 26.0.5 โ€” not measured.

Config profile: Keycloak 26.7.4 from the official image (digest-pinned) in development mode and 389 Directory Server 3.1, in containers on one Docker network on a dedicated test VM; two realms that differ in one setting โ€” "Remove invalid users during searches" left at its default (on) in rr14 and switched off in rr14-keep; in each, an LDAP provider (vendor Red Hat Directory Server, Import users on, edit mode READ_ONLY, periodic syncs off, syncs run by hand), the same three test users, admin events and user events saved, and a realm role held only in Keycloak; the log category org.keycloak.storage.UserStorageManager at DEBUG and everything else at INFO.

Verified on: 2026-11-14 (desk sources re-checked; Keycloak 26.8.2 was the latest release) ยท lab measured 2026-09-28 on Keycloak 26.7.4.

Affects: Keycloak 26.7.4 realms with LDAP federation, Import users on and "Remove invalid users during searches" at its default: a user deleted in LDAP stayed in Keycloak after a full and a changed-users sync, and was removed when next looked up, together with the realm role mapping it held only in Keycloak, with no admin event and no log line at the INFO level; with the option off, the user stayed, disabled.

TL;DR: On Keycloak 26.7.4 with LDAP federation, a user deleted in LDAP stayed in Keycloak through a full and a changed-users sync โ€” both sync results counted no removal โ€” and was removed only when an administrator next looked it up, with no admin event and no log line at the INFO level; with "Remove invalid users during searches" off, the user stayed, disabled.

Full report: https://whenitruns.substack.com/p/when-keycloaks-ldap-sync-runs-past

Reproduction repo: https://github.com/whenitruns/when-keycloaks-ldap-sync-runs-past-a-user-deleted-in-the-directory

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.