OpenLDAP ACLs, Password Policy (ppolicy) and Backups on AlmaLinux 10

OpenLDAP on AlmaLinux series, part 6 (final). Previous: part 5, SSSD LDAP client. Earlier parts: part 1 installed slapd with cn=config, part 2 added users and groups, part 3 enabled StartTLS and part 4 added a second server with syncrepl. This part covers who may read and change what (ACLs), password rules and lockout (the ppolicy overlay) and backups.

A directory that works is only half the job. Three questions decide whether it is safe to run: who can read and change which attributes, what stops people from using weak, reused or endlessly guessable passwords, and how you get everything back after a deleted entry, a dead disk or a bad change. This post answers them for the two-server lab from the previous parts: access control lists with olcAccess, the ppolicy overlay (loaded on both servers) with a cracklib password check, and slapcat backups with a tested restore.

It applies to AlmaLinux, RHEL, Rocky Linux, Oracle Linux and CentOS Stream 9 and 10 with OpenLDAP 2.6 (openldap-servers from EPEL on EL10, as in part 1). Every output below comes from OpenLDAP 2.6.13 built for AlmaLinux 10, run in a lab with the same two servers and the SSSD client from part 5. The “What was tested” section at the end lists exactly what was not.

What you will build

AreaResult
ACLsUsers change their own loginShell and gecos; members of sysadmins reset passwords and edit those attributes; ou=Services is hidden from everyone but the replicator; anonymous binds are refused
Password policyDefault policy: 12 characters minimum, three character classes and a cracklib check, history of 5, 90 day maximum age with 14 day warning and 3 grace logins, lockout for 15 minutes after 5 failures
Service accountsA separate policy for sssd-bind and replicator that never expires and never locks
BackupsA daily LDIF backup of cn=config and the data, and three tested restores: whole server, single entry, config only

Before you start: take a backup

You are about to change the access rules and load a new overlay on a working directory. Take a text backup of the configuration and the data on each server first. Part 1 mentioned slapcat; the full script is in the backup section below.

install -d -m 0700 /root/ldap-before
slapcat -n 0 -l /root/ldap-before/config.ldif
slapcat -b dc=example,dc=lan -l /root/ldap-before/data.ldif

Part A: Access control lists

How olcAccess works

The ACL list for a database is the multi-valued attribute olcAccess on its olcDatabase={2}mdb,cn=config entry. Each value is a rule of the form {n}to <what> by <who> <access> [<control>] by .... The rules are evaluated like this:

  • The list is ordered by the index {n}. slapd takes the first to clause that matches the entry and attribute being accessed and ignores the later ones, unless a by clause ends with break.
  • Inside that clause the by clauses are also read in order; the first one that matches the requester decides.
  • If no by clause matches, the answer is none.
  • Access levels, from the weakest: none, disclose, auth (may bind), compare, search, read, write, manage. Each level includes the ones before it.
  • Controls: stop (default, evaluation ends), continue (keep reading by clauses of this rule), break (go to the next to clause).
  • Who: self, users (anyone who authenticated), anonymous, * (everyone), dn.exact=, dn.children=, group and set expressions.
  • The rootDN (cn=admin,dc=example,dc=lan) is not subject to ACLs of its own database, and neither is root over ldapi:/// with -Y EXTERNAL for cn=config.

What the rules from parts 1 and 4 already do

ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b "olcDatabase={2}mdb,cn=config" -s base olcAccess
olcAccess: {0}to * by dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" read by * break
olcAccess: {1}to attrs=userPassword by self write by anonymous auth by * none
olcAccess: {2}to attrs=shadowLastChange by self write by users read by * none
olcAccess: {3}to * by users read by * none
  • {0} (part 4): the replication account reads everything. by * break means every other requester continues with the next rules instead of being stopped.
  • {1}: nobody but the owner can read or write userPassword. Anonymous may auth, which is what a bind needs; it does not allow reading the hash. Everyone else gets none.
  • {2}: users may change their own shadowLastChange; any logged-in user can read it.
  • {3}: the catch-all. Any authenticated user may read everything else; anonymous gets nothing.

Here is what that means in practice, from a lab run with real binds (StartTLS, -ZZ):

Requester and requestResult
Anonymous: search ou=PeopleNo such object (32) (the entries are not even disclosed)
sssd-bind: read uid, loginShell, userPassword of jdoeuid, loginShell, shadowLastChange returned; no userPassword
jdoe: read own entryincludes userPassword (the hash)
jdoe: read asmith’s entryuid, loginShell, shadowLastChange; no userPassword
jdoe: change own loginShellInsufficient access (50)
jdoe: list ou=Servicesreturns cn=sssd-bind and cn=replicator (not great: service accounts are visible to every user)

So the rules from part 1 already protect the hashes from sssd-bind. Two things are missing for a real site: users cannot change their own shell or GECOS name, and service account entries are visible. The next step fixes both and adds a delegated password reset for administrators.

Test ACLs with slapacl before you trust them

slapacl asks the server configuration what a given identity may do to an entry and attribute, without any network connection or password. Syntax: slapacl -b <entry DN> -D <requester DN> <attribute>/<access>. Run it as root on the server (with the default config directory on EL no -F is needed):

