cd ../articles

System BTS SIO labs

An OpenLDAP directory with a web console (LDAP Account Manager)

Setting up slapd on Debian 13, designing a small directory tree, and putting LDAP Account Manager in front of it so accounts can be managed from a browser.

  • OpenLDAP
  • LAM
  • Apache
  • LDIF

After NIS, the modern way to centralise accounts: an OpenLDAP directory on Debian 13, a small and deliberate tree, and LDAP Account Manager (LAM) on top so accounts can be managed from a browser instead of hand-written LDIF.

Context

ContainerCT 104 openldap, unprivileged, Debian 13 (trixie)
Address192.168.1.104/24 on vmbr1
DirectoryOpenLDAP slapd 2.6
Web consoleLDAP Account Manager 9 on Apache + PHP 8.4
Base DNdc=home,dc=local

LDAP in two minutes

An LDAP directory is a tree of entries. Each entry has a unique DN (distinguished name) built from its path, for example uid=jdupont,ou=people,dc=home,dc=local, and a set of attributes defined by its object classes. Unlike NIS, it is extensible (mail, phone, groups, anything), it supports TLS, and almost every application can authenticate against it.

Installing slapd

apt update
DEBIAN_FRONTEND=noninteractive apt install -y slapd ldap-utils
dpkg-reconfigure slapd      # domain home.local, organisation, admin password

The result lives in the cn=config database, not in a text file:

olcSuffix: dc=home,dc=local
olcRootDN: cn=admin,dc=home,dc=local

Setting the admin password the LDAP way

The admin password is the olcRootPW attribute of the database entry. As root, through the local socket and SASL EXTERNAL, no password is needed to change it:

HASH=$(slappasswd)          # prompts, prints a {SSHA} hash
cat > /tmp/rootpw.ldif <<EOF
dn: olcDatabase={1}mdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: $HASH
EOF
ldapmodify -Y EXTERNAL -H ldapi:/// -f /tmp/rootpw.ldif
ldapwhoami -x -D "cn=admin,dc=home,dc=local" -W -H ldap://localhost

Designing the tree

Small and boring on purpose: one branch for people, one for groups.

openldap.svg
A small, deliberate directory tree
A small, deliberate directory tree
Text version
dc=home,dc=local
├── ou=people
│   └── uid=jdupont          Jean Dupont · uidNumber 10001
└── ou=groups
    └── cn=utilisateurs      posixGroup · gidNumber 10000
ldif/base.ldif (excerpt)
dn: ou=people,dc=home,dc=local
objectClass: organizationalUnit
ou: people

dn: cn=utilisateurs,ou=groups,dc=home,dc=local
objectClass: posixGroup
cn: utilisateurs
gidNumber: 10000

dn: uid=jdupont,ou=people,dc=home,dc=local
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: jdupont
cn: Jean Dupont
sn: Dupont
uidNumber: 10001
gidNumber: 10000
homeDirectory: /home/jdupont
loginShell: /bin/bash
userPassword: {SSHA}…

UIDs start at 10000 so directory users can never collide with local accounts (1000+) on a client. posixAccount is what makes the entry usable for a Linux login later.

ldapadd -x -D "cn=admin,dc=home,dc=local" -W -H ldap://localhost -f ldif/base.ldif
ldapsearch -x -D "cn=admin,dc=home,dc=local" -W -b "dc=home,dc=local" dn

LDAP Account Manager

DEBIAN_FRONTEND=noninteractive apt install -y ldap-account-manager
# pulls Apache, PHP 8.4 and php-ldap; serves the app under /lam

LAM 9 stores its configuration as JSON:

  • /etc/ldap-account-manager/config.cfg: global settings and master password
  • /var/lib/ldap-account-manager/config/lam.conf: the server profile

The default profile points at dc=my-domain,dc=com. Rather than click through every screen, I replaced the demo values and checked the JSON stayed valid:

F=/var/lib/ldap-account-manager/config/lam.conf
cp "$F" "$F.bak"
sed -i \
  -e 's|cn=Manager,dc=my-domain,dc=com|cn=admin,dc=home,dc=local|g' \
  -e 's|ou=People,dc=my-domain,dc=com|ou=people,dc=home,dc=local|g' \
  -e 's|ou=group,dc=my-domain,dc=com|ou=groups,dc=home,dc=local|g' \
  -e 's|dc=yourdomain,dc=org|dc=home,dc=local|g' "$F"
php -r 'json_decode(file_get_contents($argv[1])); echo json_last_error() ? "ERROR\n" : "OK\n";' "$F"
systemctl reload apache2
KeyValue
ServerURLldap://localhost:389
Adminscn=admin,dc=home,dc=local
typeSettings.suffix_userou=people,dc=home,dc=local
typeSettings.suffix_groupou=groups,dc=home,dc=local

The login page at http://192.168.1.104/lam then offers cn=admin,dc=home,dc=local, and users and groups can be created, edited and deleted from the browser.

Checks

systemctl is-active slapd apache2 && systemctl is-enabled slapd apache2
ss -tlnp | grep :389
curl -o /dev/null -w "%{http_code}\n" http://192.168.1.104/lam/     # 200

Before this could go anywhere near production

  • TLS: LDAPS on 636 or StartTLS, and useTLS forced in LAM. Plain LDAP sends bind passwords in clear.
  • HTTPS and access control on /lam: behind the reverse proxy, restricted to admin networks.
  • ACLs: olcAccess rules so users can read the directory and change only their own password.
  • Backups: slapcat -n 0 (config) and slapcat -n 1 (data), on a schedule.
  • Real passwords: the demo ones go, generated secrets in a password manager come in.

Useful commands

slapcat -n 0 > config.ldif          # export configuration
slapcat -n 1 > data.ldif            # export data
ldapmodify -x -D "cn=admin,dc=home,dc=local" -W -f change.ldif
ldapdelete -x -D "cn=admin,dc=home,dc=local" -W "uid=xxx,ou=people,dc=home,dc=local"
slappasswd                          # hash a password interactively

NIS vs. LDAP, after doing both

NISOpenLDAP
Data modelFlat maps copied from /etcExtensible tree, any attribute
EncryptionNoneTLS
Who uses itUnix clientsUnix, apps, mail, VPNs, SSO
Learning curveShortSteeper (cn=config, LDIF, ACLs)

NIS taught me what a directory has to do. LDAP is what I would actually deploy. Next on that path: an Authentik instance using this directory as a user source, for SSO across the homelab.