Configure OpenLDAP with TLS/SSL
Configure OpenLDAP Server
- Install OpenLDAP-Server RPM
Use yum to install following rpm's.
Start and enable openldap-server deamon
- Set LDAP root account password and generate hash
Run slappasswd and set LDAP root password and generate its Hash.
Keep a note of both the password and its hash as these will be used later in configurations
- Add LDAP server initial configuration Attribute
Create base_config.ldif file with following contents:
Deploy configuration change to LDAP server.
- Create Custom CA-Signed Certificate
Create the root CA key
Using root CA key, Create the self-signed root CA certificate
Create a private key for LDAP server
Using the LDAP server private key, create a certificate signing request (CSR)
Sign the certificate signing request (CSR) using the custom root CA
Set the user and group ownership on all newly created certificates
Verify the newly created LDAP certificate
- Set self-signed certificate Attribute in LDAP Configuration
Create certs.ldif file with following contents:
Deploy configuration change to LDAP server.
Deploy configuration change to LDAP server.
- Add in-built LDAP schemas
- Set LDAP Domain Attribute
Create create_domain.ldif file with following contents:
Deploy configuration change to LDAP server.
- Adding LDAP User
Create ldap password for sample test user
Create create_test_user.ldif file with following contents:
Deploy configuration change to LDAP server.
- Enable TLS/SSL in LDAP configuration file
Add the following ldaps option in below parameter
Add the following parameter
Restart service
- Check DB File Config
- Check Domain Config
- Check User Config
- Install OpenLDAP Client RPM
- Enable LDAP Client Configuration
- Verify nsswitch Setting
- Add the following parameter
- Configure TLS/SSL Certificate
- Start and Enable NSCD Services
- Query test user information from LDAP Server
- Login to server with test user. User home directory will be auto-created
[root@openldap-server ~]# yum -y install openldap openldap-servers openldap-clients
[root@openldap-server ~]# systemctl start slapd.service
[root@openldap-server ~]# systemctl enable slapd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/slapd.service to /usr/lib/systemd/system/slapd.service.
[root@openldap-server ~]#
[root@openldap-server ~]# slappasswd
New password:
Re-enter new password:
{SSHA}JNNjNtlq2ZtO7oDvcR+7YbTuOvx8nv5V
[root@openldap-server ~]#
[root@openldap-server ~]# vi base_config.ldif
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: dc=linuxtechspace,dc=com
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=root,dc=linuxtechspace,dc=com
dn: olcDatabase={2}hdb,cn=config
changeType: modify
add: olcRootPW
olcRootPW: {SSHA}JNNjNtlq2ZtO7oDvcR+7YbTuOvx8nv5V
dn: olcDatabase={1}monitor,cn=config
changetype: modify
replace: olcAccess
olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external, cn=auth" read by dn.base="cn=root,dc=linuxtechspace,dc=com" read by * none
[root@openldap-server ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f base_config.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"
modifying entry "olcDatabase={1}monitor,cn=config"
[root@openldap-server ~]# cd /etc/openldap/certs/
[root@openldap-server ~]# openssl genrsa -out LTSrootCA.key 2048
[root@openldap-server ~]# openssl req -x509 -new -nodes -key LTSrootCA.key -sha256 -days 1024 -out LTSrootCA.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:US
State or Province Name (full name) []:TN
Locality Name (eg, city) [Default City]:Memphis
Organization Name (eg, company) [Default Company Ltd]:Linux Tech Space
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:openldap-server.linuxtechspace.com
Email Address []:admin@linuxtechspace.com
[root@openldap-server ~]# openssl genrsa -out LTSldap.key 2048
[root@openldap-server ~]# openssl req -new -key LTSldap.key -out LTSldap.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:US
State or Province Name (full name) []:TN
Locality Name (eg, city) [Default City]:Memphis
Organization Name (eg, company) [Default Company Ltd]:Linux Tech Space
Organizational Unit Name (eg, section) []:IT
Common Name (eg, your name or your server's hostname) []:openldap-server.linuxtechspace.com
Email Address []:admin@linuxtechspace.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@openldap-server ~]# openssl x509 -req -in LTSldap.csr -CA LTSrootCA.pem -CAkey LTSrootCA.key -CAcreateserial -out LTSldap.crt -days 1460 -sha256
Signature ok
subject=/C=US/ST=TN/L=Memphis/O=Linux Tech Space/OU=IT/CN=openldap-server.linuxtechspace.com/emailAddress=admin@linuxtechspace.com
Getting CA Private Key
[root@openldap-server ~]# chown ldap:ldap /etc/openldap/certs/LTS*
[root@openldap-server ~]# ls -l /etc/openldap/certs/LTS*
-rw-r--r-- 1 ldap ldap 1387 Jun 13 20:10 LTSldap.crt
-rw-r--r-- 1 ldap ldap 1094 Jun 13 20:07 LTSldap.csr
-rw-r--r-- 1 ldap ldap 1675 Jun 13 20:06 LTSldap.key
-rw-r--r-- 1 ldap ldap 1675 Jun 13 20:01 LTSrootCA.key
-rw-r--r-- 1 ldap ldap 1505 Jun 13 20:03 LTSrootCA.pem
-rw-r--r-- 1 ldap ldap 17 Jun 13 20:10 LTSrootCA.srl
[root@openldap-server ~]# vi certs.ldif
dn: cn=config
changetype: modify
replace: olcTLSCertificateFile
olcTLSCertificateFile: /etc/openldap/certs/LTSldap.crt
-
replace: olcTLSCACertificateFile
olcTLSCACertificateFile: /etc/openldap/certs/LTSrootCA.pem
-
replace: olcTLSCertificateKeyFile
olcTLSCertificateKeyFile: /etc/openldap/certs/LTSldap.key
[root@openldap-server ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f certs.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
[root@openldap-server ~]# ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b "cn=config" olcTLSCACertificateFile olcTLSCertificateFile olcTLSCertificateKeyFile
dn: cn=config
olcTLSCertificateFile: /etc/openldap/certs/LTSldap.crt
olcTLSCACertificateFile: /etc/openldap/certs/LTSrootCA.pem
olcTLSCertificateKeyFile: /etc/openldap/certs/LTSldap.key
[root@openldap-server ~]# ldapadd -Y EXTERNAL -H ldapi:// -f /etc/openldap/schema/cosine.ldif
[root@openldap-server ~]# ldapadd -Y EXTERNAL -H ldapi:// -f /etc/openldap/schema/nis.ldif
[root@openldap-server ~]# ldapadd -Y EXTERNAL -H ldapi:// -f /etc/openldap/schema/inetorgperson.ldif
[root@openldap-server ~]# vi create_domain.ldif
dn: dc=linuxtechspace,dc=com
objectClass: dcObject
objectClass: organization
dc: linuxtechspace
o: linuxtechspace
dn: ou=users,dc=linuxtechspace,dc=com
objectClass: organizationalUnit
ou: users
[root@openldap-server ~]# ldapadd -x -W -D cn=root,dc=linuxtechspace,dc=com -f create_domain.ldif
Enter LDAP Password:
adding new entry "dc=linuxtechspace,dc=com"
adding new entry "ou=users,dc=linuxtechspace,dc=com"
Enter the LDAP root account password when prompted which we set in initial steps.
[root@openldap-server ~]# slappasswd
New password:
Re-enter new password:
{SSHA}r/xCHez+Sik4Y7TfirPDVXdsWuD7+Kd4
[root@openldap-server ~]#
[root@openldap-server ~]# vi create_test_user.ldif
dn: uid=test,ou=users,dc=linuxtechspace,dc=com
uid: test
cn: test
objectClass: shadowAccount
objectClass: top
objectClass: person
objectClass: inetOrgPerson
objectClass: posixAccount
userPassword: {SSHA}r/xCHez+Sik4Y7TfirPDVXdsWuD7+Kd4
shadowLastChange: 17016
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
loginShell: /bin/bash
uidNumber: 1002
gidNumber: 1002
homeDirectory: /home/test
sn: test
dn: cn=test,ou=users,dc=linuxtechspace,dc=com
objectClass: posixGroup
objectClass: top
cn: test
userPassword: {crypt}x
gidNumber: 1002
[root@openldap-server ~]# ldapadd -x -W -D cn=root,dc=linuxtechspace,dc=com -f create_test_user.ldif
Enter LDAP Password:
adding new entry "uid=test,ou=users,dc=linuxtechspace,dc=com"
adding new entry "cn=test,ou=users,dc=linuxtechspace,dc=com"
Enter the LDAP root account password when prompted which we set in initial steps.
[root@openldap-server ~]# vi /etc/sysconfig/slapd
SLAPD_URLS="ldapi:/// ldap:/// ldaps:///"
[root@openldap-server ~]# vi /etc/openldap/ldap.conf
TLS_CACERTDIR /etc/openldap/certs
TLS_REQCERT never
[root@openldap-server ~]# systemctl restart slapd
View OpenLDAP Server Configuration
[root@openldap-server ~]# ldapsearch -Y EXTERNAL -H ldapi:/// -b cn=config olcDatabase=\*
[root@openldap-server ~]# ldapsearch -x -b dc=linuxtechspace,dc=com
[root@openldap-server ~]# ldapsearch -x -b "dc=linuxtechspace,dc=com" "(cn=test)"
OpenLDAP Client Configuration
[root@openldap-client ~]# yum -y install openldap openldap-clients nss-pam-ldapd nscd
[root@openldap-client ~]# authconfig --enableldap --enableldapauth --ldapserver=ldaps://openldap-server.linuxtechspace.com \\
--ldapbasedn="dc=linuxtechspace,dc=com" --enablemkhomedir --disableldaptls --update
Check /etc/nsswitch.conf file to make sure ldap option is configured for following three parameters
[root@openldap-client ~]# vi /etc/nsswitch.conf
passwd: files sss ldap
shadow: files sss ldap
group: files sss ldap
[root@openldap-client ~]# vi /etc/nslcd.conf
tls_reqcert allow
Copy CA certificate from LDAP server
[root@openldap-client ~]# cd /etc/openldap/cacerts/
[root@openldap-client ~]# scp openldap-server:/etc/openldap/certs/LTSrootCA.pem .
Create the c hash of the CA certificate
[root@openldap-client ~]# /etc/pki/tls/misc/c_hash /etc/openldap/cacerts/LTSrootCA.pem
3646b900.0 => /etc/openldap/cacerts/LTSrootCA.pem
[root@openldap-client ~]# ln -s /etc/openldap/cacerts/LTSrootCA.pem 3646b900.0
[root@openldap-client ~]# ls -l /etc/openldap/cacerts
lrwxrwxrwx 1 root root 35 Jun 13 21:59 3646b900.0 -> /etc/openldap/cacerts/LTSrootCA.pem
-rw-r--r-- 1 root root 1505 Jun 13 21:58 LTSrootCA.pem
[root@openldap-client ~]# systemctl start nscd nslcd
[root@openldap-client ~]# systemctl enable nscd nslcd
[root@openldap-client ~]# getent passwd test
test:x:1002:1002:test:/home/test:/bin/bash
[root@openldap-client ~]#
login as: test
test@openldap-client's password:
Creating directory '/home/test'.
[test@openldap-client ~]$
We are all done now!.