Keycloak with multiple LDAP or Active Directory domains: what the integration does
If your organization now runs several directories, whether from an acquisition, separate Active Directory forests or a legacy domain nobody has retired, Keycloak's supported method is user federation with one LDAP or Active Directory provider per directory, all attached to the same realm. Each provider reads users from its own directory and presents them to applications through that single realm, so applications keep one login endpoint and one token issuer while the directories stay where they are. The Keycloak server administration guide documents LDAP and Active Directory user federation as this mechanism, and this integration should be designed only around the behavior that guide describes.
The work is not in creating the providers. It is in deciding how the realm resolves a user who could exist in more than one directory, which provider it asks first, and what happens when one directory cannot be reached. Provider priority sets the lookup order, so the first match wins. Two directories can hold the same username for different people, and the realm has no built-in answer for that, so you need an agreed rule for username collisions before you connect the second provider. Confirm with your Keycloak version how the admin console orders providers and how it reports a provider that fails during login, because those behaviors decide your outage and cutover plan.
Before you build, inventory each directory's user attributes, group model and which domain controllers or LDAP endpoints Keycloak can reach from its network segment. Ask the directory owners whether any account is shared across domains and whether a retired domain still has active accounts. The answers determine whether the realm needs a single lookup order, separate login paths per domain, or a migration of accounts before the old directory is switched off. Keycloak does not decide these questions for you, and an unplanned change to a provider can lock out users in every domain at once.
What you need before connecting a second directory
Connecting a second LDAP or Active Directory domain to Keycloak adds failure points that a single directory never exposed. The items below cover the Keycloak version, the database, directory credentials, transport security, network paths and attribute ownership, and each one should be settled on paper before the first federation provider is created.
Keycloak version and target release
Keycloak 26.8.1 is the current release, so start from it only if your upgrade plan allows. Confirm the target version with your own upgrade plan and test the federation setup on that exact version, since provider behavior and upgrade notes change between minor releases. Record the version in the change request so that later upgrades can be checked against the same provider configuration.
Keycloak upgrading guideSupported production database
Keycloak stores federation settings, mapped users and sessions in its database, and the dev-file database is for development only. Choose one of the supported production databases, such as PostgreSQL 14 to 18, and confirm the version your platform team operates. Both supported high availability designs need a synchronously replicated database, so check that before the directory work begins.
Keycloak database guideRead-only bind account per directory
Each directory needs its own service bind account with read-only rights to the search base that Keycloak imports from. Use separate accounts so that one directory's password rotation does not break another, and document who owns each account and its expiry. Ask the directory team to confirm that the account cannot write attributes or reset passwords.
LDAPS or StartTLS with trusted certificates
Keycloak should reach each domain controller over LDAPS or StartTLS, and the certificate chain for each directory must be trusted by the Keycloak truststore on every node. Plan the truststore update for each directory's certificate authority, including renewal dates. Plaintext LDAP exposes bind credentials and user data on the network, so treat any exception as a documented risk decision.
Network paths to every domain controller
Every Keycloak node that can run a login or sync must reach every domain controller it may query, on the LDAP and LDAPS ports the directory uses. Test from each node, not only from a jump host, and include DNS resolution for the domain controller names. Ask the network team which firewall rules, load balancers or site links sit on each path, because a path that works for one node may fail for another.
Attribute ownership register
Write down which directory is the authoritative source for each user attribute, such as email, display name, department and account status, before any provider is enabled. Overlapping directories will otherwise overwrite each other at each sync. This register also drives username collision rules and the mappers you configure, and it gives auditors a record of where each identity attribute comes from.
How to configure multiple LDAP providers in one realm
This sequence takes several directories, forests or acquired domains from inventory to working user federation in one Keycloak realm, with each provider tested on its own and then together.
Inventory directories and overlapping identities
The identity owner and the directory administrator for each domain list every forest or domain that must sign in, the service account each one will use for binding, and the user search base for each. They also record where the same username or email appears in more than one directory, because those collisions decide the lookup order and the attribute mapping later. The step is done when a written table lists each directory, its owner, its search base, its bind account and its known overlaps, and the team agrees which directory is authoritative for each overlapping user.
Create one user federation provider per directory
An administrator in the Keycloak admin console creates a separate LDAP or Active Directory user federation provider for each directory in the target realm. Each provider gets its own connection URL, bind DN and bind credential, users DN, and username attribute. Use a distinct display name per provider so audit entries and login logs can be traced to a directory. The step is done when every provider is saved in the realm and appears in the user federation list with its own settings, and no provider reuses another provider's connection details.
Configure attribute mappers and import settings
For each provider, the administrator maps the directory attributes Keycloak needs, such as email, first name, last name and any group membership attributes, and chooses whether users are imported into the local database on first login or on demand. Mappers should be set per provider because the attribute names differ between an Active Directory forest and another LDAP directory. Note the import choice and the sync mode for each provider in the runbook. The step is done when each provider has a documented mapper set and an import setting, and an administrator can read those settings back without guessing which directory they belong to.
Set provider priority and test each connection
The administrator sets a priority value on each provider so Keycloak knows the order to query them when a username is looked up. Then, for each provider, the administrator runs the connection test and the authentication test from the provider page using a dedicated test account in that directory. A failed test usually points to the bind account, the LDAP URL or TLS trust, or the users DN. The step is done when every provider returns a successful connection test and a successful authentication for its test account, and the priority values are written down with the reason for each.
Validate lookup order with test accounts from each domain
The team signs in with at least one test account from each directory, plus a deliberately duplicated username if the overlap analysis found one. They check which provider resolved each account by reviewing the user's federation link in the admin console and the login events. This is the step where a collision shows up as the wrong person signing in, so the team should confirm that the expected directory wins for each case. The step is done when each test account signs in and maps to the directory the team agreed in the inventory, and every collision case behaves as the written decision says.
Look up users in the admin console
An administrator searches for users from each directory in the admin console, both by username and by email, and confirms that the attributes and group data display correctly. The check also covers a user who should not be found, such as a disabled account or a user from a directory that is not authoritative for that name, so the team knows the search behaves as the design requires. The step is done when each lookup returns the expected user with the expected provider link, and the results are recorded alongside the test accounts.
Add sync and group settings
Once authentication and lookup work, the administrator configures periodic changed-user synchronization and full synchronization for each provider, and sets how group membership is imported and mapped to Keycloak roles or groups. Sync schedules should be set per provider so one slow directory does not hold up another. The step is done when a sync run for each provider completes with no errors in the log, a change made in the source directory appears in Keycloak after the next sync, and the group mappings match the access model agreed at the start.
How provider priority and username collisions affect sign-in
Keycloak consults user federation providers in priority order, and the first provider that finds a matching username wins. When two Active Directory forests both contain an account named jsmith, the realm does not hold two identities for that name. It holds one, and the provider that answers first decides which directory account signs in. The second account is not reachable through that username. This is the main reason the lookup order is a security decision rather than a tuning setting. Before go-live, confirm in the server administration guide and in your Keycloak version how priority is set on each LDAP or Active Directory provider, and how a user imported from one provider is treated when a second provider later sees the same name.
There are three practical ways to avoid ambiguity. The first is to choose a unique login attribute across all directories, such as a user principal name or an email address that is verified to be unique in every forest, and make that the Keycloak username. The second is a domain-qualified username convention, where users sign in with a form that names their directory, so that a collision cannot resolve silently to the wrong account. The third is to place directories that overlap in separate realms and connect them through brokering, which removes the shared namespace entirely but adds a second login hop and more configuration to maintain. Each option has consequences for help desk scripts, application claims and audit logs, so the choice should be written down before any provider is created.
Whatever rule you choose, test it with real overlapping accounts copied from each directory, including accounts with the same username, the same email address and disabled or expired accounts in one domain. Confirm which account signs in, which provider is recorded against the user, and what the application receives in its tokens. Repeat the test after changing provider priority, after a directory is reindexed or renamed, and after any Keycloak upgrade, because the behavior you verified is only the behavior of the version you tested. Keep the results as evidence for your access review.
Attributes and identifiers to map per directory
This table lists each identity field you must decide for every LDAP or Active Directory provider in the realm, with the attribute options, the linking role and who should own the authoritative value. Read each row as a decision to record before the first provider is enabled, because changing it later can split or duplicate accounts.
| Field | Typical choice and options | Role in the realm | Who decides the authoritative source |
|---|---|---|---|
| Username source | sAMAccountName for pre-Windows 2000 logons, userPrincipalName for sign-in, or an LDAP uid on OpenLDAP or FreeIPA-style directories | Becomes the Keycloak username, so it must be unique across all providers or collisions appear | Directory team for each forest, with the identity owner approving the cross-domain naming rule |
| mail attribute, or userPrincipalName where mail is empty in some domains | Used for account matching, notifications and verified email handling; confirm whether each domain's mail values are trustworthy | Messaging or identity team that owns mailbox provisioning in each domain | |
| First and last name | givenName and sn in Active Directory, or the equivalent attributes in other LDAP schemas | Display and profile data; decide whether Keycloak or the directory wins on each login sync | HR or the directory owner, since these values usually originate in the HR system |
| Unique external ID | objectGUID in Active Directory, entryUUID in OpenLDAP-style directories, or a stable employee ID | Links a Keycloak user to one directory object even after a rename; avoid relying on username alone | Directory team, with the architect confirming the attribute is stable across domain moves and migrations |
| Group membership handling | Group mapper that imports groups, a role mapper, or no group import with authorization decided by the application | Controls whether directory groups become Keycloak groups or roles and how nested membership is read | Application owners and security team, who decide which groups grant access in each client |
| Attribute update ownership | Import on login, periodic sync, or read-only mode for each mapped attribute | Sets which system wins when the same field changes in Keycloak and in the directory | Identity owner for the realm, recorded per attribute in the design document |
| Provider scope and search base | One base DN or domain per provider, with users limited to the intended organizational units | Prevents one directory from importing accounts that belong to another domain or tenant | Directory team for each domain, approved by the realm owner |
| Disabled or departed user handling | Whether a directory disable flag is imported, and whether Keycloak disables local sessions when the account is disabled upstream | Determines whether offboarding in one domain reaches every application that uses the realm | Security team with HR, who own the joiner, mover and leaver process |
Security settings for federated directories
Each directory you federate into a Keycloak realm becomes a trusted source of usernames, groups and password checks. The controls below decide how much damage a compromised bind account, an interception or a misconfigured admin mapping can do, and they need to be set per provider rather than once for the whole realm.
Least-privilege bind accounts
Create a separate, read-only bind account for each directory, scoped to the search base that Keycloak needs. Do not reuse a domain administrator or a shared service account across providers. Confirm with the directory team which attributes the account can read, and check that it cannot write, reset passwords or modify group membership. A bind account that spans two forests or domains multiplies the impact of one leaked credential.
Keycloak docsLDAPS or StartTLS with validation
Encrypt every connection from Keycloak to each directory, either with LDAPS or StartTLS, and validate the server certificate against the correct internal CA for that directory. Turning off certificate checks to get a connection working hides the problem and leaves bind passwords and user attributes exposed to anyone on the path. Keep a separate truststore entry per directory so one forest's CA does not silently trust another.
Production guideLimit directory groups to admin roles
Federated users should not receive Keycloak admin roles just because they belong to a broadly populated directory group. Map only specific, reviewed groups from each directory to realm roles, and keep administrative roles assigned locally to a small set of accounts. Confirm that a group from an acquired domain cannot grant admin rights through a mapper that matches on a shared group name.
Protect bind passwords in configuration
Keycloak stores LDAP bind credentials in its provider configuration, so treat them as secrets. Keep them out of exported realm files, version control and shell history, and supply them through a secrets mechanism your platform team controls. Rotate each bind password on a schedule and after any staff change, and record which provider each credential belongs to so rotation does not break a different directory.
Log and review authentication failures
Repeated failed logins against one directory can signal password spraying or a misconfigured bind account. Keycloak 26.8 persists login failures to the database by default, so the table will grow with every failed attempt across all providers. Decide how long to keep those records, who reviews them and how they are exported to your SIEM, then confirm the retention setting in your own environment before go-live.
Upgrading guideHow one realm routes a login across several directories
The login starts when a user submits a username on the Keycloak login page of one realm. Keycloak checks its user federation providers in priority order and sends the bind to the first directory that holds a matching account. If a directory cannot be reached, Keycloak must fall through to the next provider or fail that login, so check how each provider is configured for that case. The trust boundary sits between Keycloak and each domain controller, where Keycloak holds a bind account and the directory decides whether the password is correct.
Lookup order, bind to the first matching directory, and fallback when a directory is unreachable.
What happens when one directory is unreachable or retired
When one directory becomes unreachable, the users who authenticate through that LDAP or Active Directory provider cannot sign in while the outage lasts, because Keycloak has no other source that can verify their passwords. Users whose accounts live in other providers, or in the local Keycloak database, continue to sign in normally, since each provider is consulted separately. Keycloak's behavior during a timeout depends on the provider's connection and search settings and on whether the user already exists locally, so test a simulated outage in a non-production realm: block the directory port, attempt a login for a user from each provider, and record which logins fail, how long they take to fail, and what the administrator console shows. Confirm this against the exact Keycloak version you run, because federation failure handling has changed between releases.
Retiring a directory calls for a deliberate sequence rather than a single switch. First, confirm there are no active dependencies: list the clients, identity provider mappers and role or group mappings that rely on attributes or groups from that provider, and check which applications assume its users exist. Next, turn off periodic sync and on-demand import for the provider so Keycloak stops writing changes from it, and tell affected users and application owners the date sign-in will change. Then disable the provider itself, which stops authentication against it while leaving its configuration in place so it can be re-enabled if the retirement is reversed.
Keep the imported accounts after disabling. Deleting them removes group memberships, role assignments, and sessions that other systems may still reference, and it cannot be undone without a restore. Set a review date, record who owns the cleanup decision, and remove accounts only after logs show no sign-ins for an agreed period and the affected applications have been checked. Document each step in the change record so the auditors and the directory team can see what changed and when.
Common failures when federating several directories
This table maps the failures teams most often hit when Keycloak federates several LDAP or Active Directory domains into one realm. Read each row as symptom, likely cause and first fix, and check the cause before changing settings. The main takeaway is that most failures trace back to connection settings, lookup order, or which directory is authoritative for an attribute.
| Failure | Likely cause | Fix to try first |
|---|---|---|
| Connection test fails for a second domain | LDAPS certificate chain not trusted by the Keycloak truststore, or the chain is incomplete | Import the full issuing chain into the Keycloak truststore on every node, then retest the connection and authentication from the admin console |
| Connection test fails with invalid credentials | Bind DN or bind password is wrong, or the bind account is in a different domain than the one being searched | Use the user principal name or full DN of a service account in that directory, and confirm the account can read the users container |
| Connection test fails with a timeout | Wrong port (389 instead of 636 for LDAPS, or a global catalog port), or a firewall between the Keycloak nodes and the domain controllers | Confirm the port and network path from every Keycloak node, not only from an administrator workstation |
| Users from the second domain cannot sign in | Provider lookup order places an earlier provider first, or the search base does not include the users' OU | Review provider priority, then check the users DN and search scope against where the accounts sit |
| Wrong account matched at sign-in | The same username exists in two directories, and the first provider in priority order answers the lookup | Decide whether usernames are globally unique, and if not, change the login identifier or use a domain-qualified name |
| Group membership missing for some users | Group mapper scope or group DN points at one domain only, or nested groups are not enabled | Set each group mapper to its own directory's group base, and verify nested group handling matches how the directory stores membership |
| Attributes stale after directory changes | Sync mode set to import only, or a different directory is authoritative for the attribute than the one Keycloak reads | Name the authoritative source for each attribute, set the sync mode to match, and run a manual sync to confirm the value updates |
| Sign-in slow when one directory times out | Unreachable domain controller is tried on every lookup, and default timeouts are long | Reduce connection and read timeouts, list reachable controllers first, and test failover from each Keycloak node |
Questions buyers ask about multi-directory Keycloak federation
What drives the cost of federating several LDAP or Active Directory domains into one Keycloak realm?
The main cost drivers are the number of directories, the number of forests, how many usernames and email addresses overlap across them, how group membership is modeled, and how much of the estate is cut over in one step. Each extra directory adds a provider to configure, map, test and document, and overlapping usernames add decisions about collision handling and account linking. The cost is one-time build work plus recurring upgrade and review work. Ask for a written scope that lists each directory, the attribute and group mappings, the failover behavior you require, and the test cases that will sign off the cutover. DeployOpen does not publish a price list, so a quote follows from that written scope.
How long does a multi-directory Keycloak federation project take?
Duration depends on how many directories and forests are involved, how many of them have overlapping identities, and how much testing your change process requires. Work usually runs in the order of discovery, provider build, collision testing, failover testing, pilot logins and cutover, and each stage waits on input from your directory owners. No duration is fixed in advance. Ask for a timeline inside the written scope that shows which steps depend on your teams, such as approvals, test accounts and change windows, so the schedule reflects your environment rather than a generic estimate.
What must our team provide before a Keycloak directory federation project starts?
Plan to supply the following before the build starts:
- Directory administrators for each domain or forest who can confirm schemas, OU placement and group models
- Bind accounts with read-only access, along with agreed rotation and password storage rules
- TLS certificates or the trust chain needed for LDAPS connections from the Keycloak network
- Firewall and routing approvals from each directory's network owners to the Keycloak hosts
- Test users in each directory, including accounts with duplicate or near-duplicate usernames
- A named owner for the change window and for rollback decisions
Confirm each item with the relevant owner early, because approvals and certificate issuance often set the pace.
Can our internal team set up multiple directory providers in Keycloak without a partner?
Yes, a capable internal team can do this, provided it has someone who understands both Keycloak's user federation settings and the directories involved. The hard parts are rarely the first provider. They are provider priority, username collisions across domains, how Keycloak behaves when one directory is unreachable, and how to disable a provider without orphaning accounts. Ask whether your team has tested each of these in a non-production realm, who will own the design after go-live, and how many people can cover the work if someone leaves. A partner is useful when you need the design reviewed, the failure cases tested, or the work delivered within a fixed scope.
Do we need AD FS or Microsoft Entra ID instead of direct LDAP federation?
Not necessarily. Direct LDAP or Active Directory federation in Keycloak reads users from the directory itself, and it suits applications that connect to Keycloak and need the directory's users. Microsoft's comparison notes that most on-premises apps authenticate against Active Directory with LDAP or Windows-integrated methods, and that Active Directory needs a federation system such as AD FS for SaaS apps. Entra ID is the cloud identity service that existing Active Directory organizations sync to through Microsoft Entra Connect. Choose based on where your authoritative identities live, which applications must trust which sign-in path, and whether your security team requires sign-in to flow through a Microsoft service. Those are separate projects with their own scope, so confirm which path fits before you write the requirements.
What ongoing work follows a Keycloak upgrade when several directories are federated?
Each Keycloak upgrade needs a regression pass across every directory provider, not only a check that the server starts. Upgrade notes change over time, so review the release notes for each version that you move to, then retest login for each directory, group sync, attribute mappings, failover behavior and disable procedures. Keycloak also documents a database schema migration at startup by default, with a manual option that its upgrading guide suggests for large deployments, so plan database backups and the migration method before the upgrade window. Directory changes such as renamed domains, new forests or certificate renewals create their own recurring work. DeployOpen offers ongoing support, upgrades and continuous testing as retainers, and those terms are set in a written agreement.
How should we handle one directory being unreachable without locking out users from the others?
Decide the failure behavior before the build, because Keycloak's behavior depends on how each provider is configured and on your login flows. Confirm which directories must keep working when another is down, how long a failed lookup should wait before Keycloak moves on, and whether accounts from an unreachable directory should be denied or served from cached data. Test this with a real outage in a non-production realm, including a case where an account exists in two directories. Record the results so your operations team knows what users will see during an incident. Ask your partner or internal team to show the test evidence before go-live.
How DeployOpen scopes and delivers this integration
DeployOpen plans, implements, tests and documents self-hosted Keycloak inside your own infrastructure, so the realm, the directory connections and the logs stay under your control. Most engagements are fixed-scope, and the written agreement is where the multi-directory design gets pinned down: which LDAP or Active Directory domains and forests are in scope, which User Federation providers will be created, which bind accounts Keycloak will use, which test accounts exist in each directory, what the username and email collision rules are, and what counts as done for failover and provider disablement. Deliverables and timelines follow from that list, so ask for each directory to be named explicitly rather than described as a group of domains.
Delivery usually moves through the same stages for every directory: confirm network paths and certificate trust from the Keycloak nodes to each domain controller, build one provider per directory in a non-production realm, run the mapper and priority tests against the test accounts, then rehearse an outage of one directory and a controlled disablement before anything touches production sign-in. DeployOpen documents the resulting configuration, the runbook for adding or retiring a directory, and the evidence your security and compliance teams will ask for. The client's own staff should expect to supply directory administrators for bind account creation and reviewers for the test results, since those steps depend on access DeployOpen will not have by default.
After go-live, ongoing support, upgrades and continuous testing are available as a retainer, which is useful when Keycloak minor releases change federation behavior or when an acquisition adds a new domain. Confirm in the written scope which Keycloak version is targeted, since the current release line is the one you will be operating, and confirm who owns the Keycloak Operator or container build if you deploy on Kubernetes. DeployOpen does not issue audit reports or certifications, so any control evidence it prepares goes to your auditors for their own assessment.

