Pcornel
Browse topics
Options
Recent
Favorites
Identity · Technical reference

LDAP

Direct answer

LDAP is the protocol clients use to read and change entries in a directory (Active Directory, OpenLDAP, 389 Directory Server): bind to authenticate, then search, compare or modify entries addressed by distinguished name.

When to use this

Use it when an application, appliance or Linux host authenticates users or reads groups from a directory, or when you need to query AD attributes directly.

First 30 seconds

1. Can the client resolve and reach the server on 389/636 (or 3268/3269)?

2. Does the bind succeed with the intended identity (result code 0)?

3. Is the base DN and scope right for where the object lives?

4. Does the filter match the attribute names and syntax the server uses?

5. For TLS: does the client trust the issuing CA and does the name match?

Operational verification

name resolution → TCP 389/636 → TLS (LDAPS or StartTLS) → bind (simple or SASL) → search (base DN, scope, filter, attributes) → result code and entries → application maps attributes/groups

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Protocol per RFC 4510–4519; examples use OpenLDAP client tools against Active Directory.
Applicability is projected only from persisted Topic profile and Command metadata.
At a glance

Operational reference

Fast context before you go deeper.

PlatformProtocol per RFC 4510–4519; examples use OpenLDAP client tools against Active Directory.
Scope / prerequisiteUse it when an application, appliance or Linux host authenticates users or reads groups from a directory, or when you n…
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Read-only Verification Verify boundary

Verify in order: transport, bind, then search.

# 1. RootDSE (anonymous, base scope): naming contexts and SASL mechanisms
ldapsearch -H ldap://dc1.corp.example.com -x -s base -b "" defaultNamingContext supportedSASLMechanisms

# 2. Bind over LDAPS with the application's identity and find one user
ldapsearch -H ldaps://dc1.corp.example.com:636 -D "svc-ldap@corp.example.com" -W \
  -b "DC=corp,DC=example,DC=com" "(sAMAccountName=anna)" dn memberOf userAccountControl

# 3. Kerberos (GSSAPI) bind after kinit; no password on the wire
kinit anna@CORP.EXAMPLE.COM
ldapsearch -H ldap://dc1.corp.example.com -Y GSSAPI -b "DC=corp,DC=example,DC=com" "(sAMAccountName=anna)" dn

# 4. Certificate presented by LDAPS
openssl s_client -connect dc1.corp.example.com:636 -servername dc1.corp.example.com </dev/null | openssl x509 -noout -subject -issuer -dates
ResultWhat it tells you
result: 0 Success with entriesBind, base DN, scope and filter are correct
result: 0 Success, numEntries absentSearch worked but nothing matched — check base DN, scope and attribute names
ldap_bind: Invalid credentials (49)Wrong DN/UPN or password; AD adds a data 52e (bad password) or data 775 (locked) sub-code
Strong(er) authentication required (8)Server requires signing or TLS — use ldaps:// or GSSAPI
Can't contact LDAP server (-1)Name, port, firewall or TLS trust failure

The AD sub-codes in error 49 (52e, 525, 530, 531, 532, 533, 701, 773, 775) identify the account condition and are the quickest way to separate a typo from a locked or expired account.

Step 2 Common mistakes Narrow the fault
  • Simple binds on port 389 without TLS — the password crosses the network in cleartext.
  • Binding as a domain administrator from an application; use a read-only service identity.
  • Pointing the application at a single DC by IP — no failover and no certificate name match.
  • Treating a successful bind as authorization; the directory ACL and the application's group mapping still decide access.
  • Forgetting paging, so large directories appear to "lose" users after 1000 results.
  • Assuming memberOf includes nested and primary groups.
Step 3 Troubleshooting Narrow the fault

The application says "LDAP unavailable". Test from the application host, not your workstation: name resolution, TCP to 389/636, then openssl s_client for TLS. A TLS failure is usually trust (the client lacks the issuing CA) or name mismatch (connecting by IP or an alias not in the certificate).

Bind fails with 49. Read the AD sub-code. 52e is a bad password; 775 locked; 532 expired password; 773 must change at next logon; 533 disabled. A service account with an expired password is the classic cause after months of working fine.

Bind fails with 8 after hardening. The client uses a simple bind on 389 or SASL without signing. Move it to LDAPS or StartTLS, or to a SASL mechanism with signing. Use events 2887/2889 to list remaining clients before enforcing.

User is found but group membership is missing. memberOf shows direct groups only and does not include the primary group (usually Domain Users). Use the in-chain matching rule for nested groups, or ask the application to evaluate groups by tokenGroups.

Search returns some but not all users. Check scope (one vs sub), the base DN (users outside that OU), referrals (the object is in another domain — use the Global Catalog on 3268/3269) and paging (results capped at the page size).

Works against one DC, fails against another. Replication delay, a DC without a valid certificate for LDAPS, or a firewall that only allows certain DCs.

Key points

Bind (who you are) and search (what you read) are separate steps. Base DN + scope + filter decide what is returned. Port 389 is cleartext unless StartTLS or signing protects it; 636 is LDAPS; AD Global Catalog is 3268/3269. Prefer TLS and SASL signing over simple binds on 389.

