LDAP authentication requires an Enterprise Edition license.
Prerequisites
- Enterprise License - LDAP is an Enterprise-only feature
- LDAP Server - Active Directory, OpenLDAP, FreeIPA, etc.
- Network Access - Dockhand must reach the LDAP server (port 389 or 636)
- Service Account (recommended) - For user/group searches
Configuration
1. Configure LDAP Provider
Navigate to Settings > Authentication > LDAP and click Add Configuration. Or via API:Configuration Fields
Display name for the LDAP provider (e.g., “Active Directory”, “OpenLDAP”)
Enable/disable this provider without deleting configuration
LDAP server URL with protocol and port.Examples:
ldap://dc.example.com:389(plain LDAP)ldaps://dc.example.com:636(LDAP over TLS)ldap://10.0.1.10:389
Service account DN for searching users/groups. Optional if allowing anonymous bind.Examples:
- Active Directory:
CN=Service Account,OU=Service Accounts,DC=example,DC=com - OpenLDAP:
cn=admin,dc=example,dc=com
Password for the service account (stored encrypted)
Base DN for user searches. All users must be under this DN.Examples:
DC=example,DC=comOU=Users,DC=example,DC=comou=people,dc=example,dc=org
LDAP filter to find users.
{{username}} is replaced with the login username.Common Filters:- Active Directory:
(sAMAccountName={{username}}) - OpenLDAP:
(uid={{username}}) - Email login:
(mail={{username}}) - Multiple:
(|(uid={{username}})(mail={{username}}))
LDAP attribute containing the usernameCommon Values:
- Active Directory:
sAMAccountName - OpenLDAP:
uid - Email:
mail
LDAP attribute containing the email address
LDAP attribute containing the full nameCommon Values:
cn(common name)displayNamegivenName(first name only)
Base DN for group searches (required for role mappings)Examples:
OU=Groups,DC=example,DC=comou=groups,dc=example,dc=org
Custom LDAP filter for group membership checks. Available placeholders:
{{username}}- Login username{{user_dn}}- User’s distinguished name{{group}}- Group DN or name
(member={{user_dn}})(memberUid={{username}})
Group DN or name for admin access. Users in this group receive the Admin role.Examples:
- Full DN:
CN=Dockhand Admins,OU=Groups,DC=example,DC=com - Group name:
dockhand-admins(searches in groupBaseDn)
Map LDAP groups to Dockhand roles. JSON array of mappings.Example:
Use LDAP over TLS (LDAPS). Requires server certificate trust.
PEM-encoded CA certificate for TLS validation. If not provided, system CAs are used.
Testing Configuration
Test your LDAP connection before enabling:* as username).
Authentication Flow
1. User Submits Credentials
User enters username and password on the login page.2. Search for User DN
Dockhand binds with the service account and searches for the user:3. Bind as User
Dockhand attempts to bind as the found user DN with the provided password:4. Extract User Attributes
Dockhand extracts user information from the LDAP entry:5. Check Admin Group Membership
IfadminGroup is configured, check if the user is a member:
6. Process Role Mappings
For each configured role mapping, check group membership:7. Create/Update Local User
Dockhand creates or updates a local user account:8. Create Session
Dockhand creates a session and logs the user in:Active Directory Examples
Standard Configuration
With StartTLS
LDAPS (LDAP over SSL)
Allow Email Login
alice or [email protected].
OpenLDAP Examples
Standard Configuration
With posixGroup Schema
posixGroup schema uses memberUid (username) instead of member (DN).
Admin Role Assignment
Automatically grant admin access based on LDAP group membership:Group DN vs. Group Name
You can specify either:- Full DN:
CN=Dockhand Admins,OU=Groups,DC=example,DC=com(searches at that exact DN) - Group name:
dockhand-admins(searches ingroupBaseDn)
= and ,.
Role Mappings
Map LDAP groups to Dockhand roles:1. Create Roles
First, create roles in Dockhand (Settings > Roles):- Docker Admins (ID: 2) - Full access
- Docker Viewers (ID: 3) - Read-only access
- Dev Environment (ID: 4) - Access to dev environment only
2. Configure Role Mappings
Update LDAP config with role mappings:How It Works
When a user logs in:- Dockhand checks membership in each mapped group
- Assigns corresponding Dockhand roles
- Removes roles for groups user is no longer in
- Syncs roles on every login
Security Features
LDAP Injection Prevention
Dockhand escapes special characters per RFC 4515:Timing Attack Protection
Authentication failures use the same generic error message:TLS Certificate Validation
WhentlsEnabled: true and tlsCa is provided:
Troubleshooting
Connection Refused
Error:connect ECONNREFUSED
Solutions:
- Verify the LDAP server is reachable:
telnet dc.example.com 389 - Check firewall rules
- Ensure Docker network allows outbound LDAP
- Try IP address instead of hostname
Invalid Credentials (Service Account)
Error:InvalidCredentialsError
Solutions:
- Verify
bindDnformat matches your directory - Test bind with ldapsearch:
ldapsearch -x -D "$BIND_DN" -W -b "$BASE_DN" - Check service account password
- Ensure service account isn’t locked/expired
No Users Found
Error: Test returnsuserCount: 0
Solutions:
- Verify
baseDncontains users - Check
userFiltermatches your schema - Test search with ldapsearch:
Authentication Failed (User)
Error: User gets “Invalid username or password” Solutions:- Verify user exists in LDAP
- Check
userFilterfinds the user - Test bind as user:
- Ensure user account isn’t locked/disabled
Admin Role Not Assigned
Issue: User logs in but doesn’t have admin access. Solutions:- Verify
adminGroupis configured - Check user is a member of the group
- Verify
groupBaseDnif using group name (not full DN) - Test group membership search:
TLS/SSL Errors
Error:unable to verify the first certificate
Solutions:
- Provide CA certificate in
tlsCafield - Use full certificate chain if needed
- Test TLS with openssl:
Performance Tuning
Connection Pooling
Dockhand creates a new LDAP connection for each authentication. For high-traffic deployments, consider:- Read replica - Point
serverUrlto a read-only domain controller - Load balancer - Distribute across multiple LDAP servers
- Local caching - Use SSSD or nscd on the Docker host
Search Optimization
- Narrow baseDn - Search only the OU containing users
- Indexed attributes - Ensure
sAMAccountName/uidis indexed - Limit group checks - Only map essential groups to roles
Source Code Reference
src/lib/server/auth.ts:488-757- LDAP authentication logicsrc/routes/api/auth/ldap/+server.ts- CRUD endpointssrc/routes/api/auth/ldap/[id]/test/+server.ts- Connection testingsrc/lib/server/db/schema/pg-schema.ts:205-225- Database schema
Next Steps
RBAC
Configure role-based access control
OIDC/SSO
Add SSO for non-LDAP users
Local Users
Manage fallback admin accounts
Two-Factor Auth
Add 2FA for local admin accounts
