Revision as of 22:34, 6 January 2014

OpenLDAP is an open-source implementation of the LDAP protocol. It is mainly used as an address book (for e.g. email clients) or authentication backend to various services (such as Samba, where it is used to emulate a domain controller, or Linux system authentication, where it replaces /etc/passwd) and basically holds the user data.

The closest analogue to real life, would be the telephone directory. Another generalised explanation of what an LDAP server does is that it is a database (which it basically is, but it is not relational) which is optimised for accessing the data and not writing them.

Commands relate to OpenLDAP that begin with ldap (like ldapsearch) are client-side utilities while commands that begin with slap (like slapcat) are server-side.

Directory services are an enormous topic. Configuration can therefore be complex. This page is a starting point for a basic OpenLDAP installation and a sanity check.

If you are totally new to those concepts, this is an good introduction that is easy to understand and that will get you started, even if you are new to everything LDAP.

Installation

Configuration

The server

Note: If you already have an OpenLDAP database on your machine, remove it by deleting everything inside /var/lib/openldap/openldap-data/.

The server configuration file is located at /etc/openldap/slapd.conf.

Edit the suffix and rootdn. The suffix typically is your domain name but it does not have to be. It depends on how you use your directory. We will use example for the domain name, and com for the tld. The rootdn is your LDAP administrator's name (we'll use root here).

suffix "dc=example,dc=com"
rootdn "cn=root,dc=example,dc=com"

Now we delete the default root password and create a strong one:

# sed -i "/rootpw/ d" slapd.conf #find the line with rootpw and delete it
# echo "rootpw $(slappasswd)" >> slapd.conf #add a line which includes the hashed password output from slappasswd

You will likely want to add some typically used schemas to the top of slapd.conf:

include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema

You will likely want to add some typically used indexes to the bottom of slapd.conf:

OpenLDAP over TLS

If you access the OpenLDAP server over the network and especially if you have sensitive data stored on the server you run the risk of someone sniffing your data which is sent clear-text. The next part will guide you on how to setup an SSL connection between the LDAP server and the client so the data will be sent encrypted.

In order to use TLS, we must first create a certificate. You can have a certificate signed, or create your own Certificate Authority (CA), but for our purposed, a self-signed certificate will suffice.

Warning: OpenLDAP cannot use a certificate that has a password associated to it.

Create a self-signed certificate

You will be prompted for information about your LDAP server. Much of the information can be left blank. The most important information is the common name. This must be set to the DNS name of your LDAP server. If your LDAP server's IP address resolves to example.org but its server certificate shows a CN of bad.example.org, LDAP clients will reject the certificate and will be unable to negotiate TLS connections (apparently the results are wholly unpredictable).

Now that the certificate files have been created copy them to /etc/openldap/ssl/ (if this directory doesn't exist create it) and secure them.
slapdcert.pem must be world readable because it contains the public key. slapdkey.pem on the other hand should only be readable for the ldap user for security reasons:

The TLSCipherSuite specifies a list of OpenSSL ciphers from which slapd will choose when negotiating TLS connections, in decreasing order of preference. In addition to those specific ciphers, you can use any of the wildcards supported by OpenSSL. NOTE: HIGH, MEDIUM, and +SSLv2 are all wildcards.

Note: To see which ciphers are supported by your local OpenSSL installation, type the following: openssl ciphers -v ALL

Start slapd with SSL

You will have to edit slapd.service to change to protocol slapd listens on.

First, disable slapd.service if it's enabled.
Then, copy the stock service to /etc/systemd/system/:

# cp /usr/lib/systemd/system/slapd.service /etc/systemd/system/

Edit it, and add change ExecStart to:

/etc/systemd/system/slapd.service

ExecStart=/usr/bin/slapd -u ldap -g ldap -h "ldaps:///"

Note: Localhost connections don't need to use SSL so you could replace "ldaps:///" by "ldap://127.0.0.1 ldaps:///" in systemd service file of slapd.service in /etc/systemd/system/slapd.service.

Then reenable and start it:

# systemctl daemon-reload
# systemctl restart slapd.service

If slapd started successfully you can enable it with:

# systemctl enable slapd.service

Note: If you created a self-signed certificate above be sure to add TLS_REQCERT allow to /etc/openldap/ldap.conf or you won't be able connect to the server.

Next Steps

You now have a basic LDAP installation. The next step is to design your directory. The design is heavily dependent on what you are using it for. If you are new to LDAP, consider starting with a directory design recommended by the specific client services that will use the directory (PAM, Postfix, etc).