slapacl -b "uid=jdoe,ou=People,dc=example,dc=lan" \
        -D "cn=sssd-bind,ou=Services,dc=example,dc=lan" \
        userPassword/read loginShell/read uid/read
authcDN: "cn=sssd-bind,ou=services,dc=example,dc=lan"
read access to userPassword: DENIED
read access to loginShell: ALLOWED
read access to uid: ALLOWED

Use slapacl after every ACL change. The next sections show why: slapd accepts some wrong rules without complaint.

Add the new rules (on both servers)

Save as 70-acl.ldif. It replaces rule {1} with a version that also lets members of the posixGroup sysadmins write passwords, and inserts two new rules. The group match uses a set expression because the groups from part 2 are posixGroup entries with memberUid (user names, not DNs), which the group clause cannot read. The expression user/uid & [cn=sysadmins,...]/memberUid is true when the requester’s own uid value appears in the group’s memberUid values.

dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {1}
-
add: olcAccess
olcAccess: {1}to attrs=userPassword
  by self write
  by set="user/uid & [cn=sysadmins,ou=Groups,dc=example,dc=lan]/memberUid" write
  by anonymous auth
  by * none
-
add: olcAccess
olcAccess: {3}to attrs=loginShell,gecos
  by self write
  by set="user/uid & [cn=sysadmins,ou=Groups,dc=example,dc=lan]/memberUid" write
  by users read
  by * none
-
add: olcAccess
olcAccess: {4}to dn.subtree="ou=Services,dc=example,dc=lan"
  by * none

Apply it on ldap1 and on ldap2. The cn=config tree is not replicated by the syncrepl setup from part 4, so every ACL change has to be made twice:

ldapmodify -Y EXTERNAL -H ldapi:/// -f 70-acl.ldif      # on ldap1
ldapmodify -Y EXTERNAL -H ldapi:/// -f 70-acl.ldif      # on ldap2

Result on both servers (verified with ldapsearch on each):

olcAccess: {0}to * by dn.exact="cn=replicator,ou=Services,dc=example,dc=lan" read by * break
olcAccess: {1}to attrs=userPassword by self write by set="user/uid & [cn=sysadmins,ou=Groups,dc=example,dc=lan]/memberUid" write by anonymous auth by * none
olcAccess: {2}to attrs=shadowLastChange by self write by users read by * none
olcAccess: {3}to attrs=loginShell,gecos by self write by set="user/uid & [cn=sysadmins,ou=Groups,dc=example,dc=lan]/memberUid" write by users read by * none
olcAccess: {4}to dn.subtree="ou=Services,dc=example,dc=lan" by * none
olcAccess: {5}to * by users read by * none

Rule {4} sits before the catch-all {5} on purpose. Rule {0} comes first, so the replication account still reads ou=Services (and the userPassword rule {1} still lets the service accounts bind, because it matches the attribute before {4} is reached). Now verify with slapacl:

# members of sysadmins (asmith) versus a normal user (bjones), both acting on jdoe
slapacl -b "uid=jdoe,ou=People,dc=example,dc=lan" -D "uid=asmith,ou=People,dc=example,dc=lan" \
        userPassword/write loginShell/write gecos/write uid/write
write access to userPassword: ALLOWED
write access to loginShell: ALLOWED
write access to gecos: ALLOWED
write access to uid: DENIED

slapacl -b "uid=jdoe,ou=People,dc=example,dc=lan" -D "uid=bjones,ou=People,dc=example,dc=lan" \
        userPassword/write loginShell/write gecos/write uid/write
write access to userPassword: DENIED
write access to loginShell: DENIED
write access to gecos: DENIED
write access to uid: DENIED

# jdoe on his own entry
write access to userPassword: ALLOWED
write access to loginShell: ALLOWED
write access to uid: DENIED
write access to shadowLastChange: ALLOWED

# who can read the service account entry
slapacl -b "cn=sssd-bind,ou=Services,dc=example,dc=lan" -D "uid=jdoe,ou=People,dc=example,dc=lan" entry/read
read access to entry: DENIED
slapacl -b "cn=sssd-bind,ou=Services,dc=example,dc=lan" -D "cn=sssd-bind,ou=Services,dc=example,dc=lan" entry/read
read access to entry: DENIED
slapacl -b "cn=sssd-bind,ou=Services,dc=example,dc=lan" -D "cn=replicator,ou=Services,dc=example,dc=lan" entry/read
read access to entry: ALLOWED

The same checks with real binds:

# jdoe changes his own shell: allowed now, and the change shows up on ldap2 two seconds later
ldapmodify -x -ZZ -H ldap://ldap1.example.lan -D uid=jdoe,ou=People,dc=example,dc=lan -W
...
ldapsearch -x -ZZ -LLL -H ldap://ldap2.example.lan -D cn=sssd-bind,ou=Services,dc=example,dc=lan -W \
   -b uid=jdoe,ou=People,dc=example,dc=lan -s base loginShell
loginShell: /bin/sh

# jdoe lists ou=Services
No such object (32)

# asmith (sysadmin) resets bjones, then bjones tries the same on jdoe
ldappasswd -x -ZZ -H ldap://ldap1.example.lan -D uid=asmith,ou=People,dc=example,dc=lan -W \
   -s 'Bjones#Reset2026' uid=bjones,ou=People,dc=example,dc=lan            (rc=0)
