The LDAP middleware for Goma Gateway provides secure authentication using LDAP (Lightweight Directory Access Protocol) servers with HTTP Basic Authentication. This middleware validates user credentials against your organization’s directory service and can forward authenticated user information to backend services.
Features
LDAP Authentication: Seamless integration with existing LDAP/Active Directory infrastructure
Built-in Rate Limiting: Protects LDAP servers from excessive authentication requests
Connection Pooling: Optimizes performance with configurable connection management
Username Forwarding: Passes authenticated usernames to backend services via headers
TLS Support: Secure connections with StartTLS and certificate validation options
Flexible User Filtering: Customizable LDAP queries for user authentication and authorization
How It Works
Client sends request with HTTP Basic Authentication credentials
Middleware extracts username/password from Authorization header
Establishes connection to LDAP server using configured bind credentials
Searches for user using the provided user filter
Attempts to bind with user’s credentials for authentication
On success, optionally forwards username to backend service
Rate limiting prevents abuse and protects LDAP infrastructure
Configuration
Basic Configuration
middlewares:-name:ldap-authtype:ldappaths:-/*rule:url:ldap://ldap.example.com:389# or use env ${ENV_NAME}baseDN:dc=example,dc=combindDN:uid=service-account,ou=people,dc=example,dc=combindPass:service_account_passworduserFilter:"(uid=%s)"
Complete Configuration Example
middlewares:-name:ldap-authtype:ldappaths:-/api/*-/admin/*rule:# Authentication Settingsrealm:"CompanyLDAP"# Authentication realm displayed in browserforwardUsername:true# Forward username to backend (default: false)# LDAP Server Configurationurl:ldaps://ldap.company.com:636# LDAP server URL (ldap:// or ldaps://)baseDN:dc=company,dc=com# Base DN for user searches# Service Account CredentialsbindDN:cn=gateway-service,ou=service-accounts,dc=company,dc=combindPass:secure_service_password# User Search ConfigurationuserFilter:"(&(objectClass=inetOrgPerson)(uid=%s)(memberOf=cn=gateway-users,ou=groups,dc=company,dc=com))"# TLS ConfigurationstartTLS:false# Use StartTLS for plain LDAP connectionsinsecureSkipVerify:false# Skip certificate verification (not recommended for production)# Performance OptimizationconnPool:size:10# Connection pool sizeburst:20# Rate limiting burst capacityttl:300s# Connection time-to-live
Configuration Parameters
Required Parameters
Parameter
Description
Example
url
LDAP server URL with protocol and port
ldap://ldap.example.com:389
baseDN
Base Distinguished Name for searches
dc=example,dc=com
bindDN
Service account DN for LDAP operations
cn=service,dc=example,dc=com
bindPass
Service account password
password123
userFilter
LDAP filter to locate users (%s = username)
(uid=%s)
Optional Parameters
Parameter
Type
Default
Description
realm
string
"LDAP Authentication"
Authentication realm name
forwardUsername
boolean
false
Forward username to backend in X-Forwarded-User header
startTLS
boolean
false
Upgrade plain connection to TLS
insecureSkipVerify
boolean
false
Skip TLS certificate verification
Connection Pool Configuration
Parameter
Type
Default
Description
connPool.size
integer
5
Number of connections to maintain
connPool.burst
integer
10
Maximum burst requests allowed
connPool.ttl
duration
60s
Connection lifetime before refresh
Common LDAP Filter Examples
Basic User Authentication
userFilter:"(uid=%s)"# Match by usernameuserFilter:"(sAMAccountName=%s)"# Active Directory usernameuserFilter:"(mail=%s)"# Match by email address
Group-Based Authorization
# Users must be members of specific groupuserFilter:"(&(uid=%s)(memberOf=cn=app-users,ou=groups,dc=example,dc=com))"# Multiple group membership (OR condition)userFilter:"(&(uid=%s)(|(memberOf=cn=admins,ou=groups,dc=example,dc=com)(memberOf=cn=developers,ou=groups,dc=example,dc=com)))"# Active Directory group membershipuserFilter:"(&(sAMAccountName=%s)(memberOf=CN=GatewayUsers,OU=SecurityGroups,DC=company,DC=com))"
Advanced Filters
# Exclude disabled accounts and require group membershipuserFilter:"(&(uid=%s)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(memberOf=cn=active-users,ou=groups,dc=example,dc=com))"# Multiple object classesuserFilter:"(&(|(objectClass=person)(objectClass=inetOrgPerson))(uid=%s))"