OpenLDAP auf CentOS 7

January 13, 2021 in linux, redhat ‐ 4 min read

In diesem Artikel soll es darum gehen, wie man OpenLDAP auf CentOS 7 installiert und wie man es rudimentär bedient.

Er bedient sich grob an dem offiziellen Quick Start Guide.

Warum CentOS 7 und nicht CentOS 8?

  • CentOS 8 geht 2021 end of life, CentOS 7 hat noch support bis 2024. Click mich für Details.

Warum openLDAP und nicht 389ds / FreeIPA

  • Lernzwecke
  • Es funktioniert und ist relativ einfach handlebar

Basisinstallation

Im Gegensatz zu CentOS8 bei dem man openLDAP selbst bauen muss, ist es bei CentOS7 bereits in den Repos.

yum install openldap openldap-servers

Der server kommt mit dem slapd service daher.
Diesen starten und enablen wir.

systemctl start slapd
systemctl enable slapd

Prüft anschließend, dass der Dienst läuft und port 389 gebunden hat.

[root@openldap ~]# systemctl status slapd
● slapd.service - OpenLDAP Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/slapd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mi 2021-01-13 11:02:31 CET; 1min 59s ago
     [...]


[root@openldap ~]# netstat -tulpen | grep slapd
tcp        0      0 0.0.0.0:389             0.0.0.0:*               LISTEN      0          312156     15731/slapd
tcp6       0      0 :::389                  :::*                    LISTEN      0          312157     15731/slapd

Initiale Konfiguration

Bei der Installation von openLDAP werden einige Tools mitinstalliert.
Diese werden wir nun verwenden um die initiale Konfiguration der openLDAP Instanz vorzunehmen.

Slapcat - exportiert Daten im ldif Format.

Slapcat is used to generate an LDAP Directory Interchange Format (LDIF) output based upon the contents of a slapd(8) database.

slappasswd - hasht passwörter

Slappasswd is used to generate an userPassword value suitable for use with ldapmodify(1), slapd.conf(5) rootpw configuration

Da wir bisher noch kein Passwort gesetzt haben, nutzen wir slappasswd um initial ein Passwort zu setzen.

[root@openldap ~]# slappasswd
New password:
Re-enter new password:
{SSHA}mLWOOC88hfX1HH0l0mZQDhJjqHfgsBqi

Dies wirft euch ein gehashtes Passwort aus, welches wir gleich brauchen werden.

Zunächst aber schauen wir uns an, wie ldif files aufgebaut sind.
LDIF (LDAP Data Interchange Format) Dateien beschreiben den Inhalt eines Directories oder beinhalten Änderungsaufforderungen.

dn (Distinguished Name) - Ist der ein Objekt eindeutig identifizierende name. Achtung, in kanonischer Schreibweise!

changetype - ist die Art der Änderung der vorzunehmenden Änderung. Möglich sind:

  • add
  • delete
  • modify
  • modrdn (Modify RDN, relative distinguished name)
  • moddn - (Modify DN, distinguished name)

replace: - ist die Anweisung den Wert von zu ändern

: - definiert den Wert des zu ändernden Attributes

Mit diesen Infos solltet Ihr jetzt in der Lage sein folgende dreiÄnderungen zu lesen.

(Tragt hier jeweils eure eigenen Werte ein)

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=YOURDOMAIN,dc=local

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=YOURADMINUSER,dc=YOURDOMAIN,dc=local

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootPW
olcRootPW: {SSHA}mLWOOC88hfX1HH0l0mZQDhJjqHfgsBqi

Wir replacen in olcDatabase={2}hdb,cn=config die Werte von:

  • olcSuffix mit dc=YOURDOMAIN,dc=local
  • olcRootDN mit cn=YOURADMINUSER,dc=YOURDOMAIN,dc=local
  • olcRootPW mit {SSHA}mLWOOC88hfX1HH0l0mZQDhJjqHfgsBqi

Was ist dieses OLC?

OLC steht für on-line configuration und ermöglicht es Änderungen an dem LDAP Schema zu machen, ohne den Deamon neu starten zu müssen.

Historically OpenLDAP has been statically configured, that is, to make a change to the configuration the slapd.conf file was modified and slapd stopped and started. In the case of larger users this could take a considerable period of time and had become increasingly unacceptable as an operational method. OpenLDAP version 2.3 introduced an optional new feature whereby configuration may be performed at run-time using a DIT entry called cn=config. The feature is known by a varied and confusing number of terms including on-line configuration (OLC) (our favorite), zero down-time configuration, cn=config and slapd.d configuration.

https://www.zytrax.com/books/ldap/ch6/slapd-config.html

Um diese werte wie in der neu angelegten .ldif Datei beschrieben zu modifizieren, nutzen wir nun ldapmodify.

Ldapmodify - ein Werzeug zum hinzufügen und editieren von LDAP Einträgen

ldapmodify opens a connection to an LDAP server, binds, and modifies or adds entries. The entry information is read from standard input or from file through the use of the -f option.

ldapmodify manpage

Ldapmodify ist Teil des Paketes openldap-clients.

yum install openldap-clients

ldapmodify sagen wir mit -H, mit welcher URI es sich verbinden soll. In diesem Fall nutzen wir den lokalen Unix Socket, welcher laufen sollte.
Prüfen könnt ihr das folgendermaßen.

[root@openldap slapd.d]# ss -l -p |grep ldap
u_str  LISTEN     0      128    /var/run/ldapi 312152                * 0                     users:(("slapd",pid=15731,fd=7))

Mit -f geben wir an, dass es die Änderungen aus einem File eingelesen werden sollen.

Der Output sollte etwa so aussehen:

[root@openldap slapd.d]# ldapmodify -H ldapi:/// -f db.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={2}hdb,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

modifying entry "olcDatabase={2}hdb,cn=config"

Leseempfehlungen

LDAP for Rocket Scientists

Modifying Entries Using ldapmodify

Oracle® Identity Management User Reference - LDIF Format for Entries

Ubuntu Serverguide ab Seite 112