ldappasswd -x -ZZ -H ldap://ldap1.example.lan -D uid=bjones,ou=People,dc=example,dc=lan -W \
   -s 'Hack#Test2026' uid=jdoe,ou=People,dc=example,dc=lan
Result: Insufficient access (50)

The lab servers listened on ports 3890 and 3891, so the lab commands carried the port; the commands above are written with the default port 389.

Refuse anonymous binds

Anonymous reading is already blocked by rule {5}, but servers still accept an anonymous bind and answer for the root DSE. A global option refuses the bind itself. It lives on the cn=config entry, so again apply it on both servers:

dn: cn=config
changetype: modify
add: olcDisallows
olcDisallows: bind_anon
ldapsearch -x -ZZ -LLL -H ldap://ldap1.example.lan -b dc=example,dc=lan -s base dn
ldap_bind: Inappropriate authentication (48)
	additional info: anonymous bind disallowed

Before the change the same command returned No such object (32). The SSSD client from part 5 binds with sssd-bind, so it is not affected; all SSSD tests later in this post ran with this option active.

ACL pitfalls, with the real messages

slapd checks the syntax of a new rule but not everything that can be wrong with it. These cases were tried on the lab server (and the changes undone):

What was sentWhat slapd saidLesson
{1}to attrs=loginShell by self reed by users readexpecting <access> got "reed"Typos in levels are caught
to attrs=loginShel by self writeunknown attr "loginShel" in to clauseAttribute names are checked against the schema
by selff writeexpecting <access> got "selff"The message names the word it choked on, not the word before it
add: olcAccess with index {9} when only four rules existAccepted; the rule was appended at the end of the listAn out-of-range index does not fail, it appends. A rule after your catch-all never runs
by set="user/uid &" write (broken set expression)Accepted (rc 0)Set expressions are not validated when you load them. Test with slapacl
delete: olcAccess with a value that does not existNo such attribute (16)Count the rules first
The same ldapmodify as cn=admin over the network instead of -Y EXTERNALInsufficient access (50)cn=config is writable only by root over ldapi:/// (part 1)

Delete rules by index, highest index first, so the numbers do not shift under you: delete: olcAccess with the value {5} removes the rule currently at that position. The two accepted bad rules above were removed that way, and a slapacl run confirmed the original four.

Part B: Password policy with the ppolicy overlay

The ppolicy overlay implements the IETF password policy draft. It watches binds and password changes and enforces length, history, age, lockout and grace logins. The rules live in policy entries in the directory; the overlay decides which entry applies to a user.

Step 1: load the module on both servers

The module goes into the same cn=module{0},cn=config entry that holds dynlist.la and syncprov.la (parts 2 and 4). The pwdPolicy schema is built into the module in OpenLDAP 2.6, so no schema LDIF has to be loaded. Save as 71-ppolicy-module.ldif:

dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: ppolicy.la

Step 2: add the overlay on both servers

Save as 72-ppolicy-overlay.ldif:

dn: olcOverlay=ppolicy,olcDatabase={2}mdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcPPolicyConfig
olcOverlay: ppolicy
olcPPolicyDefault: cn=default,ou=Policies,dc=example,dc=lan
olcPPolicyUseLockout: TRUE
olcPPolicyHashCleartext: TRUE
olcPPolicyCheckModule: /usr/lib64/openldap/check_password.so
ldapmodify -Y EXTERNAL -H ldapi:/// -f 71-ppolicy-module.ldif     # ldap1 and ldap2
ldapmodify -Y EXTERNAL -H ldapi:/// -f 72-ppolicy-overlay.ldif    # ldap1 and ldap2
SettingMeaning
olcPPolicyDefaultThe policy used for every user that has no pwdPolicySubentry. Without it (and without per-user entries) no policy is enforced at all.
olcPPolicyUseLockout: TRUEA bind to a locked account answers Invalid credentials (49) in all cases; with this option a client that sends the password policy control also learns Account locked. The man page warns that this helps an attacker, so decide per site. The tests below use TRUE because it makes the behaviour visible.
olcPPolicyHashCleartext: TRUEHash clear-text passwords that arrive through a plain add or modify instead of the password modify operation. Tested: a clear-text replace: userPassword was stored as {SSHA}... and the user could bind with the clear-text password. The man page recommends denying read access to the hashes to every user when this option is used; rule {1} above does that.
olcPPolicyCheckModulePath of a shared library with a check_password() function for extra quality checks. The openldap-servers package ships /usr/lib64/openldap/check_password.so (the LTB project cracklib checker) with its configuration in /etc/openldap/check_password.conf. A policy opts in with pwdUseCheckModule: TRUE.

If the path is wrong, the overlay is refused and nothing is half-configured. Sent with the path /usr/lib64/openldap/check_password.so on a host where that file did not exist, the server answered:

ldap_add: Other (e.g., implementation specific) error (80)
	additional info: <olcPPolicyCheckModule> lt_dlopen(/usr/lib64/openldap/check_password.so) failed: file not found

The overlay appears as olcOverlay={2}ppolicy, after dynlist and syncprov, on both servers.

Step 3: create the policies

Both servers have the module now, so the policy entries can replicate. If you add the entries first, a server without the module cannot parse them (see the restore section for the exact error). Save as 73-policies.ldif and add it on ldap1 only; syncrepl copies it:

dn: ou=Policies,dc=example,dc=lan
objectClass: organizationalUnit
ou: Policies

dn: cn=default,ou=Policies,dc=example,dc=lan
objectClass: top
objectClass: device
objectClass: pwdPolicy
objectClass: pwdPolicyChecker
cn: default
pwdAttribute: userPassword
pwdCheckQuality: 2
pwdMinLength: 12
pwdUseCheckModule: TRUE
pwdInHistory: 5
pwdMaxAge: 7776000
pwdExpireWarning: 1209600
pwdGraceAuthnLimit: 3
pwdLockout: TRUE
pwdMaxFailure: 5
pwdFailureCountInterval: 900
pwdLockoutDuration: 900
pwdAllowUserChange: TRUE
pwdMustChange: FALSE
pwdSafeModify: FALSE
ldapadd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W -f 73-policies.ldif

device is just a structural class with a cn; any structural class works, because pwdPolicy is auxiliary. The values, with the man page meaning:

AttributeValueMeaning
pwdAttributeuserPasswordRequired. The only accepted value
pwdCheckQuality2Check the syntax; refuse the password if it cannot be checked (for example a client-side hashed value). 1 would accept what it cannot check
pwdMinLength12Minimum length in bytes (not characters)
pwdUseCheckModuleTRUEAlso run check_password.so after the built-in checks. Needs olcPPolicyCheckModule
pwdInHistory5Remember the last five passwords in pwdHistory
pwdMaxAge777600090 days in seconds. 0 or absent: never expires
pwdExpireWarning1209600Warn during the last 14 days
pwdGraceAuthnLimit3Number of logins allowed with an expired password
pwdLockout, pwdMaxFailureTRUE, 5Lock after 5 consecutive failures
pwdFailureCountInterval900Failures older than 15 minutes are forgotten
pwdLockoutDuration900Locked for 15 minutes; 0 or absent means locked until an administrator unlocks
pwdAllowUserChange, pwdSafeModifyTRUE, FALSEUsers may change their own password; the old password need not be sent. The man page prefers ACLs to pwdAllowUserChange
pwdMustChangeFALSETRUE forces a change at the first bind after an administrator reset. Not used in the lab, see the note below

Existing passwords do not expire at once. Expiry is measured from pwdChangedTime, which is only written when the password is changed or reset. In the lab, jdoe (created in part 2) had no pwdChangedTime until the first change, and the man page states that without it the password does not expire.

Step 4: a policy for the service accounts

The default policy would also apply to sssd-bind and replicator. That is dangerous in two ways. Five wrong binds against sssd-bind (a typo in one client’s sssd.conf is enough) lock the account for every client. In the lab, five failures gave ldap_bind: Invalid credentials (49); Account locked even for the correct password. And once the account password is ever changed, pwdMaxAge would expire it after 90 days and take SSSD and replication down together. Create a policy that never locks or expires and attach it to both accounts with the operational attribute pwdPolicySubentry:

dn: cn=service,ou=Policies,dc=example,dc=lan
objectClass: top
objectClass: device
objectClass: pwdPolicy
cn: service
pwdAttribute: userPassword
pwdLockout: FALSE
pwdMaxAge: 0
pwdAllowUserChange: FALSE

dn: cn=sssd-bind,ou=Services,dc=example,dc=lan
changetype: modify
add: pwdPolicySubentry
pwdPolicySubentry: cn=service,ou=Policies,dc=example,dc=lan

dn: cn=replicator,ou=Services,dc=example,dc=lan
changetype: modify
add: pwdPolicySubentry
pwdPolicySubentry: cn=service,ou=Policies,dc=example,dc=lan

(Add the policy entry with ldapadd and the two assignments with ldapmodify, as cn=admin, on ldap1.) After the change eight wrong binds against sssd-bind left it usable: ldapwhoami with the right password on ldap2 answered dn:cn=sssd-bind,ou=Services,dc=example,dc=lan, and both servers showed the assignment.

Step 5: test the quality rules

Use ldappasswd as the user, so the policy applies. (The rootDN bypasses most checks, see below.) -a gives the old password, -s the new one. Each result is from the lab:

New passwordResultWhy
Sh0rt#1Constraint violation (19), Additional info: Password fails quality checking policyShorter than 12
xK9mq2Lw7v! (11 characters, three classes)same messageShorter than 12 (the built-in check runs first)
Password1234!same messagecracklib: “it is based on a dictionary word”
abcdefghijklmnopsame messageOne character class, below minPoints 3; cracklib also says “too simplistic/systematic”
123456789012345same messageOne character class
xK9mq2Lw7vTz (12 characters, upper, lower, digit)successPasses
The previous password againConstraint violation (19), Additional info: Password is in history of old passwordspwdInHistory 5

After a successful change the user entry carries a pwdChangedTime value and one more pwdHistory value per stored password. The history values hold the hash, so protect them like userPassword (rule {1} covers only userPassword; the catch-all {5} lets any user read other attributes of an entry, so consider adding pwdHistory to the protected attributes on a site where that matters). After five changes the lab entry held exactly five pwdHistory values. Note that an administrator reset is also recorded in the history.

The client only sees the generic message. The slapd log line for a rejection by the module reads check_password_quality: module error: (/usr/lib64/openldap/check_password.so) .[1]: it names the module but, in the lab, gave no reason. To find out why a password was refused, run it through cracklib-check (from the cracklib package, a dependency of openldap-servers) and compare with the character class rules:

for p in 'Password1234!' 'abcdefghijklmnop' 'xK9mq2Lw7vTz'; do echo "$p" | cracklib-check; done
Password1234!: it is based on a dictionary word
abcdefghijklmnop: it is too simplistic/systematic
xK9mq2Lw7vTz: OK

The module reads /etc/openldap/check_password.conf. The shipped file has every line commented out, so the defaults apply: useCracklib 1 and minPoints 3 (one point per character class used: lower, upper, digit, punctuation). Uncomment minUpper, minDigit and so on to require a number of characters of one class. The cracklib check needs the word list under /usr/share/cracklib/ (package cracklib-dicts, installed with cracklib); the module README says that with an unreadable word list the cracklib part is skipped silently. In the lab the first password-quality run was done by accident without the word list visible to the module, and the cracklib part was silently skipped; with the list in place, dictionary words were refused. Check with a known bad password after every OS upgrade.

The README of the module also warns that runtime errors in it may bring down slapd, and that it should be used at your own risk. It is a small, old third-party module that ships with the package; test it on a replica before production, and keep the built-in checks (pwdMinLength) in place so the policy still has teeth if you disable the module.

The rootDN bypasses the policy

The man page says some policies do not apply to the rootDN, and it showed: ldappasswd as cn=admin set the password abc on a user without complaint, while the same request from asmith (a member of sysadmins, with write access through rule {1}) was refused with Password fails quality checking policy. So do routine resets as a named administrator account, not as cn=admin. A requester with manage access to userPassword is treated as a password administrator by ppolicy “where relevant” according to the man page; that variant was not tested, which is why rule {1} grants write.

Step 6: test lockout and unlock

Five wrong passwords for jdoe were sent to ldap2. Each returned Invalid credentials (49). Then the operational attributes looked like this on ldap2, and, two seconds later, identically on ldap1:

ldapsearch -x -ZZ -LLL -H ldap://ldap2.example.lan -D cn=admin,dc=example,dc=lan -W \
   -b uid=jdoe,ou=People,dc=example,dc=lan -s base pwdAccountLockedTime pwdFailureTime
dn: uid=jdoe,ou=People,dc=example,dc=lan
pwdFailureTime: &lt;timestamp&gt;   (five values)
pwdAccountLockedTime: &lt;timestamp&gt;

The failure counters were written on ldap2 and replicated to ldap1, because both servers run as providers (part 4, multi-provider) and both have the overlay. A lock earned on one server is therefore honoured by the other, so an attacker cannot get five more guesses by switching servers. The man page notes that on a plain consumer authentication failures normally affect only that server’s copy; for a read-only consumer behind a provider the overlay has ppolicy_forward_updates (needs updateref and the chain overlay). That setup was not tested here.

With the correct password while locked, the answer depends on whether the client sends the password policy control (ldapwhoami -e ppolicy does):

ldapwhoami -e ppolicy -x -ZZ -H ldap://ldap1.example.lan -D uid=jdoe,ou=People,dc=example,dc=lan -W
ldap_bind: Invalid credentials (49); Account locked

ldapwhoami -x -ZZ -H ldap://ldap2.example.lan -D uid=jdoe,ou=People,dc=example,dc=lan -W
ldap_bind: Invalid credentials (49)

Unlocking. Delete pwdAccountLockedTime. Trying to delete pwdFailureTime in the same request fails, because it is a no-user-modification attribute:

dn: uid=jdoe,ou=People,dc=example,dc=lan
changetype: modify
delete: pwdAccountLockedTime
-
delete: pwdFailureTime

ldap_modify: Constraint violation (19)
	additional info: pwdFailureTime: no user modification allowed

Send only the first change. After that, the next successful bind clears the failure times by itself; in the lab both servers showed no pwdAccountLockedTime and no pwdFailureTime afterwards. Without an administrator, the lock ends by itself after pwdLockoutDuration.

Per-user policies, expiry and grace logins

A user entry can name its own policy in pwdPolicySubentry. To see lockout expiry and password aging in seconds instead of weeks, the lab used a short-lived test policy on bjones. Do not use these values in production:

dn: cn=lab-short,ou=Policies,dc=example,dc=lan
objectClass: top
objectClass: device
objectClass: pwdPolicy
cn: lab-short
pwdAttribute: userPassword
pwdLockout: TRUE
pwdMaxFailure: 2
pwdLockoutDuration: 10
pwdMaxAge: 12
pwdExpireWarning: 8
pwdGraceAuthnLimit: 2

Results (ldapwhoami -e ppolicy, times from the lab):

What happenedOutput
Two wrong passwords, then the right oneThe account was locked (Invalid credentials (49); Account locked), and it unlocked on its own after the 10 seconds
Right password shortly before expirySuccess (0) (Password expires in 6 seconds)
First bind after pwdMaxAgeSuccess (0) (Password expired, 1 grace logins remain)
Second bindSuccess (0) (Password expired, 0 grace logins remain)
Third bindInvalid credentials (49); Password expired

The entry recorded each grace login in pwdGraceUseTime. The user has to get the password changed by an administrator or, with grace logins left, change it themselves. The lab policy was removed again afterwards.

pwdMustChange: TRUE (force a change after an administrator reset) was not tested. It restricts what a user may do until the password is changed, so check how your clients handle it before enabling it for the default policy.

What SSSD does with a locked account

Five wrong passwords through sssctl user-checks locked jdoe on the server, and then the right password returned pam_authenticate for user [jdoe]: Authentication failure. The account phase still said pam_acct_mgmt: Success with the default access provider, which matters for ssh key logins because they skip the password check. To deny the account phase as well, use the ppolicy access order from part 5:

[domain/LDAP]
access_provider = ldap
ldap_access_order = ppolicy
ldap_pwdlockout_dn = cn=default,ou=Policies,dc=example,dc=lan

ldap_pwdlockout_dn is not optional unless your policy is named exactly like the SSSD default. Without it SSSD looks for cn=ppolicy,ou=policies,<search base>. In the lab, with the policy named cn=default, the account check passed for a locked user and the debug log (level 8) said:

ldap_pwdlockout_dn was not defined in configuration file.
Trying to find out if ppolicy is enabled using the DN: cn=ppolicy,ou=policies,dc=example,dc=lan
[pwdLockout] was not found. Granting access.
Password policy is disabled on LDAP server - storing 'access granted' in sysdb.

With ldap_pwdlockout_dn set, the locked user was denied, and after the unlock (and sss_cache -E) allowed again:

sssctl user-checks -a acct -s sshd jdoe          (locked)
pam_acct_mgmt: Permission denied
Access denied by online lookup - account is locked.          (sssd_LDAP.log)

sssctl user-checks -a acct -s sshd jdoe          (after unlock and sss_cache -E)
pam_acct_mgmt: Success

Two limits of that test: the lab ran the PAM checks with a service file containing only pam_sss.so, and changing a password through SSSD (passwd on the client) could not be tested, because sssctl user-checks -a chau runs as root and SSSD answered Password reset by root is not supported. The server side of password changes was tested with ldappasswd above.

Part C: Backups and restores

What to back up

  • cn=config: modules, overlays, ACLs, TLS settings, the replication agreement. slapcat -n 0.
  • The data in the dc=example,dc=lan database: slapcat -b dc=example,dc=lan. This includes userPassword hashes and the ppolicy state.
  • Files outside the directory: the TLS certificates and keys in /etc/openldap/certs, the CA from part 3 (keep the CA key offline) and /etc/openldap/check_password.conf. These are plain files; copy them with your normal file backup.
  • Each server: the config is not replicated, so cn=config has to be saved on ldap1 and ldap2. The data of the two servers is the same; saving it on both costs little.

A copy of /var/lib/ldap/data.mdb taken while slapd is running is not a safe backup. slapcat is: the slapcat man page says it is always safe to run it with the mdb backend while slapd is running. The LDIF is also portable between versions, which a file copy is not.

A backup script

Save as /usr/local/sbin/ldap-backup.sh, mode 0750, owner root. It writes both LDIF files to a temporary name, checks that they contain entries, publishes them, compresses them and removes backups older than 14 days. The umask keeps the files private, because they contain password hashes.

#!/bin/sh
# /usr/local/sbin/ldap-backup.sh : LDIF backup of cn=config and the data database
set -eu
umask 077
BACKUP_DIR=${BACKUP_DIR:-/var/backups/openldap}
KEEP_DAYS=${KEEP_DAYS:-14}
SUFFIX=${SUFFIX:-dc=example,dc=lan}
SLAPCAT=${SLAPCAT:-/usr/sbin/slapcat}
SLAPD_D=${SLAPD_D:-/etc/openldap/slapd.d}
STAMP=$(date +%Y%m%d-%H%M%S)
mkdir -p "$BACKUP_DIR"
for part in config data; do
  case $part in
    config) set -- -n 0 ;;
    data)   set -- -b "$SUFFIX" ;;
  esac
  out="$BACKUP_DIR/$(hostname -s)-$part-$STAMP.ldif"
  "$SLAPCAT" -F "$SLAPD_D" "$@" -l "$out.tmp"
  # sanity check: at least one entry, then publish atomically
  n=$(grep -c '^dn:' "$out.tmp" || true)
  [ "$n" -gt 0 ] || { echo "backup of $part is empty" >&2; rm -f "$out.tmp"; exit 1; }
  mv "$out.tmp" "$out"
  gzip -9 "$out"
  echo "$part: $n entries -> $out.gz"
done
find "$BACKUP_DIR" -name '*.ldif.gz' -mtime +"$KEEP_DAYS" -delete

Output of a run on a lab server (the host name and directory are shortened here):

# /usr/local/sbin/ldap-backup.sh
config: 15 entries -> /var/backups/openldap/ldap1-config-20261126-022548.ldif.gz
data: 17 entries -> /var/backups/openldap/ldap1-data-20261126-022548.ldif.gz

ls -l /var/backups/openldap
-rw------- 1 root root 9523 ... ldap1-config-20261126-022548.ldif.gz
-rw------- 1 root root 2243 ... ldap1-data-20261126-022548.ldif.gz

The entry counts matched a live ldapsearch of the suffix (17 entries) and the file permissions are 0600. slapd was running during the backup. The password hashes are in the data file, so treat the backup as a secret: encrypt it before it leaves the server and keep the offsite copy under the same access rules as the directory.

To run it daily with systemd (standard unit syntax; these two units were not run in the lab):

# /etc/systemd/system/ldap-backup.service
[Unit]
Description=OpenLDAP LDIF backup

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/ldap-backup.sh

# /etc/systemd/system/ldap-backup.timer
[Unit]
Description=Daily OpenLDAP backup

[Timer]
OnCalendar=*-*-* 02:30:00
Persistent=true

[Install]
WantedBy=timers.target

systemctl daemon-reload
systemctl enable --now ldap-backup.timer

A backup you have never restored is a hope, not a backup. The following three restores were all done in the lab from the backup files above.

Restore 1: a whole server (config first, then data)

This is the procedure for a rebuilt or replaced server with the same packages installed and an empty /etc/openldap/slapd.d and data directory. Order matters: the data contains attributes defined by modules and schemas from the configuration. Loading the data into a server that lacks them fails. In the lab, loading the backup into a scratch server without the ppolicy module stopped at the first user entry:

slapadd -b dc=example,dc=lan -l data.ldif
<= str2entry: str2ad(pwdHistory): attribute type undefined
slapadd: could not parse entry

So restore the configuration first. The steps, with the checks that were run:

# stop slapd; make sure /var/lib/ldap exists, is empty and owned by ldap
systemctl stop slapd
zcat ldap1-config-20261126-022548.ldif.gz > /tmp/config.ldif
zcat ldap1-data-20261126-022548.ldif.gz   > /tmp/data.ldif

# 1. configuration (database 0 is always cn=config)
sudo -u ldap slapadd -n 0 -F /etc/openldap/slapd.d -l /tmp/config.ldif

# 2. data
sudo -u ldap slapadd -b dc=example,dc=lan -F /etc/openldap/slapd.d -l /tmp/data.ldif

# 3. verify before starting
slaptest -F /etc/openldap/slapd.d
config file testing succeeded
slapcat -b dc=example,dc=lan | grep -c '^dn:'
17
restorecon -Rv /etc/openldap /var/lib/ldap
systemctl start slapd

Notes from the test and the man pages:

  • Run slapadd as the ldap user (sudo -u ldap). The man page says all files slapadd creates belong to the user it runs as; as root they would be unreadable for slapd. If you did run it as root, chown -R ldap:ldap /etc/openldap/slapd.d /var/lib/ldap.
  • The lab restored into fresh directories, so the running lab servers were not touched. The restored configuration was checked with slaptest (config file testing succeeded), the list of DNs in the restored data was identical to the live server’s, and a restored slapd answered a StartTLS bind as jdoe and returned pwdMinLength: 12 from the policy entry.
  • The restored configuration still carries olcSecurity: ssf=1 from part 3, so connect with StartTLS (-ZZ). The certificate files named in the configuration must exist on the new host, which is why they belong in the file backup.
  • Do not use slapadd -w to restore a server that is part of a replication pair. The man page says it should only be used to load a fresh seed provider.
  • Replicas need no restore: if ldap2 is lost, build it as in part 4 with an empty database and let syncrepl fill it. If ldap1 is lost and ldap2 is healthy, you can instead re-create ldap1 and let it pull from ldap2 (multi-provider). Use the LDIF restore when no server is left, or when something wrong has already replicated everywhere.

Restore 2: one deleted entry

A deleted entry is deleted on both servers within seconds, which is why the replica does not count as a backup. In the lab, the entry for bjones was deleted with ldapdelete and the deletion replicates like any other change. The entry was recovered from the backup:

# 1. pull the entry out of the backup (paragraph mode: entries are separated by blank lines)
zcat ldap1-data-20261126-022548.ldif.gz | \
  awk -v RS= -v ORS='\n\n' '/^dn: uid=bjones,ou=People,/' > bjones.ldif

# 2. adding it as is fails
ldapadd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W -f bjones.ldif
ldap_add: Constraint violation (19)
	additional info: structuralObjectClass: no user modification allowed

# 3. drop the attributes the server maintains (and their wrapped continuation lines), then add
awk '/^ /{ if(!drop) print; next }
     { drop=($0 ~ /^(structuralObjectClass|entryUUID|creatorsName|createTimestamp|entryCSN|modifiersName|modifyTimestamp|pwdChangedTime|pwdHistory|pwdFailureTime|pwdAccountLockedTime|pwdGraceUseTime):/);
       if(!drop) print }' bjones.ldif > bjones.clean.ldif
ldapadd -x -ZZ -H ldap://ldap1.example.lan -D cn=admin,dc=example,dc=lan -W -f bjones.clean.ldif
adding new entry "uid=bjones,ou=People,dc=example,dc=lan"

The entry was back on ldap2 as well, and bjones could bind to ldap2 with the password he had before, because the hash is part of the entry. What does not come back is everything the server generates: a new entryUUID and entryCSN, and no pwdChangedTime or history. A restored account therefore does not expire until its password is changed. Group memberships live in the group entries (memberUid), so check those too if the group was changed after the backup.

Restore 3: only the configuration

If just cn=config was damaged (a broken ACL change, a bad overlay) and the data is fine, restore the configuration into an empty directory with slapadd -n 0 -F /tmp/newconfig -l config.ldif and check it with slaptest -F /tmp/newconfig. In the lab this printed config file testing succeeded. Then stop slapd, move the old slapd.d aside (do not delete it), put the new one in place with the right owner and SELinux labels, and start slapd. A smaller change is usually better repaired with ldapmodify; use the backup when you cannot tell what changed.

