How LDAP Works: Directory Services, DIT Structure, and Active Directory

Lightweight Directory Access Protocol (LDAP) is a protocol for accessing and managing distributed directory information services over a network. If you have ever logged into a corporate laptop, had your email address auto-completed from a company directory, or been assigned to a security group that controls your application access, LDAP was almost certainly the underlying technology. Originally defined in RFC 1777 (1995) as a simpler alternative to the X.500 Directory Access Protocol, LDAP v3 (RFC 4511, 2006) has become the standard way to store and query identity information in enterprises. Active Directory, the backbone of most corporate IT environments, is fundamentally an LDAP directory with Microsoft-specific extensions.

What Is a Directory Service?

A directory service is a specialized database optimized for read-heavy, write-infrequent workloads. Unlike a general-purpose relational database, a directory is designed around a hierarchical data model, attribute-based queries, and distributed replication. Think of it as a phone book for an organization — you look up information far more often than you update it.

Directory services store identity information: user accounts, group memberships, email addresses, phone numbers, office locations, certificates, and anything else that describes people, devices, or resources in an organization. They provide a single source of truth that other systems query: email servers look up mailbox locations, RADIUS servers verify credentials, SAML Identity Providers retrieve user attributes, and applications check group memberships for authorization.

The Directory Information Tree (DIT)

LDAP organizes data in a hierarchical tree structure called the Directory Information Tree (DIT). Every entry in the directory has a unique position in this tree, identified by its Distinguished Name (DN).

LDAP Directory Information Tree (DIT) dc=example,dc=com ou=People ou=Groups ou=Services uid=jdoe cn=Jane Doe uid=bsmith cn=Bob Smith cn=engineering member: uid=jdoe,... cn=ldap-proxy Service account Distinguished Name (DN) for Jane Doe: uid=jdoe,ou=People,dc=example,dc=com uid=jdoe RDN (Relative DN) ou=People Org Unit dc=example Domain Component dc=com Domain Component

Naming: DN, RDN, and Common Attributes

Every LDAP entry is identified by its Distinguished Name (DN), which is the full path from the entry to the root of the tree, written with the most specific component first:

uid=jdoe,ou=People,dc=example,dc=com

Key naming components:

Schema and Object Classes

LDAP enforces data structure through a schema — a set of rules defining what attributes an entry can or must have. The schema is built from two components:

Object classes come in three types:

A typical user entry might use these object classes:

dn: uid=jdoe,ou=People,dc=example,dc=com
objectClass: top
objectClass: inetOrgPerson      # structural: cn, sn, mail, etc.
objectClass: posixAccount       # auxiliary: uidNumber, gidNumber, homeDirectory
objectClass: ldapPublicKey      # auxiliary: sshPublicKey
cn: Jane Doe
sn: Doe
givenName: Jane
uid: jdoe
mail: [email protected]
uidNumber: 1001
gidNumber: 1001
homeDirectory: /home/jdoe
loginShell: /bin/bash
userPassword: {SSHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=
sshPublicKey: ssh-ed25519 AAAA... jane@laptop

LDAP Operations

LDAP defines a set of operations that clients can perform:

Bind (Authentication)

The Bind operation authenticates the client to the directory. There are two types:

A common pattern is the bind-and-search authentication flow: an application binds as a service account, searches for the user by username, then attempts to bind as the found user's DN with the provided password. If the second bind succeeds, the password is correct.

# Step 1: Service account binds
BIND DN="cn=app-svc,ou=Services,dc=example,dc=com" Password="svc-secret"

# Step 2: Search for the user by username
SEARCH Base="ou=People,dc=example,dc=com" Filter="(uid=jdoe)"
# Result: DN="uid=jdoe,ou=People,dc=example,dc=com"

# Step 3: Attempt to bind as the user
BIND DN="uid=jdoe,ou=People,dc=example,dc=com" Password="user-provided-password"
# Success = correct password; Failure = wrong password

Search

The Search operation queries the directory. It takes several parameters:

Add, Modify, Delete, Modify DN

Compare and Extended Operations

LDAPS vs. StartTLS

LDAP supports two methods for TLS encryption:

Both provide the same level of encryption once established. LDAPS is simpler (no upgrade step) and is generally preferred in new deployments. StartTLS has a known downgrade vulnerability: if an attacker can strip the StartTLS command from the client's connection (a man-in-the-middle attack), the client may fall back to plaintext. To prevent this, clients should be configured to require StartTLS and fail if it is not available.

LDAPS vs. StartTLS LDAPS (port 636) 1. TCP connect to port 636 2. TLS handshake (immediate) 3. LDAP Bind (encrypted) 4. LDAP operations (encrypted) Everything encrypted from start StartTLS (port 389) 1. TCP connect to port 389 2. StartTLS extended op (plaintext!) 3. TLS handshake (upgrade) 4. LDAP Bind + operations (encrypted) Plaintext until step 3 completes

Active Directory: Microsoft's LDAP Implementation

Microsoft Active Directory (AD) is the world's most deployed LDAP-based directory. It serves as the authentication and authorization backbone for most enterprise Windows environments. AD uses LDAP as its primary access protocol, with several extensions:

AD also supports LDAP controls — extensions to standard LDAP operations. Important AD controls include paged results (for searches returning more than 1000 entries), server-side sorting, and the SD control (for retrieving security descriptors).

LDAP Replication

Production LDAP deployments use replication for high availability and geographic distribution. Two replication models exist:

Active Directory uses a multi-master replication model where all domain controllers accept writes. Replication is based on a change notification mechanism with configurable replication intervals (15 seconds within a site, 15 minutes or more between sites). AD uses Update Sequence Numbers (USNs) and a high-watermark vector to track which changes each replica has already received, preventing infinite replication loops.

LDAP Injection

Similar to SQL injection, LDAP injection occurs when user input is incorporated into LDAP search filters without proper sanitization. Consider an application that searches for a user like this:

filter = "(&(uid=" + username + ")(userPassword=" + password + "))"

An attacker who enters *)(uid=*))(|(uid=* as the username can manipulate the filter to bypass authentication. The resulting filter becomes:

(&(uid=*)(uid=*))(|(uid=*)(userPassword=anything))

Defenses include:

LDAP in Authentication Flows

LDAP rarely faces end users directly. Instead, it serves as the backend for other authentication protocols:

LDAP Performance and Indexing

LDAP servers must handle high query rates efficiently. Performance depends heavily on proper indexing:

Without proper indexes, LDAP searches degrade to full directory scans. On a directory with millions of entries, an unindexed search can take seconds instead of milliseconds — and the LDAP server may refuse the query entirely if it exceeds the configured time or size limits.

Security Best Practices

LDAP and Network Infrastructure

LDAP directories are critical infrastructure whose availability directly impacts authentication across the entire organization:

Relevant RFCs

See It in Action

Major LDAP and directory service providers operate on networks routed via BGP. Explore them using the god.ad BGP Looking Glass:

See BGP routing data in real time

Open Looking Glass
More Articles
How TLS/HTTPS Works: Securing the Internet's Traffic
Certificate Transparency: How CT Logs Secure the Web's PKI
How Firewalls Work: Packet Filtering, Stateful Inspection, and Beyond
What is Cross-Site Scripting (XSS)?
What is Cross-Site Request Forgery (CSRF)?
What is Server-Side Request Forgery (SSRF)?