Red Hat dropped the OpenLDAP server from RHEL 9, so on Rocky Linux 9 the openldap-servers package comes from EPEL or Symas repo. This guide sets up a single OpenLDAP 2.6 server that you can later use as the user directory for an eduroam IdP.
We use dc=uni,dc=ac,dc=ma as the base of the directory and ldap.uni.ac.ma as the server name. Replace them with your own.
1. Prerequisites#
A freshly installed Rocky Linux 9 with static IPv4 and IPv6 addresses and a DNS name. Update and reboot:
dnf -y upgrade
reboot
2. Install OpenLDAP#
dnf -y install epel-release
dnf -y install openldap-servers openldap-clients
systemctl enable --now slapd
Check which database the package created. The commands below assume it is olcDatabase={2}mdb:
ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config -LLL dn | grep olcDatabase
3. Set the base DN and the admin password#
Generate a hashed password for the directory administrator:
slappasswd -h {SSHA}
Create db.ldif, pasting the hash you just generated:
db.ldifdn: olcDatabase={2}mdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=uni,dc=ac,dc=ma
-
replace: olcRootDN
olcRootDN: cn=admin,dc=uni,dc=ac,dc=ma
-
replace: olcRootPW
olcRootPW: {SSHA}paste-the-hash-here
-
replace: olcAccess
olcAccess: {0}to attrs=userPassword by self write by anonymous auth by * none
olcAccess: {1}to * by self read by users read by * none
ldapmodify -Y EXTERNAL -H ldapi:/// -f db.ldif
4. Load the schemas#
The inetOrgPerson class used for user accounts needs the cosine schema first:
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
For eduroam and identity federations you will also want the eduPerson and eduOrg schemas: see Add eduPerson and eduOrg schemas to OpenLDAP.
5. Create the base of the tree#
Create base.ldif with the organisation and two units, one for people and one for groups:
base.ldifdn: dc=uni,dc=ac,dc=ma
objectClass: top
objectClass: dcObject
objectClass: organization
o: University X
dc: uni
dn: ou=people,dc=uni,dc=ac,dc=ma
objectClass: organizationalUnit
ou: people
dn: ou=groups,dc=uni,dc=ac,dc=ma
objectClass: organizationalUnit
ou: groups
ldapadd -x -D cn=admin,dc=uni,dc=ac,dc=ma -W -f base.ldif
Then add a first user with user.ldif (set the password afterwards with ldappasswd):
user.ldifdn: uid=jdoe,ou=people,dc=uni,dc=ac,dc=ma
objectClass: inetOrgPerson
uid: jdoe
cn: John Doe
sn: Doe
mail: jdoe@uni.ac.ma
ldapadd -x -D cn=admin,dc=uni,dc=ac,dc=ma -W -f user.ldif
ldappasswd -x -D cn=admin,dc=uni,dc=ac,dc=ma -W -S uid=jdoe,ou=people,dc=uni,dc=ac,dc=ma
6. Enable TLS#
Use a certificate for ldap.uni.ac.ma, for example one from MARWAN-TCS with HARICA. Copy the certificate, its key and the CA chain to /etc/openldap/certs/ and let the ldap user read them:
chown ldap:ldap /etc/openldap/certs/ldap.*
chmod 600 /etc/openldap/certs/ldap.key
tls.ldifdn: cn=config
changetype: modify
replace: olcTLSCACertificateFile
olcTLSCACertificateFile: /etc/openldap/certs/chain.crt
-
replace: olcTLSCertificateFile
olcTLSCertificateFile: /etc/openldap/certs/ldap.crt
-
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/openldap/certs/ldap.key
ldapmodify -Y EXTERNAL -H ldapi:/// -f tls.ldif
To also listen on LDAPS (port 636), set the listeners in /etc/sysconfig/slapd and restart:
/etc/sysconfig/slapdSLAPD_URLS="ldapi:/// ldap:/// ldaps:///"
systemctl restart slapd
7. Open the firewall#
LDAP uses port 389 (plain or StartTLS) and LDAPS port 636. Only allow the networks that need the directory, such as your RADIUS servers:
firewall-cmd --permanent --add-service=ldap
firewall-cmd --permanent --add-service=ldaps
firewall-cmd --reload
8. Logging#
slapd logs to syslog facility local4. Send it to its own file:
echo 'local4.* /var/log/slapd.log' > /etc/rsyslog.d/slapd.conf
systemctl restart rsyslog
9. Test#
From the server and from a client, search for the user over TLS:
ldapsearch -x -H ldaps://ldap.uni.ac.ma -D uid=jdoe,ou=people,dc=uni,dc=ac,dc=ma -W -b dc=uni,dc=ac,dc=ma "(uid=jdoe)"
If the search returns the entry, the directory is ready. Next step: connect it to FreeRADIUS with eduroam IdP using OpenLDAP.