When LDAP and Active Directory user federation fits a Keycloak rollout
If your people and groups already live in an LDAP directory or Active Directory, you probably do not want Keycloak to hold a second copy of every account. User federation lets Keycloak look up users in the existing directory, validate their credentials against it, and, depending on configuration, import or cache selected attributes so that tokens carry what applications need. Teams usually reach for it when the directory is the system their HR and access processes already maintain, when password policy and account lockout must stay in one place, or when a single sign-on rollout must cover staff who never had a Keycloak account. The server administration guide documents LDAP and Active Directory user federation alongside Kerberos, and those are the mechanisms this topic covers.
Federation looks simple until you decide who owns each piece of data. Group and role mappers decide which directory groups become Keycloak roles and client scopes, and a mapper that works for one application can grant the wrong access to another. Attribute ownership matters just as much: if a user's email, department or manager is edited in the directory but also in Keycloak, one side will silently win. Sync timing adds another layer, because periodic synchronization and on-demand lookups behave differently when someone leaves the company, changes teams or is disabled. Before building anything, write down for each attribute and group which system is authoritative, how often changes must reach Keycloak, and what happens to existing sessions when an account is disabled upstream.
Confirm the directory details with the people who run it before you configure the connection: the LDAP or Active Directory flavor, how users and groups are organized, which service account Keycloak will bind with and what it is allowed to read, and whether the directory is reachable from the Keycloak network segment over TLS. Also confirm whether any application needs Kerberos sign-in for integrated Windows authentication, since that changes both the federation setup and the network path. The sections that follow cover read-only and writable modes, synchronization, mappers and Kerberos in order, so use this section to settle the ownership questions first.
Which Keycloak settings make up directory federation
Directory federation in Keycloak is configured through a small set of linked settings in the admin console. The connection decides what Keycloak can reach, the edit mode decides who owns user data, and the mappers and sync settings decide what gets copied and how often. Get these in order and the rest of the rollout is far easier to test.
User storage provider connection
This is where Keycloak is told how to reach the directory: the connection URL, the bind credentials for a service account, the users DN where user searches start, and the search scope. A common mistake is binding with a personal administrator account or using a users DN that is too high in the tree, which pulls in service accounts and disabled users. Use a dedicated read-scoped bind account and test the search filter against a known test user before saving. Confirm exact option names against the server administration guide for your version.
Keycloak docsEdit mode setting
The edit mode controls whether Keycloak can write changes back to the directory. Read-only keeps the directory as the single source of truth and blocks password and profile changes in Keycloak, while writable lets Keycloak modify directory entries. Teams often pick writable for convenience and later find that Keycloak updates collide with directory policies. Decide this with the directory owners before the first sync, and confirm which modes your version offers.
Attribute and object class mappers
Attribute mappers translate directory attributes, such as mail, given name and surname, into Keycloak user fields. The object class setting determines which directory entries count as users, which matters because many directories hold users, computers and service accounts in the same subtree. A frequent mistake is mapping an attribute that is empty for many users, so profile fields silently stay blank. Sample a set of representative accounts and check each mapped field after the first import.
Group mappers
Group mappers import directory groups as Keycloak groups and keep membership aligned, so group-based access in applications can follow the directory. The mapper depends on how groups are stored: membership may be held on the group or on the user, and nested groups need deliberate handling. Teams often assume nested membership is resolved automatically and then find users missing access. Confirm the membership model and nesting behavior for your directory before you rely on group claims.
Role mappers
Role mappers link directory group membership, or a directory attribute, to Keycloak realm or client roles. Role mapping is where federation turns into authorization, so an error here grants or removes application access. A common mistake is mapping broad groups, such as all staff, to administrative client roles. Keep the mapping list short, document which directory group maps to which role, and review it with the application owners before go-live.
Synchronization settings
Synchronization controls how Keycloak imports users and how often it refreshes them, with full sync and changed-user sync as the main modes. Full sync rereads the whole directory and is heavier, while changed-user sync relies on directory change tracking. Teams often leave the periodic schedule running with no alert, so disabled accounts or removed groups linger in Keycloak. Set a schedule that matches your offboarding process, check how removed users are handled, and monitor sync results.
How a federated login reaches the directory through Keycloak
The flow starts when a user's browser is redirected from an application acting as an OIDC or SAML client to Keycloak. Keycloak checks its local database for the user and, when federation is enabled, uses a bind account to query the LDAP or Active Directory server across a trust boundary. Imported attributes and mapped groups are stored in Keycloak's database, while passwords stay in the directory when the provider is read-only. Check which side holds the password, which account Keycloak binds with, and which mapped attributes are written locally. This is an illustrative flow, not a fixed deployment.
Illustrative flow of a federated sign-in between browser, client, Keycloak and the directory.
Read-only or writable federation: which mode fits your directory
This table compares the main federation choices for Keycloak against an LDAP or Active Directory source: who writes, when users are copied, and whether group and role mappers write back. Read each row as a decision, then check the operational cost in the right-hand column before choosing a mode.
| Decision | When it fits | Operational cost |
|---|---|---|
| Read-only federation | The directory is the only system allowed to change identities, and Keycloak only needs to authenticate users and read attributes | Account changes such as password resets, new hires and leavers must go through the directory team, and Keycloak cannot fix attribute gaps itself |
| Writable federation | Users must change profile data or passwords from Keycloak screens and the directory team accepts Keycloak as a writer | A dedicated bind account needs write permissions, so access reviews must cover that account, and failed or partial writes need monitoring |
| No synchronization (lookup on login) | Directories are large or change often, and you want Keycloak to query the directory each time a user signs in | Every sign-in depends on directory availability and latency, and some attributes may not be searchable in local Keycloak views |
| Periodic or full synchronization | You need local user records for admin search, event linkage or consistent attributes across clients | Sync jobs add load on the directory, and changes between runs can leave Keycloak and the directory out of step |
| Importing users into the local database | Applications need user IDs and attributes stored in Keycloak, or you want to keep working when the directory is briefly unreachable | Imported copies can drift from the directory, so removed or disabled accounts need an explicit cleanup rule |
| Group and role mappers, read-only | Directory groups should decide Keycloak roles and access, and the directory stays the authority for membership | Role changes depend on the next sync or login, so access removed in the directory may persist in Keycloak until refreshed |
| Group and role mappers, write back | Keycloak-side role or group changes must appear in the directory for other systems to use | Each write back extends directory permissions and creates a second place where membership can be changed, so confirm ownership first |
How to configure LDAP or Active Directory federation in Keycloak
This sequence takes a Keycloak realm from an empty user store to one where directory users sign in through a client application, with the directory remaining the source of truth for identities and group membership.
Confirm directory structure and bind account with the directory team
The identity team and the directory administrators agree on the connection endpoint, the transport encryption to use, the base distinguished name that holds the users to federate, the object classes and login attribute (such as sAMAccountName or uid), and which groups should reach Keycloak. Record these in the design document before any configuration is changed. The step is done when both teams have signed off on the written values and the directory team confirms which accounts and groups are in scope.
Create a dedicated service bind account
The directory team creates a separate service account for Keycloak with read access to the search base and the attributes and group objects Keycloak needs, and no write or administrative rights. Keep the password in a secrets store and set a rotation process before go-live. The step closes when the account authenticates against the directory from the Keycloak host and cannot modify a test object outside its permitted scope.
Create the user federation provider in the target realm
In the admin console, open the target realm, go to User federation, and add an LDAP provider. Enter the connection URL, the bind DN and credentials, the users DN, the username attribute, and the object classes used by your directory. Enable TLS for the connection. Do this in a test realm first, not the production realm. The step closes when the provider is saved without validation errors.
Set the edit mode deliberately
Choose read-only, unsynchronized or writable mode based on whether Keycloak may change directory objects. Read-only keeps the directory as the only place where profile and password changes are made, which fits most directory-as-source-of-truth designs. Writable mode lets Keycloak write back attributes and passwords and needs directory permissions that the bind account in the previous step would then need. Confirm the choice with the directory team and document it. The step closes when the mode is set and recorded, and a test attempt to change an attribute behaves as the chosen mode predicts.
Test connection and authentication from the admin console
Use the connection test and the authentication test buttons on the provider page. The connection test confirms that Keycloak can reach the server and bind with the service account. The authentication test confirms that the bind account can search the users DN. Fix errors in the provider settings and repeat until both pass. The step closes when both tests succeed, and a known test user is returned by a user search in the realm.
Map attributes and add group and role mappers
Review the default attribute mappers for email, first name, last name and username, and add mappers for any additional attributes that applications need. Add a group mapper that imports directory groups into Keycloak, choosing whether to import only groups under a chosen DN and whether to map group membership into roles. Confirm attribute names and group DNs with the directory team, since these drive what appears in tokens. The step closes when a test user's imported profile and group memberships match the directory.
Run a first synchronization on a test realm
Trigger an initial full synchronization of users from the provider page, then review the results: count of users added, updated and failed, and any unresolved mapper errors. Run a changed-users synchronization after changing a test object in the directory to confirm that updates flow through. Schedule periodic synchronization only after both runs produce the expected results. The step closes when the imported user count matches the directory scope and a changed test object appears with its updated value.
Confirm a test user signs in through a client application
Register a test client application in the same realm, then sign in as a federated test user with the directory password. Decode the issued ID or access token and check that the expected claims, including group or role claims from the mappers, are present and that a user outside the mapped groups does not receive them. The step closes when the test user signs in, the token contents match the mapper design, and the results are recorded for review before the configuration is moved to production.
How Kerberos sign-in works on top of Active Directory federation
Kerberos sign-in lets a domain-joined user reach Keycloak without typing a password, because the browser presents a Kerberos ticket issued by the domain controller through the SPNEGO negotiation. Keycloak documents Kerberos as a separate feature from LDAP and Active Directory user federation, so it is configured on top of a working directory connection rather than in place of one. The directory still supplies the user records, group memberships and password checks for anyone who signs in with a password. Before any work starts, confirm with the directory team that the Active Directory domain is the one Keycloak federates against, since a Kerberos ticket from a different domain will not match a federated user.
The prerequisites sit mostly outside Keycloak. The directory team must create a service principal for the Keycloak host and export its keytab, and the keytab must be protected like any other credential because it allows Keycloak to decrypt tickets. DNS must resolve the Keycloak hostname consistently with the name in the service principal, and the clocks of the Keycloak host, the browsers and the domain controllers must be synchronized within the tolerance Kerberos allows. Each of these is a common cause of failed negotiation, so check them in a test domain before touching production realms.
On the browser side, users need their browser to send Kerberos credentials to the Keycloak hostname, which in practice means adding that hostname to the trusted sites list through policy for domain-joined machines. Plan for users who are off the corporate network, on unmanaged devices or outside the domain, who will not get a ticket and must fall back to the password form. Keycloak's Kerberos settings, the fallback behavior and the exact browser steps change with the Keycloak version and your environment, so confirm each setting against the Keycloak server administration guide and verify the full flow in your own test domain before rollout.
What drives federation effort and how to keep each part down
This table lists the main drivers of LDAP and Active Directory federation work in Keycloak, what each one does to effort, and how to reduce it. Read it before you ask for a quote, because most of the cost sits in directory decisions that are easier to settle early than to change during build.
| Driver | Why it changes the work | How to keep it down |
|---|---|---|
| Number of directories and domains | Each directory needs its own connection, bind account, certificate handling, and mapper set. Multi-forest or multi-domain estates multiply the testing matrix. | Confirm which directories must sign users in on day one. Federate only those and defer the rest to a later phase. |
| Realms that federate the same directory | Every realm holds its own federation provider, mappers, and sync schedule. Shared directories across realms duplicate configuration and create drift between them. | Use one realm for one directory where the business model allows it. Document any second realm as an explicit decision with an owner. |
| Size and nesting of groups | Deeply nested groups and large membership lists slow synchronization and make group-to-role mapping harder to reason about and verify. | Agree which groups drive application access before build. Map only those groups, and flatten or exclude groups used for mail distribution or other non-access purposes. |
| Attribute mapping complexity | Each mapped attribute needs a source, a target, a format rule, and a test case. Multi-valued attributes and inconsistent directory data add review cycles. | Agree attribute ownership in writing: which system is authoritative for name, email, department, and manager. Keep the mapped set to what applications actually read. |
| Write-back requirements | Writable mode lets Keycloak change directory objects, which needs service account permissions, change auditing, and agreement from the directory team. Read-only mode avoids most of this work. | Default to read-only mode. If users must change passwords through Keycloak, scope the write permissions to specific attributes and document who approves them. |
| Kerberos scope | Kerberos sign-in needs keytab handling, service principal names, browser configuration, and testing from domain-joined and non-domain clients. Each added network zone adds test cases. | Limit Kerberos to the internal sign-in paths that need it. Confirm the list of supported clients and networks before the work starts. |
| Applications that depend on mapped roles | Each application that reads group or role claims must agree on claim names, values, and behavior for users with no mapped role. Changes to mappers can break several applications at once. | Inventory the applications and the exact claims each one reads. Freeze the role model before integration starts and track changes through a single change process. |
| Environments and matching test data | Development, test, and production each need a directory with comparable users, groups, and nesting. Missing or synthetic test data hides mapper errors until go-live. | Use a small, dedicated test directory with representative accounts, nested groups, and edge cases such as disabled users. Keep its structure in sync with production through a documented process. |
| Internal team time | Directory administrators, identity owners, and application owners must review mappings, approve access, and test sign-in. This is usually the largest share of client-side effort and is paid from internal budgets. | Name the decision makers and their availability in the scope. Ask the provider to list which approvals are needed and at which points. |
| Keycloak platform and testing work | The provider typically is paid for configuration, mapper and sync setup, Kerberos work, test plans, and handover. Testing scales with each driver above. | Ask for a written scope that lists directories, realms, groups, mapped attributes, Kerberos paths, and test environments as separate line items. |
Securing the directory connection and the bind account
A federation provider is a standing trust path between Keycloak and your directory, so every control here limits what that path can read, write or grant. The cards below cover transport, the bind account, secret storage, admin access, write-back scope and role mapping, and each one follows the same production baseline: TLS everywhere and a clear split between the admin console and public endpoints.
Verify TLS on the directory connection
Connect to the directory over LDAPS or StartTLS and do not allow plaintext binds, because the bind password and every user lookup would otherwise cross the network in the clear. Keycloak's production guidance calls for TLS on all communication, so apply the same rule to the directory link. Import the full certificate chain for your domain controllers or LDAP servers into the Keycloak truststore and confirm that hostname validation passes. Test with a domain controller that has a certificate rotation scheduled, so you know the chain update process before go-live.
Production guideScope the bind account to read
Keycloak uses a bind account to search and read users, so give it read-only rights on the directory and limit its search base to the organizational units that hold users and groups Keycloak needs. Do not reuse a domain administrator or a personal account. Ask your directory team to confirm which attributes the account can read, because a broad read scope exposes data that Keycloak will import and may place in tokens.
Store bind secrets outside realm exports
Keep the bind password and any Kerberos keytab in a secret store or a protected file on the host, never in a realm export, a Git repository or a ticket. Realm exports are often shared between teams for migration and troubleshooting, so a credential placed there spreads further than intended. Rotate the bind password on a schedule and record who holds it. Confirm with your security team how the secret reaches the Keycloak process in your deployment model, whether that is a container secret, a vault integration or a mounted file.
Restrict who can edit federation providers
A user with rights to change a user storage provider can point Keycloak at a different directory, change the search base or alter attribute mappings, which can quietly widen who can sign in. Limit realm administration to a named group, use separate accounts for administrators and daily work, and keep the admin console on a hostname or context path that is not reachable from the public internet. Review the admin event log for changes to federation settings. Ask your identity team which roles can currently edit user federation in each realm.
Server admin guideLimit write-back to named attributes
If you enable writable mode, Keycloak can push changes such as profile edits or password resets back to the directory, so the write scope must be narrower than the read scope. Grant the bind account write permission only on the specific attributes Keycloak is allowed to change, and keep account creation and group membership changes in the directory. Test write-back with a disposable test account first, and confirm with the directory team that a failed write cannot leave the two systems disagreeing about the same user.
Review groups that map to admin roles
A directory group mapped to a Keycloak realm or client administrative role gives every member of that group control over Keycloak itself, which makes group mappers a privilege path as well as a sign-in convenience. List every mapper that feeds an administrative role, confirm the owner of each source group, and remove mappings nobody can justify. Repeat the review whenever directory groups are restructured, because a renamed or reused group can inherit rights it never had before.
How to test federation before production cutover
The purpose of this test plan is to prove that the directory, not Keycloak, decides who can sign in and what they are allowed to do. Build a test realm that federates a copy of the directory's test accounts, using a test organizational unit and a test group, so that no production user is touched. Before running anything, write down the expected result for every test case: the expected login outcome, the expected token claims, the expected log entry and the expected time to take effect. A test without a written expectation tends to be judged after the fact, and that is how drift goes unnoticed.
Start with the lifecycle checks. Disable a test account in the directory, then trigger synchronization in the user federation provider settings, and confirm that the account cannot sign in through Keycloak. Repeat with a deleted account and with a user moved out of the synchronized organizational unit. Next, change a test user's group membership in the directory and confirm that the change reaches the token after the next sync or login, as your configured mapper settings dictate. Check password outcomes too: a wrong password and a locked directory account should both fail in Keycloak for the reason the directory gives, and Keycloak should not allow a local password to bypass either result. Confirm brute force settings on the realm do not hide the real cause from your support team.
Then run the negative tests that most often reveal misconfiguration. Bind the federation provider with a service account that has only read rights, then with one that has insufficient rights to read group or attribute objects, and record which operations fail and how. For Kerberos, let a test keytab expire or use a stale one and confirm that sign-in falls back or fails as you specified. Finally, make the directory unreachable, for example by blocking the LDAP or LDAPS port on a test network path, and check what existing sessions, token refresh and new sign-ins do during the outage. Any failed check should stop the cutover, trigger a defect record with the failing expectation attached, and be retested after the fix. Ask your identity team to confirm the exact failover behavior for your Keycloak version before you write the expected results.
What to monitor, document and hand over after go-live
Federation keeps running after go-live only if someone watches it, knows which system owns each attribute and group, and can rotate the bind credentials without an outage. The items below connect the monitoring signals to the documents your operations team needs on day one.
Login failure signals and trend
Track failed sign-ins over time, not just as a count at a point in time. A sudden rise after a directory password policy change, a lockout wave or a stale bind credential shows up here first. Compare failures against your own weekly baseline and check whether they cluster by realm, client or user source. Login failures are persisted to the database by default in Keycloak 26.8, so confirm your retention matches what your audit team expects.
Keycloak metrics docsDirectory connection health and sync results
Review the outcome of each scheduled synchronization and the health of the LDAP or Active Directory connection, including whether the bind account can still authenticate and whether the configured directory servers respond. Record the last successful sync, the number of users created, updated and removed, and any errors. A sync that silently stops leaves disabled leavers signed in and new starters locked out, so alert on the absence of a successful run as well as on failures.
Metrics on the management interface
Keycloak exposes Prometheus-format metrics at /metrics on its management interface when started with --metrics-enabled=true. Scrape that endpoint from a network path that is not public, and confirm that the optional HTTP request and cache histograms are enabled only if your Prometheus setup can handle the cardinality. Set alert thresholds from your own baseline during a pilot period, not from generic values copied from another environment.
Cache health for cached user data
Federated user data is cached inside Keycloak, so a stale or overloaded cache can make a removed or changed directory account look current for longer than your policy allows. Watch cache hit and miss behavior and eviction patterns after a large sync. Confirm with your identity team how long cached attributes may live and whether a forced refresh is part of the leaver process, then verify that behavior in a test realm before relying on it.
Attribute and group ownership map
Write down which system is the source of truth for each attribute and group that Keycloak imports, maps or overrides. Typical examples include name, email, department, employee number and role groups. Mark which fields are read-only in Keycloak, which may be edited locally, and who approves a change. Without this map, a support agent who edits a local attribute can silently diverge from the directory, and the next sync will either overwrite the change or leave it in conflict.
Directory bind account rotation runbook
Document how the bind account password is rotated, which Keycloak user federation settings change with it, who holds the directory permissions, and how the change is tested in a non-production realm first. Include the steps to roll back if the sync fails after rotation. Agree in advance whether the bind account is a dedicated service account with read-only scope, and record the directory team contact who can unlock it. Review this runbook at least once per directory password policy cycle.
Questions teams ask before federating LDAP or Active Directory into Keycloak
How much effort does LDAP or Active Directory federation in Keycloak take?
The effort depends less on Keycloak itself than on the directory it connects to. The main drivers are how many directory containers hold users and groups, how clean the directory data is (duplicate accounts, disabled users, inconsistent email addresses), how many applications need group-based roles, and whether the directory team must create new service accounts and certificates. A single domain with clean groups is a small change. Several forests, nested groups and undocumented ownership add design and testing time. Ask any partner to size the work from a written list of directory locations, group rules and target applications, and confirm how they will test with a non-production directory before cutover.
Can our internal team federate Active Directory into Keycloak without a partner?
Yes, a team with Keycloak administration experience and access to the directory can do it, and the Keycloak server administration guide documents the LDAP and Active Directory federation settings. The skills that usually take longer to build are directory design (which groups map to which roles), Kerberos configuration, and testing login across every application after cutover. Teams usually weigh their own capacity against the risk of a mistake in production identity. A partner typically adds value by reviewing the mapping design, building a test plan and documenting the runbook so that the internal team can operate it later.
What does the directory team need to provide for the federation work?
The directory team usually provides four things. First, a dedicated bind account with the least privileges needed to read users and groups, plus a process for rotating its password. Second, test accounts and a non-production copy or sandbox of the directory so that login and sync can be tested without touching real users. Third, a group design that states which groups grant which application roles and who approves changes. Fourth, for Kerberos sign-in, a service principal and keytab created under the directory team's control. Confirm these items in writing before the schedule is set, because each one blocks a different test.
Should Keycloak use read-only or writable mode for directory users?
Read-only mode is the safer default when the directory is the source of truth. Keycloak reads users, groups and password validation from the directory, and administrators make account changes in the directory itself. Writable mode lets Keycloak create, update and in some cases set passwords in the directory, which can be useful for a transition but moves change control and write permissions into the identity platform. Choose writable mode only when a documented business need exists, when the directory team agrees to the write permissions, and when the change process covers who may alter directory objects from Keycloak.
What happens to existing local Keycloak users when federation is added?
Existing local users stay in Keycloak and keep their local credentials, roles and sessions unless someone changes them. Federated users are separate records that Keycloak links to the directory. Duplicate usernames or email addresses between the two sets can cause sign-in confusion or accidental account linking, so the plan should list every overlap before enabling federation. Decide whether local accounts for employees will be retired, kept for service or break-glass use, or moved into the directory. Test each case with a sample account, because role assignments and required actions can differ between local and federated users.
How do we decide what the directory must own before cutover?
Start with a list of identity facts and assign each to an owner: account existence, enablement, group membership, application roles, password policy, MFA enrollment and account recovery. The directory should own anything that other systems already rely on, which usually covers existence, enablement and group membership. Keycloak should own items that exist only for its applications, such as client settings, some role composites and MFA factors that the directory does not store. Write the answer per attribute, then test each one by disabling and re-enabling a test user and checking that the change reaches Keycloak as expected.
How DeployOpen scopes, builds and hands over directory federation
DeployOpen treats LDAP and Active Directory federation as a scoped deliverable inside your own infrastructure. We agree the directory connection, the sync model and the mapper design in writing before any configuration changes, then build and test the federation in a non-production realm first.
How we scope
- Inventory the directory forests, domains, OUs and service accounts Keycloak will bind to and read from.
- Decide with you whether federation is read-only or writable, and which attributes Keycloak may ever change in the directory.
- Record the group and role mapping rules, Kerberos sign-in needs and the applications that depend on them in a written scope.
How we build
- Configure the LDAP or Active Directory provider in a non-production realm using a least-privilege bind account, with TLS to the directory.
- Build and test full and changed-user synchronization schedules, then set group, role and attribute mappers against test accounts.
- Test sign-in paths for disabled, locked and departed directory accounts, and confirm Kerberos behavior where it is in scope.
How we hand over
- Deliver the realm configuration, mapper inventory, sync settings and a runbook describing the source-of-truth rules for your team.
- Walk your identity and directory administrators through how group changes, account disablement and password resets flow from the directory.
- Provide a test record showing the sign-in and sync cases run, with the findings and fixes from each round.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, and can cover federation changes after go-live.
- Review Keycloak upgrade notes for changes that touch user storage, sync or mappers before each planned upgrade.
- Confirm with your directory team which support boundary applies to bind account rotation, schema changes and certificate renewal.

