Lesson 1 of 12 · The LDAP model
The LDAP model — DIT, DN, object classes, schemas and LDIF
Objective
Understand how an LDAP directory organizes its information, be able to name any entry by its DN, and write by hand the LDIF files used to populate and modify a directory.
Key points
- A directory is a database optimized to be read very often (who is this user? which group are they in?) and modified rarely.
- The entries form a tree, the DIT (Directory Information Tree). The root carries the domain name:
dc=masterlinux,dc=lab. - Each entry has a unique name, the DN (Distinguished Name), which is read from the leaf to the root:
uid=dev,ou=people,dc=masterlinux,dc=lab. - Object classes (
objectClass) decide which attributes are required (MUST) and allowed (MAY). They are defined in schemas. - LDIF is the text format of the directory: you use it to import, export and modify.
1. Why a directory?
The MasterLinux office in Lille has 40 Linux servers. With local accounts, a new administrator has to be created 40 times, and a departure forgotten on a single server leaves a door open. With a directory, the account exists once; the servers come and read it.
LDAP (Lightweight Directory Access Protocol) is the protocol used to talk to a directory, on port 389 (clear text or with StartTLS) or 636 (LDAPS, encrypted from the start of the connection). Several products speak it:
| Server | Where you meet it |
|---|---|
OpenLDAP (slapd) |
Debian, Ubuntu, hosting providers, appliances; the most widespread open-source one |
| 389 Directory Server | Red Hat's LDAP engine, at the heart of FreeIPA / IdM |
| Active Directory | Windows estates; it speaks LDAP and Kerberos |
The commands and the LDIF format in this course work with all three.
2. The DIT: a tree of names
dc=masterlinux,dc=lab ← root (the “suffix”)
├── ou=people ← organizational unit: people
│ ├── uid=admin
│ ├── uid=dev
│ └── ou=support
│ └── uid=support-toulouse
├── ou=groups
│ ├── cn=developpeurs
│ └── cn=admins
└── ou=services ← technical accounts (backup, applications)
└── uid=backup
The abbreviations to know:
| Abbreviation | Stands for | Example |
|---|---|---|
dc |
domain component | dc=masterlinux |
ou |
organizational unit | ou=people |
cn |
common name | cn=developpeurs |
uid |
user id (login name) | uid=dev |
o |
organization | o=MasterLinux |
3. DN and RDN
The RDN (Relative DN) is the name of the entry inside its folder: uid=dev. The DN adds all the parents up to the root:
uid=dev,ou=people,dc=masterlinux,dc=lab
└─RDN─┘ └────────── DN du parent ──────┘
- The DN is read from left (leaf) to right (root), the opposite of a file path. In the diagram above, the right-hand part is the parent's DN.
- Attribute names are not case-sensitive (
UID=dev=uid=dev); for values, it depends on the attribute (uidis not,userPasswordis). - A comma inside a value is escaped:
cn=Support\, Nantes,ou=groups,…. - The RDN must be an attribute that is present in the entry: an entry
uid=dev,…necessarily containsuid: dev.
4. Object classes, attributes and schemas
An entry is not a bag of free-form attributes. Each objectClass states what is required and what is allowed:
| Class | Type | Required (MUST) | Used for |
|---|---|---|---|
inetOrgPerson |
STRUCTURAL | cn, sn |
a person: mail, telephoneNumber, displayName… |
posixAccount |
AUXILIARY | cn, uid, uidNumber, gidNumber, homeDirectory |
the Linux account: loginShell, gecos |
shadowAccount |
AUXILIARY | uid |
the equivalent of /etc/shadow: shadowLastChange, shadowMax |
posixGroup |
STRUCTURAL | cn, gidNumber |
a Linux group; members listed with memberUid |
groupOfNames |
STRUCTURAL | cn, member |
a group whose members are DNs |
organizationalUnit |
STRUCTURAL | ou |
a “folder” |
An entry has exactly one STRUCTURAL class (what it is) and as many AUXILIARY classes as needed (added “capabilities”).
Classes and attributes are defined in schemas. On OpenLDAP, the most used ones are:
| Schema | Provides |
|---|---|
core |
organizationalUnit, dcObject, basic attributes (always loaded) |
cosine |
historical attributes (uid, mail…) |
inetorgperson |
inetOrgPerson (depends on cosine) |
nis |
posixAccount, shadowAccount, posixGroup (RFC 2307) |
# List the schemas loaded on an OpenLDAP server (local root access)
ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=schema,cn=config dn
# dn: cn=schema,cn=config
# dn: cn={0}core,cn=schema,cn=config
# dn: cn={1}cosine,cn=schema,cn=config
# dn: cn={2}nis,cn=schema,cn=config
# dn: cn={3}inetorgperson,cn=schema,cn=config
If you add an entry without a required attribute, the server answers for example ldap_add: Object class violation (65) additional info: object class 'posixAccount' requires attribute 'homeDirectory'.
memberUid or member?
Two ways of describing the members of a group coexist:
- RFC 2307 (
nisschema):posixGroup+memberUid: dev— a plain name; this is the OpenLDAP default on Debian. - RFC 2307bis /
groupOfNames:member: uid=dev,ou=people,dc=masterlinux,dc=lab— a full DN; this is the model used by FreeIPA and Active Directory, and it allows nested groups.
SSSD can read both, but you have to tell it which one with ldap_schema = rfc2307 or rfc2307bis (lesson 3.1). Getting it wrong gives empty groups.
5. The LDIF format
An LDIF file is a series of entries separated by an empty line. Each entry starts with its dn: line.
# Comment: a line that starts with #
version: 1
dn: uid=admin,ou=people,dc=masterlinux,dc=lab
objectClass: inetOrgPerson
objectClass: posixAccount
uid: admin
cn: Administrateur
sn: Admin
mail: admin@masterlinux.lab
uidNumber: 10000
gidNumber: 10000
homeDirectory: /home/admin
loginShell: /bin/bash
Three rules that catch everyone out:
::= base64 value. A tool encodes any value that contains an accented character, starts with a space or contains a non-printable character:description:: w4lxdWlwZS…. Decode it withbase64 -d.- Folded lines. A line that is too long (more than 76 characters by default with
ldapsearch) continues on the next line, which starts with a space. Agrepon the full DN then fails. Join the lines first:ldapsearch -o ldif-wrap=no …orsed -e ':a;N;$!ba;s/\n //g'. - Parents first.
ldapaddprocesses the entries in file order:ou=peoplemust come beforeuid=dev,ou=people,…, otherwise you getNo such object (32).
# Decode a base64 attribute
echo 'w4lxdWlwZSBzdXBwb3J0IOKAlCBhZ2VuY2UgZGUgQ2FzYWJsYW5jYQ==' | base64 -d
# Équipe support — agence de Toulouse
# Join the folded lines, then isolate one entry (awk “paragraph” mode)
sed -e ':a;N;$!ba;s/\n //g' export.ldif | awk 'BEGIN{RS=""} /uidNumber: 10007/'
The same format is also used for modifications (changetype: modify): that is the next lesson.
6. Choosing numeric identifiers well
uidNumber and gidNumber are what the kernel really sees: they are what gets written to disk as the owners of files.
- Reserve a range that never overlaps local accounts: for example 10000 to 59999 for the directory (local Debian/Rocky accounts start at 1000).
- Never reuse a freed
uidNumber: the files of the former owner would belong to the new one. - The same
uidNumberon two entries = two people sharing the same files. A simple check:getent passwd | awk -F: '{print $3}' | sort | uniq -d.
By version
| Item | Debian 12 | Debian 13 | Ubuntu 24.04 | Rocky 9 |
|---|---|---|---|---|
| Server package | slapd (OpenLDAP 2.5) |
slapd (OpenLDAP 2.6) |
slapd (OpenLDAP 2.6) |
openldap-servers from the plus repository (not enabled by default) |
| Client tools | ldap-utils |
ldap-utils |
ldap-utils |
openldap-clients |
| Directory offered by the vendor | OpenLDAP | OpenLDAP | OpenLDAP | 389 Directory Server / FreeIPA |
| Schemas loaded at installation | core, cosine, nis, inetorgperson | same | same | core only (the others must be loaded) |
Red Hat has not shipped the OpenLDAP server since RHEL 8 (the clients remain). On Rocky, you therefore install either openldap-servers from the plus repository, or FreeIPA (lesson 3.4).
Common pitfalls
- Searching for the full DN with
grepin a folded export: it is split across two lines. Use-o ldif-wrap=noor join the lines. - Forgetting the RDN attribute: the entry
uid=dev,…withoutuid: devis rejected (Naming violation). - Two unrelated STRUCTURAL classes (
inetOrgPerson+posixGroup): rejected. A person is not a group. - Mixing
memberUidandmemberfrom one group to another: clients that expect one do not see the other.
Lab
You prepare the import files for the MasterLinux directory, exactly as you would before a first ldapadd:
- the root and the two units
peopleandgroups, in the right order; - the Linux account
dev(person + POSIX account + shadow); - the group
developpeurs; - find a DN in an export with folded lines;
- decode a base64 attribute.
The lab container has no running LDAP server: you work on the files, which are the ones you would import on a real server with ldapadd -x -D cn=admin,dc=masterlinux,dc=lab -W -f base.ldif.
Quiz
- What does DN stand for, and in which direction is it read?
- What is the difference between a STRUCTURAL class and an AUXILIARY class?
- What does
description::(double colon) mean in an LDIF file? - Why must
ou=peopleappear beforeuid=dev,ou=people,…in an imported file? - One group uses
memberUid, another usesmember. Which one follows RFC 2307?
Answers
- Distinguished Name, the unique name of an entry; it is read from the leaf (left) to the root (right).
- The STRUCTURAL class says what the entry is (only one per entry); an AUXILIARY class adds attributes (posixAccount adds uidNumber, homeDirectory…).
- The value is base64-encoded (accented characters, special characters, leading space).
ldapaddprocesses the entries in order and rejects an entry whose parent does not exist (No such object).memberUid(posixGroup, nis schema).membercontains DNs (RFC 2307bis, groupOfNames).