Key checks
  • ldapsearch -H ldaps://<dc>:636 -D <bind-dn> -W -b <base-dn> "(sAMAccountName=<user>)" dn memberOf — bind works and the entry is found.
  • ldapsearch -H ldap://<dc> -x -s base -b "" supportedSASLMechanisms supportedControl — read the RootDSE anonymously.
  • openssl s_client -connect <dc>:636 -showcerts </dev/null — the certificate the LDAPS listener presents.
  • Windows: Directory Service event 2887/2889 — clients still using unsigned binds.
ReferenceWhat it is2 sections · depth on demand

Direct Answer

LDAP (Lightweight Directory Access Protocol) is how clients talk to a directory. A client connects, binds to prove who it is, then searches for entries under a base DN using a scope and a filter, and reads the attributes it asked for. Active Directory, OpenLDAP and 389 Directory Server all speak it. In production, protect every bind with TLS (LDAPS on 636 or StartTLS on 389) or SASL signing; a simple bind on plain 389 sends the password in cleartext.

Scope and canonical references

This Topic owns the protocol: data model, operations, binds, search semantics, ports and client tooling.

ReferenceImportant terms & boundaries1 section · depth on demand

In depth

Data model

A directory is a tree (the DIT). Every entry has a distinguished name (DN) such as CN=Anna Berg,OU=Staff,DC=corp,DC=example,DC=com, made of relative DNs from the entry up to the naming context. An entry holds attributes; its objectClass values decide which attributes are allowed or required, as defined in the server's schema. Attribute names are case-insensitive, and each attribute has a syntax and matching rules that decide how comparisons in filters behave.

Operations (RFC 4511)

OperationPurpose
BindAuthenticate the connection (simple or SASL)
SearchRead entries under a base DN with scope, filter and attribute list
CompareTest one attribute value without reading it
Add / Delete / Modify / ModifyDNChange the directory
ExtendedE.g. StartTLS, password modify, Who am I?
Unbind / AbandonClose the session / cancel an operation

Every response carries a result code: 0 success, 32 noSuchObject (wrong base DN), 49 invalidCredentials, 50 insufficientAccessRights, 8 strongerAuthRequired (the server demands signing or TLS), 4 sizeLimitExceeded.

Binds

  • Anonymous — no credentials; servers usually allow only the RootDSE.
  • Simple — DN (or, in AD, UPN) and password sent as-is. Only acceptable inside TLS.
  • SASL — a mechanism such as GSSAPI (Kerberos), GSS-SPNEGO, EXTERNAL (TLS client certificate) or DIGEST-MD5. GSSAPI/SPNEGO can sign and seal the LDAP traffic without TLS.

RFC 4513 defines these methods and the TLS rules. A successful bind proves the credentials were accepted; it does not decide what the client may read — that is the server's access control.

Search

A search names a base DN, a scope (base = only that entry, one = direct children, sub = whole subtree), a filter (RFC 4515) and the attributes to return. Filters use prefix notation:

FilterMeaning
(uid=anna)Equality
(&(objectClass=user)(mail=*))AND; * means attribute present
(\|(cn=Anna*)(sn=Berg))OR with a substring match
(!(userAccountControl:1.2.840.113556.1.4.803:=2))AD: NOT disabled (bitwise AND rule)
(memberOf:1.2.840.113556.1.4.1941:=CN=App,OU=Groups,DC=corp,DC=example,DC=com)AD: member of the group, including nested groups

Large result sets need the paged results control; AD returns at most MaxPageSize (default 1000) entries per page and reports sizeLimitExceeded if the client does not page.

Ports and transport

PortUse
389/TCPLDAP; cleartext unless StartTLS or SASL signing/sealing is used
636/TCPLDAPS — TLS from the first byte
3268/TCPAD Global Catalog (partial forest-wide replica)
3269/TCPAD Global Catalog over TLS

StartTLS is an extended operation that upgrades a 389 connection to TLS; once negotiated it protects the same as LDAPS. Either way the client must trust the server certificate and the name it connects to must be in the certificate.

Active Directory signing and channel binding

AD controls unsigned binds with the policy Domain controller: LDAP server signing requirements and the client side with Network security: LDAP client signing requirements. With Require signing, the DC rejects SASL binds without signing and simple binds outside TLS. Before enforcing, find dependent clients: event 2887 summarises unsigned binds over 24 hours, and 2889 (with 16 LDAP Interface Events diagnostics set to 2) logs each client IP and account. Channel binding ties an LDAPS session to the TLS channel to stop relay; Microsoft documents it alongside signing (ADV190023 / KB4520412).

Bind accounts

Applications should bind with a dedicated account that can read only what they need, never a domain admin. Store its secret in a vault or use a managed identity mechanism where the client supports one; see Service Accounts.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
ldaplightweight directory access protocolldapsearchldap search filterldap bindstarttls ldap
Confirmation

Confirm action

Continue?