Connect Kubernetes to LDAP

Connect Kubernetes to LDAP through an identity provider, map groups to RBAC, secure the authentication flow, and avoid unsupported direct binds.

On this page

Link to Introduction: Why LDAP Integration with Kubernetes Requires Extra ComponentsIntroduction: Why LDAP Integration with Kubernetes Requires Extra Components

Kubernetes does not natively provide LDAP authentication. Out of the box, Kubernetes supports a pluggable authentication system, but it has no built-in ability to directly communicate with LDAP directories such as OpenLDAP or Active Directory. This limitation exists by design, keeping the API server focused on authentication delegation rather than hosting authentication logic. As a result, integrating LDAP with Kubernetes requires introducing an intermediary—either an identity broker or an authentication webhook—that can translate between LDAP directory operations and the methods Kubernetes understands.

Many teams initially expect to point Kubernetes at their LDAP directory and use LDAP credentials directly with kubectl. This does not work: neither the API server nor kubectl will bind to LDAP or perform directory lookups without an intermediary. Understanding and selecting the right bridging architecture is essential for secure and maintainable LDAP Kubernetes integration.

Link to Architectural Patterns: OIDC Providers vs. Webhook AuthenticationArchitectural Patterns: OIDC Providers vs. Webhook Authentication

There are two main architectural patterns for integrating LDAP authentication into Kubernetes: OIDC bridging and direct webhook authentication. Each translates LDAP authentication into credentials the Kubernetes API server can verify.

1. OIDC (OpenID Connect) Bridge Pattern:
In this architecture, an OIDC provider (such as Dex, Keycloak, or Pinniped) is set up as an intermediary that authenticates users against LDAP. The Kubernetes API server is then configured to trust the OIDC provider, which issues tokens representing authenticated identities. Users interact with the OIDC provider (often via a browser or CLI), obtain a credential, and use it for Kubernetes access. This approach supports advanced workflows, like single sign-on, token refreshes, and group claims.

2. Webhook Authentication Pattern:
A direct webhook authentication service (such as kube-ldap-authn) is deployed in-cluster or in close proximity to Kubernetes. The API server contacts the webhook on each authentication attempt. The webhook then binds to the LDAP directory and validates user credentials, returning an authentication result to Kubernetes. This approach bypasses OIDC entirely, simplifying infrastructure but usually at the cost of flexibility and advanced features.

OIDC bridging is more common and robust in production, enabling richer identity and group flows. Direct webhook authentication is usable for basic scenarios but typically lacks support for advanced directory features.

Link to Open Source Tools: Dex, Keycloak, Pinniped, kube-ldap-authnOpen Source Tools: Dex, Keycloak, Pinniped, kube-ldap-authn

Several open-source tools address LDAP-to-Kubernetes authentication, each with distinct trade-offs.

Dex:
Dex is a popular, lightweight OIDC provider that can be configured to use LDAP as a backend identity source. It enables the API server to authenticate users through the OIDC protocol. Dex is widely used, well-supported, and flexible but requires careful configuration for proper group and claim mapping.

Keycloak:
Keycloak is a full-featured identity provider that supports OIDC, SAML, and direct LDAP integrations. In a Kubernetes context, Keycloak can bridge LDAP authentication for clusters and inject group information into tokens. Its robustness and feature set make it ideal for organizations already using Keycloak for identity management, but it may be excessive for clusters with lighter requirements.

Pinniped:
Pinniped offers a modern, cloud-native authentication flow designed for Kubernetes clusters. Pinniped natively supports LDAP and Active Directory as authentication backends, and can function as either an OIDC provider or an authentication webhook. It emphasizes security, cluster federation, and advanced group mapping scenarios, and is actively maintained.

kube-ldap-authn:
kube-ldap-authn is a simple reference implementation of a webhook authentication provider for Kubernetes that authenticates directly against LDAP. While straightforward to deploy, it focuses solely on authentication—group or role mapping is not included by default. Notably, this project is archived and unmaintained as of July 2022 and is not recommended for greenfield or production deployments.

Tool Comparison Highlights:

  • Dex / Keycloak / Pinniped (OIDC providers): Flexible, scalable, support group claims, active development.
  • kube-ldap-authn (Webhook): Simple, limited scope, archived.
  • All require correct configuration for security and group mapping; OIDC-based tools provide more robust feature sets for enterprise needs.

Link to RBAC and Group Mapping: Leveraging LDAP Groups for Kubernetes AuthorizationRBAC and Group Mapping: Leveraging LDAP Groups for Kubernetes Authorization

After authenticating a user against LDAP, Kubernetes must map that user's identity—and usually their group memberships—to RBAC rules for fine-grained authorization.

