Skip to content

LDAP User Federation

User federation lets Keycloak read (and optionally write) user accounts from an external store instead of its own internal database. The most common store is LDAP (Lightweight Directory Access Protocol), which is the protocol used by:

  • OpenLDAP — the open-source LDAP server.
  • Microsoft Active Directory (AD) — the enterprise directory service found in most corporate networks.
  • Apache Directory Server, 389 Directory Server, and others.

When a user tries to log in, Keycloak looks them up in the LDAP directory and delegates the password check to the LDAP bind. From the user’s perspective, they are just logging in with their normal directory credentials.

  1. In the admin console, make sure you are in the correct realm.
  2. Click User federation in the left sidebar.
  3. Click Add provider and select LDAP.
  4. Keycloak displays the LDAP configuration form.

Fill in the connection details:

FieldWhat to enter
VendorSelect Active Directory for AD, or Other for OpenLDAP. This pre-fills sensible defaults for DN structures and attributes.
Connection URLThe LDAP server URI, e.g., ldap://ldap.example.com:389 or ldaps://ldap.example.com:636 (LDAPS for encrypted).
Enable StartTLSPreferred alternative to LDAPS for encrypting the connection on port 389.
Connection poolingEnable in production to reuse LDAP connections.

Click Test connection to verify Keycloak can reach the server before continuing.

Keycloak needs a service account to search the directory. This is called the bind DN.

FieldWhat to enter
Bind typesimple for username/password bind.
Bind DNThe distinguished name of the service account, e.g., cn=keycloak-svc,ou=service-accounts,dc=example,dc=com.
Bind credentialsThe service account password. Store this in a Keycloak vault or environment variable — never hardcode it.

Click Test authentication to verify the bind credentials work.

FieldWhat to enter
Users DNThe base DN to search for users, e.g., ou=users,dc=example,dc=com.
Username LDAP attributeThe LDAP attribute that maps to the Keycloak username. For AD use sAMAccountName; for OpenLDAP use uid.
RDN LDAP attributeUsually cn or the same as the username attribute.
UUID LDAP attributeFor AD: objectGUID. For OpenLDAP: entryUUID. This is used as Keycloak’s internal user ID.
User object classesFor AD: person, organizationalPerson, user. For OpenLDAP: inetOrgPerson, organizationalPerson.

These two settings define how Keycloak synchronises users and whether it writes back to LDAP.

READ_ONLY — Keycloak cannot modify any LDAP attributes. Password changes are rejected. Use for corporate AD where Keycloak should not touch the directory.
WRITABLE — Keycloak can update LDAP attributes and sync password changes back to LDAP. Use only if Keycloak is authorised to write to the directory.
UNSYNCED — Keycloak stores attribute changes locally (in its own DB) without writing to LDAP.
# Recommended default for most deployments
Edit mode: READ_ONLY
  • On (default) — Keycloak imports user records into its local database on first login and after each sync. Queries are fast because they hit the local DB.
  • Off — Keycloak queries LDAP on every login. Less data stored locally, but every authentication hits the LDAP server.
  1. Click Save.
  2. Back on the User federation page, open your LDAP provider.
  3. Scroll down to the Synchronization section.
  4. Click Synchronize all users to do an immediate full sync, or configure Changed users sync to run periodically.

After the sync, go to Users in the left sidebar. You should see your LDAP users listed with a “federated” badge.

What LDAP attribute should you use as the username for Active Directory?
What does LDAP edit mode READ_ONLY mean?
What is the purpose of the bind DN in LDAP federation?
When "Import users" is turned off, what happens on every login?