Keycloak As LDAP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You cannot run keycloak as ldap server out of the box. Keycloak acts as an LDAP client that reads users from an existing directory. Teams often want one identity hub for modern web apps and older tools. They try to point older database tools directly at Keycloak for user checks. When this fails, admins often create shared local accounts on the target systems. Those broad roles give users too much power over production data. How keycloak as ldap server setups work in practice Keycloak speaks m

Keycloak + Authorization as a Service: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You cannot run keycloak as ldap server out of the box. Keycloak acts as an LDAP client that reads users from an existing directory. Teams often want one identity hub for modern web apps and older tools. They try to point older database tools directly at Keycloak for user checks. When this fails, admins often create shared local accounts on the target systems. Those broad roles give users too much power over production data.

How keycloak as ldap server setups work in practice

Keycloak speaks modern web protocols like OIDC and SAML by default. It does not listen for raw LDAP queries from external tools or servers. Instead, Keycloak uses user federation to link to an external directory service. You set up an LDAP server like OpenLDAP or Active Directory first. Then you link Keycloak to that directory to sync users and groups.

In this setup, the directory holds the base user records and passwords. Keycloak reads those records or writes changes back to the directory tree. Modern apps ask Keycloak to log users in through web flows. Older apps that need LDAP talk straight to the underlying directory server. Both paths share the same user list and group mappings.

Some teams add a custom plugin or a virtual directory in front of Keycloak. This bridge translates incoming LDAP bind requests into Keycloak API calls. While this works for basic logins, it adds another moving part to maintain. If the bridge breaks, older tools cannot check user passwords or group roles.

Why directory sync is not enough for database security

Syncing users between a directory and Keycloak solves the login problem. It lets you manage accounts and group memberships in one central place. When someone leaves the team, you disable their account once. That change stops them from logging into web apps and directory tools.

Still, login checks only decide who gets through the front door. Once a database or server accepts the login, the directory steps aside. The user now holds an open session tied to a static database role. Directory sync cannot see what queries or commands run inside that session.

Keycloak + Authorization as a Service: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Teams often map directory groups to broad admin or read roles in databases. A developer in an engineering group gets full read rights across many tables. If they run a query on a user table, they get raw data. The directory cannot rewrite emails, phone numbers, or card numbers in those results. It also cannot ask a manager to approve a risky delete command first. To control actions in flight, you need controls at the command level.

How to plan your identity architecture

Start by listing every app and database your team uses each day. Group them by the login protocol they need, such as OIDC or LDAP. If most tools use modern web logins, make Keycloak your main identity hub. Keep a light directory service only if legacy systems still demand LDAP binds.

Next, separate login checks from data rules on your backend systems. Do not rely on directory groups alone to guard sensitive tables or servers. Keep base roles small and add runtime checks for live database queries. This approach keeps user management simple while protecting data during active sessions.

Add runtime guardrails and masking beside your databases and APIs

Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.

Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.

Frequently asked questions

Can Keycloak replace OpenLDAP or Active Directory?

Keycloak can replace them only if all your apps use OIDC or SAML. If you still run tools that require LDAP binds, you must keep an LDAP directory.

Does Keycloak store passwords when linked to LDAP?

No, Keycloak usually passes the password check back to the LDAP server. It stores metadata and role mappings locally, while the directory checks the actual secret.

How do I let LDAP users log into modern databases?

You link your LDAP directory to Keycloak through user federation first. Then you use OIDC tokens from Keycloak to start database and server sessions.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.