Concepts / Identity

Identity

LDAP and directories

Also called directory, OpenLDAP, slapd, Active Directory, DN, distinguished name, bind, simple bind, LDAPS, StartTLS, nslcd, pam_ldap

One central tree of people and groups, which every server asks at login instead of keeping its own accounts.

One tree that every server asks
One tree that every server asks

Each entry is named by its path in the tree, the DN. Servers keep no accounts of their own: at login they search the directory for the user and bind with the user's password.

LDAP is the protocol for asking a directory: one central tree of people and groups that servers consult at login instead of keeping accounts. Each entry is named by a DN, its path in the tree (uid=alice,ou=people,dc=example,dc=com). Clients search with a filter (ldapsearch) and bind to log in. A simple bind sends the password itself, readable on plain LDAP (TCP 389) unless StartTLS or LDAPS (TCP 636) wraps it.

How an LDAP login works, step by step

In the LDAP lab the directory (10.60.4.10, OpenLDAP slapd) holds the tree dc=pinecone,dc=lab. buildServer (.21) and wikiServer (.22) keep no passwords; people log in from the laptop (.30). LDAP v3 is RFC 4511, over TCP 389, or 636 for LDAPS.

  1. sshd hands the password to PAM. /etc/pam.d/sshd has auth required pam_ldap.so and account required pam_ldap.so, so both phases go to the directory, through nslcd.
  2. nslcd finds the entry. It searches from the base dc=pinecone,dc=lab for (&(objectClass=posixAccount)(uid=noor)) and gets the DN uid=noor,ou=people,dc=pinecone,dc=lab.
  3. It binds as noor. A BindRequest with that DN and the password (a simple bind, RFC 4513), inside TLS to port 636. The server compares it with the entry's userPassword, a salted {SSHA} hash, and answers BindResponse result 0 (success) or 49 (invalidCredentials). No server keeps a copy of the password.
  4. The account step checks authorization. On buildServer a pam_authz_search filter (&(objectClass=posixGroup)(cn=engineers)(memberUid=$username)) must find an entry, or PAM's account step says no, even with the right password.

Delete sanne's entry once, in the directory, and every server refuses her on the next login. Plain LDAP sends a simple bind readable on the wire; StartTLS (extended operation OID 1.3.6.1.4.1.1466.20037) upgrades port 389 to TLS first, and LDAPS uses TLS from the start on TCP 636 (TLS).

What it looks like on a Linux machine

ldapsearch reads the tree. -x is a simple bind (anonymous here), -LLL prints plain LDIF:

$ ldapsearch -x -LLL -H ldap://directory.lab -b dc=pinecone,dc=lab "(&(objectClass=posixGroup)(memberUid=sanne))" cn
dn: cn=engineers,ou=groups,dc=pinecone,dc=lab
cn: engineers

An anonymous search for a person returns what the access rules show anyone: no mail, and never userPassword. slapd's log (-d stats) records each bind with its security strength factor, ssf=0 for plain LDAP and ssf=256 over LDAPS:

$ grep -A1 'BIND dn="uid=noor' /var/log/slapd.log
Nov  2 10:20:00 directory slapd: conn=1002 op=0 BIND dn="uid=noor,ou=people,dc=pinecone,dc=lab" method=128
Nov  2 10:20:00 directory slapd: conn=1002 op=0 BIND dn="uid=noor,ou=people,dc=pinecone,dc=lab" mech=SIMPLE bind_ssf=0 ssf=0
Nov  2 10:20:00 directory slapd: conn=1002 op=0 RESULT tag=97 err=0 qtime=0.000019 etime=0.000149 text=
--
Nov  2 10:20:05 directory slapd: conn=1005 op=0 BIND dn="uid=noor,ou=people,dc=pinecone,dc=lab" method=128
Nov  2 10:20:05 directory slapd: conn=1005 op=0 BIND dn="uid=noor,ou=people,dc=pinecone,dc=lab" mech=SIMPLE bind_ssf=0 ssf=256
Nov  2 10:20:05 directory slapd: conn=1005 op=0 RESULT tag=97 err=0 qtime=0.000023 etime=0.000104 text=

A leaver is one file of changes, sent bound as the administrator:

$ ldapmodify -x -H ldaps://directory.lab -D cn=admin,dc=pinecone,dc=lab -w tidy-desk-31 -f /root/sanne-leaves.ldif
deleting entry "uid=sanne,ou=people,dc=pinecone,dc=lab"

modifying entry "cn=engineers,ou=groups,dc=pinecone,dc=lab"

What goes wrong, and how you see it

Wrong password, or wrong DN. ldap_bind: Invalid credentials (49). LDAP gives the same answer for a wrong password and a DN that does not exist, so check the DN with an anonymous search first.

The server is unreachable. ldap_sasl_bind(SIMPLE): Can't contact LDAP server (-1), exit 255. Every directory login on every server fails at once; check the address, port 389 or 636, and the firewall.

A search finds nothing. No such object (32) with a Matched DN: line means the base DN is wrong; the matched part is how far the server got down the tree.

Right password, still refused. sshd logs Access denied for user bea by PAM account configuration: authentication passed, the group search after it found nothing (authentication vs authorization). Add the user to the group in the directory.

Passwords on the wire. A capture on port 389 shows the bind password in clear. Use -ZZ (StartTLS, required) or ldaps://; a server without TLS set up answers StartTLS with Protocol error (2). A directory told to refuse clear binds (security simple_bind=128) answers them with Confidentiality required (13), and its log shows err=13.

Questions people ask

What port does LDAP use? TCP 389 for LDAP and StartTLS, TCP 636 for LDAPS. Active Directory adds the global catalog on 3268 and 3269.

LDAP vs Active Directory? LDAP is the protocol; Active Directory is Microsoft's directory service, which speaks LDAP for searches and binds and uses Kerberos for logins. OpenLDAP is a directory server too.

LDAP vs Kerberos? LDAP stores who people are and which groups they are in, and can check a password by binding. Kerberos proves identity with tickets, so the password is not sent to each server. Many networks use both, as AD does; single sign-on builds on them.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab