Post

How to Set Up and Manage OpenLDAP (`slapd`) Logging on Debian 12

How to Set Up and Manage OpenLDAP (`slapd`) Logging on Debian 12

This guide covers:

  • Logging to a dedicated file (/var/log/slapd.log)
  • Setting verbose log levels for debugging/testing
  • Preventing logs from flooding /var/log/syslog
  • Ensuring slapd starts correctly after a reboot

1. Configure rsyslog to Capture OpenLDAP Logs

  1. Create the rsyslog config:
1
sudo nano /etc/rsyslog.d/50-slapd.conf
  1. Add:
if $syslogfacility-text == 'local4' then /var/log/slapd.log
& stop
  1. Set up the log file:
1
2
3
sudo touch /var/log/slapd.log
sudo chown root:adm /var/log/slapd.log
sudo chmod 640 /var/log/slapd.log
  1. Restart rsyslog:
1
sudo systemctl restart rsyslog

2. Set OpenLDAP to Log Verbosely for Testing

OpenLDAP uses the olcLogLevel attribute in its config (under cn=config).

To enable verbose testing logs:

1
2
3
4
5
6
ldapmodify -Y EXTERNAL -H ldapi:/// <<EOF
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats stats2 acl sync
EOF

This enables:

  • stats: operation-level logging
  • stats2: adds entry/attribute parsing
  • acl: logs access control decisions
  • sync: logs replication info

3. Configure systemd to Ensure Startup and Logging Work

Edit the systemd override for slapd:

1
sudo systemctl edit slapd

Paste the following:

1
2
3
4
5
[Service]
ExecStart=
ExecStartPre=/bin/mkdir -p /var/run/slapd
ExecStartPre=/bin/chown openldap:openldap /var/run/slapd
ExecStart=/usr/sbin/slapd -h "ldap:/// ldapi:///" -F /etc/ldap/slapd.d -u openldap -g openldap

This:

  • Prevents bind(9) failed errno=2 errors on reboot
  • Ensures systemd manages slapd correctly
  • Keeps slapd logging via syslog (local4) as set by olcLogLevel

Reload and restart:

1
2
3
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl restart slapd

4. View Logs

To monitor live:

1
tail -f /var/log/slapd.log

How to Return to Normal Logging

To reduce log verbosity after testing:

1
2
3
4
5
6
ldapmodify -Y EXTERNAL -H ldapi:/// <<EOF
dn: cn=config
changetype: modify
replace: olcLogLevel
olcLogLevel: stats
EOF

Or to disable logging:

1
olcLogLevel: none

Optional: Rotate Logs

Create a logrotate rule:

1
sudo nano /etc/logrotate.d/slapd

Add:

1
2
3
4
5
6
7
8
9
10
11
12
/var/log/slapd.log {
    weekly
    rotate 8
    compress
    delaycompress
    missingok
    notifempty
    create 640 root adm
    postrotate
        systemctl reload rsyslog > /dev/null 2>&1 || true
    endscript
}

Confirm It Survives Reboot

1
sudo reboot

After reboot, confirm:

1
2
3
systemctl status slapd
ls -l /var/run/slapd/ldapi
tail /var/log/slapd.log

Summary of Log Levels

LevelDescription
noneDisable logging
statsBasic operation logs
stats2Entry-level details
aclAccess control checks
syncReplication-related events
traceFull function tracing (very noisy)
argsLog startup arguments

This post is licensed under CC BY 4.0 by the author.