Configure LDAP over TLS on CentOS 6: Self-Signed Certificate and LDAPS Server Setup

This is the server-side walkthrough for adding TLS to an OpenLDAP (slapd) server on CentOS 6. You’ll create a self-signed certificate, load it into the cn=config database, and turn on LDAPS on port 636 next to StartTLS on port 389. Each step has a screenshot from our test server.

Looking for the client side? Our companion post OpenLDAP over TLS: Client Setup, Testing and Troubleshooting covers ldap.conf, trusting the certificate on clients, testing with ldapsearch -ZZ and openssl s_client, and fixing common TLS errors. This page covers only the server.

OpenLDAP logo

Before you start

You need a working OpenLDAP server on CentOS 6 (see Configure LDAP Server on CentOS 6) and a root shell. Decide the hostname clients will use, such as ldap.example.com. The certificate’s Common Name must match it.

Root shell prompt on the CentOS 6 LDAP server

Part 1: Generate the certificate

CentOS 6 ships a Makefile in /etc/pki/tls/certs that wraps the OpenSSL commands:

cd /etc/pki/tls/certs
make LDAP.key
cd /etc/pki/tls/certs on CentOS 6
make LDAP.key command in /etc/pki/tls/certs

make runs openssl genrsa -aes128 2048 and asks for a passphrase:

make LDAP.key running openssl genrsa -aes128 2048 and prompting for a passphrase

slapd can’t type a passphrase when it starts, so strip it from the key:

openssl rsa -in LDAP.key -out LDAP.key
openssl rsa removing the passphrase from LDAP.key

Create a certificate signing request. When asked for the Common Name, enter the server’s FQDN:

make LDAP.csr
make LDAP.csr prompting for the certificate Distinguished Name

Self-sign it. Our lab used 36500 days. In production, use a shorter lifetime or a certificate from your internal CA.

openssl x509 -in LDAP.csr -out LDAP.crt -req -signkey LDAP.key -days 36500
openssl x509 self-signing LDAP.csr into LDAP.crt for 36500 days

Lock down the files:

chmod 400 LDAP.*
chmod 400 LDAP.* restricting the key and certificate files

Part 2: Load the certificate into slapd

Copy the key and certificate to the OpenLDAP certificate directory and give them to the ldap user:

mkdir -p /etc/openldap/cacerts/
cp /etc/pki/tls/certs/LDAP.* /etc/openldap/cacerts/
chown ldap. /etc/openldap/cacerts/*
Creating /etc/openldap/cacerts and copying the LDAP certificate files into it

Change cn=config over the local ldapi socket as root:

ldapmodify -Y EXTERNAL -H ldapi:///
chown ldap on the cacerts files and ldapmodify -Y EXTERNAL -H ldapi:///

Paste this LDIF, then press Ctrl+D:

dn: cn=config
add: olcTLSCertificateFile
olcTLSCertificateFile: /etc/openldap/cacerts/LDAP.crt
-
add: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/openldap/cacerts/LDAP.key

If the attributes already exist, for example because you’re renewing the certificate, use replace: instead of add:.

Part 3: Enable LDAPS and restart

Edit the slapd startup options:

vi /etc/sysconfig/ldap
Opening /etc/sysconfig/ldap in vi

Set SLAPD_LDAPS=yes (around line 20) so slapd also listens on ldaps:///, port 636:

SLAPD_LDAPS=yes set in /etc/sysconfig/ldap

Restart slapd:

service slapd restart
service slapd restart showing Stopping and Starting slapd OK

Part 4: Server-side checks

netstat -tlnp | grep slapd
iptables -I INPUT -p tcp -m multiport --dports 389,636 -j ACCEPT
service iptables save

You should see slapd listening on both 389 and 636. If slapd won’t start, check /var/log/messages. The usual cause is that the ldap user can’t read the key.

Next, set up your clients to trust this certificate with the client setup and troubleshooting guide.

Hosted Linux server at www.zwiegnet.com/go

Related guides: OpenLDAP over TLS: Client Setup, StartTLS Testing and Troubleshooting | 389 Directory Server TLS Client CentOS

Leave a Reply

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