Troubleshooting

The messages marked with * come from the manual pages or the module README and were not reproduced; the others were produced in the lab.

Symptom or messageCauseFix
ldap_add: Other (e.g., implementation specific) error (80) and <olcPPolicyCheckModule> lt_dlopen(...) failed: file not foundThe path to check_password.so is wrongrpm -ql openldap-servers | grep check_password; use the absolute path
str2ad(pwdHistory): attribute type undefined or attribute type undefined for other pwd* names during slapadd; a consumer would fail the same way *The server loading the data lacks the ppolicy moduleLoad ppolicy.la on every server first; restore cn=config before the data
Password fails quality checking policy for a password that looks fineLength below pwdMinLength, too few character classes, or a cracklib dictionary or pattern hitTest with cracklib-check; the slapd log does not give the reason
Bad passwords are accepted although pwdUseCheckModule is TRUENo olcPPolicyCheckModule on this server, or the cracklib word list is missing (README: skipped silently)Check both servers; ls /usr/share/cracklib/pw_dict.*; test with Password1234!
Password is in history of old passwordspwdInHistoryChoose a new password. Administrator resets also count as history entries
Invalid credentials (49); Account locked with the right passwordToo many failures; pwdAccountLockedTime is set (visible with the admin bind)Delete pwdAccountLockedTime, or wait for pwdLockoutDuration
pwdFailureTime: no user modification allowed when unlockingThe attribute is maintained by the serverDelete only pwdAccountLockedTime; the next good bind clears the failures
Invalid credentials (49); Password expiredpwdMaxAge passed and the grace logins are used upAdministrator reset (or user change while grace logins remain)
SSSD keeps allowing a locked user to pass the account phaseldap_access_order = ppolicy without ldap_pwdlockout_dn and a policy that is not cn=ppolicy,ou=policies,<base>Set ldap_pwdlockout_dn to your policy DN (step above)
All clients suddenly fail; sssd-bind shows pwdAccountLockedTimeService account under the default policy, a client with a wrong bind passwordAttach the service policy (step 4); unlock; fix the client
Rule typo accepted, wrong effectOut-of-range index appends; set expressions are not validated at load timeslapacl after every change; list olcAccess to see the final order
An ACL change works on ldap1 but not on a client that fails over to ldap2cn=config is not replicatedApply the same LDIF on ldap2 and compare the two olcAccess lists
Plain (non-TLS) binds fail after a restore *Restored config keeps olcSecurity: ssf=1 (part 3)Use StartTLS (-ZZ); fix certificates on the new host
slapd cannot read its database after slapaddslapadd was run as root, so the files belong to rootchown -R ldap:ldap /etc/openldap/slapd.d /var/lib/ldap; restorecon -R *

Security notes

  • Lockout is a denial-of-service tool. Anyone who can reach port 389 can lock any known account by sending wrong passwords. Limit who can reach the servers (firewalld, part 3), keep the service accounts on the non-locking policy, and consider a shorter pwdLockoutDuration instead of “until an administrator unlocks”.
  • olcPPolicyUseLockout: TRUE tells a client that an account is locked, and by implication that it exists and that the password guess may be right. Switch it off if that matters more to you than clear messages.
  • Do routine password resets as a named sysadmin, not as cn=admin: the rootDN bypasses quality checks, and your audit trail should show who did it.
  • Backups contain password hashes. Mode 0600, encrypted offsite copies, and the same retention rules as the directory.
  • Keep olcSecurity: ssf=1 and the StartTLS requirement from part 3, or the passwords this policy protects travel in clear text.

What was tested and what was not

Everything in parts A and B was run against the two OpenLDAP 2.6.13 servers from part 4 (extracted AlmaLinux 10 and EPEL packages, run unprivileged on a test machine, without systemd), with ppolicy loaded on both and the SSSD 2.13.1 client from part 5. Details that differ from a real EL host: the servers listened on ports 3890 and 3891, the module paths pointed to the extraction directory (a missing-file path was also tried), and the cracklib word list came from the AlmaLinux 10 cracklib-dicts package. The backup script, the three restores and the entry recovery were run with the real slapcat, slapadd and slaptest binaries against copies in scratch directories.

Not tested: the systemd units for the timer, sudo -u ldap ownership handling and SELinux labels (restorecon), pwdMustChange, the manage access level for password administrators, ppolicy_forward_updates on a consumer, a consumer without the module receiving policy entries (the equivalent slapadd failure was), group-based group.exact ACLs for groupOfNames, password changes through SSSD and PAM on a client, ldap_access_filter, EL9 specifics, and a restore into a replication pair with slapadd -w.

Where this leaves the series

The six parts together give you: a two-server OpenLDAP directory (part 1, part 4), clean user and group data (part 2), encrypted transport (part 3), clients that log in and survive the loss of a server (part 5), and now access rules, password policy and tested backups. The sensible next checks are boring ones: run the backup script from cron or the timer, restore it once a quarter on a scratch machine, and compare the olcAccess lists of both servers after every change.

Leave a Reply

Your email address will not be published. Required fields are marked *