Manage OpenLDAP with the CLI¶
Presentation¶
The script slapd-cli
provide start, stop and other commands for OpenLDAP daemon. It requires:
Logger, to forward messages to syslog
Awk, for regular expression management
OpenLDAP, for save, index,… tools
Configuration of this script can be done in an external file, with the same name as the slapd-cli program
The main features are:
start / stop / status of OpenLDAP daemon
check configuration
debug: start OpenLDAP in debug mode (stay attached)
reindex
backup / restore data
backup / restore configuration
check synchronization status
import test data / test configuration
Tip
This script is included by default in debian and red-hat OpenLDAP LTB packages. You can also get it from the main repository.
Usage of slapd-cli¶
The script can be launched like this:
slapd-cli action [optional arguments]
Tip
In OpenLDAP LTB packages, the script is available in /usr/local/openldap/sbin/slapd-cli
.
Anyway, with the PATH updated by /etc/profile.d/openldap-profile.sh
, you can just run slapd-cli
.
Action is a keyword between:
- start
start the slapd server
- stop
stop the slapd server
- forcestop
kill the slapd server if it can’t stop
- restart
restart the slapd server
- debug
start the slapd server in debug mode (stay attached)
- force-restart
forcestop + start
- status
get the status of currently running slapd server
- configtest
test configuration syntax
- reindex
index or reindex database
- backup
backup the data
- restore
restore the data
- backupconfig
backup the configuration
- restoreconfig
restore the configuration
- checksync
check the synchronization state of the current instance to every provider found in configuration
- importflatconfigtemplate
import the flat template configuration file, after setting the variables
- importldifconfigtemplate
import the ldif template configuration file, after setting the variables
- convertconfig [inputfile.conf] [outputfile.ldif]
convert the input slapd configuration file into the equivalent ldif configuration
- buildconfigtemplate [inputfile.ldif] [outputfile.ldif]
Get the input ldif configuration file and transform it into a template configuration
- importdatatemplate
import the template data file, after setting the variables
- lloadstart
start the load-balancer
- lloadstop
stop the load-balancer
- lloadstatus
get the status of currently running load-balancer
- removeoldbackups
remove old configuration and data backup files (also done when calling backup and backupconfig actions)
Tip
slapd-cli
provides autocompletion with slapd-cli-prompt
configuration file, which is deployed by default in OpenLDAP LTB packages.
That way, you just have to use the tab key to find out the actions and autocomplete file names.
Note
This script uses the last modification time of files to know which one to restore or to remove. If you modify a file directly in the backup directory, it will impact these actions.
Installation of slapd-cli¶
Note
The OpenLDAP installation path is assumed to be /usr/local/openldap
.
Copy script in /usr/local/openldap/sbin:
# mv slapd-cli /usr/local/openldap/sbin
# chmod +x /usr/local/openldap/sbin/slapd
Configuration file must be installed into configuration folder:
# mkdir -p /usr/local/openldap/etc/openldap
# mv slapd-cli.conf /usr/local/openldap/etc/openldap/
# chmod 600 /usr/local/openldap/etc/openldap/slapd-cli.conf
Deploy template files into configuration folder:
# mv *-template.{conf,ldif} /usr/local/openldap/etc/openldap/
Optionally, deploy load-balancer configuration file:
# mv lload.conf /usr/local/openldap/etc/openldap/
# chmod 600 /usr/local/openldap/etc/openldap/lload.conf
Optionally, enable autocomplete:
# mv slapd-cli-prompt /etc/bash_completion.d/
Finally, you can decide to use the systemd services for slapd or lload:
# mv slapd-ltb.service /lib/systemd/system/
# systemctl --system daemon-reload
# systemctl enable slapd-ltb.service
# mv lload-ltb.service /lib/systemd/system/
# systemctl --system daemon-reload
# systemctl enable lload-ltb.service
Configuration of slapd-cli¶
Use the external file in /usr/local/openldap/etc/openldap
rather than editing directly the script.
Following parameters are about network:
Parameter |
Description |
---|---|
|
Listen address for LDAP requests. Meta character |
|
Listen port for LDAP requests. Use |
|
Listen address for LDAPS requests. Meta character * can be used for all interfaces |
|
Listen port for LDAPS requests. Use |
|
Directory where LDAPI socket is created (will be created if it does not exist) |
|
LDAPI socket URL (URL encoded value) |
|
Mode for LDAPI socket (by default |
|
Owner user of LDAPI socket |
|
Owner group of LDAPI socket |
|
List of listen LDAP URIs, space-separated. It is made of all previous variables.
This parameter is corresponding to |
Following parameters are about OpenLDAP directories and files:
Parameter |
Description |
---|---|
|
OpenLDAP main directory |
|
Data folder. You can set |
|
Path to the pid file. It must match the olcPidFile configuration parameter |
|
Path to the flat slapd.conf configuration file |
|
Path to the slapd.d folder. When defined, |
|
slapd binary path |
|
Additional options for slapd. Options |
|
Path to the library module folder |
|
slapadd binary path |
|
slapadd extra options |
|
slapcat binary path |
|
slapcat extra options |
|
slapindex binary path |
|
slaptest binary path |
|
ldapsearch binary path |
Following parameters are about other options for slapd launch:
Parameter |
Description |
---|---|
|
Owner user of slapd process |
|
Owner group of slapd process |
|
Syslog local user (by default |
|
Maximum delay waiting for slapd to stop. After, you need to use the |
|
Maximum opened file descriptors |
|
OpenLDAP log level to use in debug mode. Default is 256 (stats) |
|
Name of slapd service in systemd. Default is slapd-ltb. |
|
Name of lload service in systemd. Default is lload-ltb. |
Following parameters are about backup and restore:
Parameter |
Description |
---|---|
|
Do a backup data when slapd is stopped |
|
Backup folder |
|
Backup file suffix |
|
Extension of LDIF compressed file. No compression is done if this is empty |
|
Binary used to compress LDIF file |
|
Binary used to uncompress LDIF file |
|
Maximum days to keep a configuration backup file |
|
Maximum days to keep a data backup file |
|
command used for running |
|
mask used for computing unix permissions while backuping |
Following parameters are about data provisioning:
Parameter |
Description |
---|---|
|
Path to template file used for data provisioning |
|
Suffix used for data provisioning. suffix is going to be replaced in |
|
Organization ( |
|
Distinguished name for a service account. |
|
Password for the latter service account. Password must be clear-text. It will be hashed |
|
Distinguished name for an admin account.
<USER> must be replaced by any unique string.You can add any number of admin accounts by choosing as many
<USER> as you want.Admins are no different from user account except that they are member of an admin group
|
|
Password for the latter admin account. Password must be clear-text. It will be hashed |
|
|
|
surname for the admin account |
|
givenname for the admin account |
|
mail for the admin account |
|
Distinguished name for a user account.
<USER> must be replaced by any unique string.You can add any number of user accounts by choosing as many
<USER> as you want. |
|
Password for the corresponding user account. Password must be clear-text. It will be hashed |
|
|
|
surname for the user account |
|
givenname for the user account |
|
mail for the user account |
Following parameters are about configuration provisioning:
Parameter |
Description |
---|---|
|
Path to the flat slapd.conf template file used for configuration provisioning |
|
Path to the ldif template file used for configuration provisioning |
|
Main data base suffix |
|
Full-qualified domain name of the machine hosting slapd (used for |
|
Log level, see OpenLDAP |
|
path of the log file, see OpenLDAP |
|
Distinguished name for the main data base superadmin |
|
Password for the main data base superadmin. Password must be clear-text. It will be hashed |
|
Distinguished name for cn=config superadmin |
|
Password for the cn=config superadmin. Password must be clear-text. It will be hashed |
|
Distinguished name for cn=monitor superadmin |
|
Password for the cn=monitor superadmin. Password must be clear-text. It will be hashed |
|
Path to the main data base folder |
Following parameters are about load balancer:
Parameter |
Description |
---|---|
|
Listen address for LDAP requests. Meta character |
|
Listen port for LDAP requests. Use |
|
Listen address for LDAPS requests. Meta character * can be used for all interfaces |
|
Listen port for LDAPS requests. Use |
|
socket URL for load balancer (URL encoded value) |
|
list of listen LDAP URIs, space-separated. It is made of all previous variables.
This parameter is corresponding to
-h option in slapd launch command. |
|
Path to the pid file. It must match the olcPidFile configuration parameter |
|
Path to the flat lload.conf configuration file |
|
Path to the slapd.d lload conf folder. When defined, |
Run several OpenLDAP instances¶
You can run several OpenLDAP daemons on the same server.
Choose an instance name.
Link slapd-cli command: (replace <instance> by your instance name)
# ln -s /usr/local/openldap/sbin/slapd-cli /usr/local/openldap/sbin/slapd-<instance>-cli
Copy slapd-cli configuration file: (replace <instance> by your instance name)
# cp /usr/local/openldap/etc/openldap/slapd-cli.conf /usr/local/openldap/etc/openldap/slapd-<instance>-cli.conf
Edit new slapd-<instance>-cli.conf
and change at least the following parameters:
PORT
andSSLPORT
SLAPD_PID_FILE
must be changed to:/usr/local/openldap/var/run/slapd-<instance>.pid
. Take care to also change the PID file into OpenLDAP configuration (parameter olcPidFile)SLAPD_CONF_DIR
orSLAPD_CONF
to a specific configuration directory or file. Typically, for a directory:SLAPD_CONF_DIR="/usr/local/openldap/etc/openldap/slapd.d-<instance>"
SYSTEMD_SERVICE_NAME
toslapd-<instance>-ltb
(and optionnallySYSTEMD_LLOAD_SERVICE_NAME
tolload-<instance>-ltb
)BACKUP_PATH
to a dedicated backup directory:/var/backups/openldap-<instance>
Run the openldap instance with: (replace <instance> by your instance name)
# systemctl start slapd-ltb@<instance>.service
You can also use the cli for running any command on the new instance:
# slapd-instance-cli backupconfig
slapd-instance-cli: [INFO] Using /usr/local/openldap/etc/openldap/slapd-instance-cli.conf for configuration
slapd-instance-cli: [INFO] Launching OpenLDAP configuration backup...
slapd-instance-cli: [OK] Configuration saved in /var/backups/openldap-instance/config-20240523174022.ldif