With OIDC providers such as Dex, Keycloak, or Pinniped, LDAP group membership can be included as claims within the issued token. Kubernetes RBAC rules can then match on these group claims, allowing for directory-driven role assignments. This makes dynamic, large-scale access management possible and is typically required in enterprise environments.

In webhook integrations like kube-ldap-authn, authentication tokens may lack comprehensive group information, and the default implementation does not resolve group membership for Kubernetes RBAC. While schema extensions or custom attributes could, in theory, be mapped to RBAC rules, this is not standardized. Therefore, group-based authorization is significantly easier and more maintainable with OIDC-based architectures.

Link to Security Considerations: Tokens, Certificates, and LDAP Query ProtectionSecurity Considerations: Tokens, Certificates, and LDAP Query Protection

LDAP-to-Kubernetes integration introduces several critical security concerns:

  • Tokens, Not Passwords:
    Tools such as kube-ldap-authn require the use of authentication tokens (not raw LDAP passwords), since kubectl may store these credentials unencrypted within user configuration. Storing passwords puts directory security at risk; OIDC flows or short-lived tokens are preferred.

  • TLS and Modern Cipher Suites:
    All communication between the API server and authentication bridge, and between the bridge and LDAP directory, must use TLS—ideally no less than TLS 1.2 and modern cipher suites. Wrong ingress settings or non-secure endpoints can silently break authentication or expose credentials in transit.

  • LDAP Query Injection:
    Failing to properly escape or sanitize user input in LDAP queries leaves the system vulnerable to LDAP injection attacks, which can result in privilege escalation within the cluster. Only use up-to-date, maintained authentication bridges and carefully restrict who can modify directory entries.

  • Credential Handling:
    Avoid storing any secrets or passwords in plaintext on disk or in configuration. Monitor authentication bridges for vulnerabilities and keep all identity-related components up to date to prevent privilege escalation attacks.

Link to Misconceptions and Anti-patternsMisconceptions and Anti-patterns

  • Kubernetes supports LDAP natively.
    False. Native LDAP authentication is not built into Kubernetes; all integrations require an OIDC provider or webhook intermediary.

  • It is safe to use LDAP user passwords in kubectl.
    False. Kubectl stores credentials unencrypted and may expose passwords. Only use tokens or OIDC flows designed for this use case.

  • Dex is always required for LDAP integration.
    False. Dex is one option; Keycloak, Pinniped, and other brokers provide first-class LDAP support with their own trade-offs.

  • Group information flows automatically into Kubernetes RBAC.
    False. Group claims must be explicitly mapped and included by the OIDC provider; webhook solutions may need nonstandard extensions.

  • Webhook-based LDAP integration is as robust and secure as OIDC brokers.
    False. Webhook approaches are simpler but often lack advanced group mapping, federation, and secure token flows. They are best-suited for narrowly scoped or legacy scenarios.

Link to Decision Factors and Tool Selection GuideDecision Factors and Tool Selection Guide

Choosing the best LDAP-to-Kubernetes integration approach depends on your requirements for scale, flexibility, and security:

  • Use an OIDC bridge (Dex, Keycloak, Pinniped) if:

    • You require group-based RBAC, scalable identity federation, or SSO.
    • Your organization manages multiple clusters or complex identity domains.
    • You want a widely supported, production-grade integration path.
  • Consider a webhook (like kube-ldap-authn) only if:

    • You need minimal, straightforward authentication with no advanced group mapping.
    • You are maintaining a legacy deployment and cannot use OIDC bridges.
    • You accept limited flexibility and can manage operational risk (not recommended for new environments).

Prioritize tools that are actively maintained, support strong TLS configurations, and align with your RBAC/authorization requirements. For most modern organizations, OIDC-based LDAP integration with group claims is the most sustainable, secure, and future-proof solution.

Link to Conclusion: Key Lessons and Next StepsConclusion: Key Lessons and Next Steps

Kubernetes does not natively support LDAP authentication, and any robust, secure LDAP Kubernetes integration must introduce a bridging component—typically an OIDC provider or a webhook authentication service. OIDC bridges (Dex, Keycloak, Pinniped) offer richer features, including group-based RBAC mapping, SSO, and advanced security controls; webhook solutions have a narrower focus and limited support for group claims.

Choose the integration architecture that matches your security requirements and operational goals. Use only maintained, security-hardened tools with strict TLS enforcement, avoid ever using or storing LDAP passwords directly with kubectl, and stay informed on vulnerability advisories for your chosen bridge.

Up-to-date documentation and advisories from official project repositories provide the most accurate guidance—review them before and during your implementation.

Link to SourcesSources