Skip to main content
LPIC-3 Exam 303

Secure LDAPS with 389-ds and CentOS 8

By November 7, 202020 Comments

Using secure LDAPS with 389-ds and CentOS 8Secure LDAPS Communication with 389-ds and CentOS 8

In this blogs we look at creating secure LDAPS con 389-ds LDAP server using CentOS 8

Of course, installing something like an LDAP server we might expect to be able to connect to it via both LDAP and LDAPS without any issues. Of course, you’ve been in the business long enough to know that this is not going to be the case whilst we will be able to communicate via LDAPS we will have to ignore some of the security features, and this is not desirable. We are going to step you through the process of installing the 389 directory service on CentOS eight, once it’s installed we can see how we can communicate through the existing protocols. Having identified the errors that we get, we will then proceed to create our own certificate authority and issue correctly signed openSSL certificates to the server.

Having secure LDAPS communication to the 389-ds instance is important as user password for CentOS and other OSs may be stored in LDAP. We need this to be encrypted on the wrie to ensure secure and safe transmission.

The Installation of 389-DS

To install the 389-DS LDAP and secure LDAPS server, we will add the EPEL repository to our CentOS 8.2 System. Using the default profile for the module, we will also install the Cockpit wen interface front-end that can be used to manage the openLDAP directory behind 389-ds

# yum install -y epel-release
# yum update -y epel-release
# yum module install -y 389-directory-server:stable/default

 


Configure a 389-DS Directory Instance on CentOS

Having installed the package, we still need to configure and instance of an openLDAP directory. One server can host multiple Directory trees if required. The 389-ds instance can be configured using the command dscreate. We can run it interactively and answer questions using:

# dscreate interactive

We can use and answer file:

# dscreate from-file <nameoffile>

Lastly, we can create a template and edit. This option is goo to learn the options that we can set.

# dscreate create-template t1.conf

We can edit the template file as required. We leave the file so it looks as in the following:

[general]
config_version = 2
selinux = True

[slapd]
instance_name = localhost
root_dn = cn=Directory Manager
root_password = Password1

[backend-userroot]
sample_entries = yes
suffix = dc=example,dc=com
  • config_version: The file format that we are using. This is the default value of 2 that we use.
  • selinux: We are using CentOS 8 where SELinux is enabled, so we will use SELinux, there is no reason not to
  • instance_name: localhost is the default instance name, we can keep this, but it DOES NOT mean that we only listen on the localhost interface
  • root_dn: This is the account name that is used to manage the Directory
  • root_password: This is the password that will be used to manage directory entries for the root dn above
  • sample_entries: We create entries in the tree. Useful for testing and we always delete them later
  • suffix: This is the root entry or top of the directory tree that we create. All entries will have this as their entry suffix.

Creating 389-ds Instance and Testing with LDAP and Secure LDAPS on CentOS

Having created the template, we can now create the 389-ds directory instance:

# dscreate from-file t1.conf
# ss -ntl

The output of the ss command will show that the system is now listening on TCP ports 389 (LDAP) and 636 (LDAPS). From this we may think that the system is working. To a degree it is, but the SSL/TLS certificates are self-signed and not acceptable to the system. We can test this using openssl.

# openssl s_client -connect localhost:636

The final line of output will indicate an error 19 and self-signed certificate in tree. It is not just openssl that will fail, using utilities such as ldapserach will also fail on TLS:

# ldapsearch -H ldap://localhost:389 -D 'cn=Directory Manager' -W -Z -b 'dc=example,dc=com' -x

Even though we connect with LDAP, we can still ask for LDAPS using the option -Z (StartTLS). The connect fails because of the self-signed certificate. We can prove that we can connect without TLS, by removing the option -Z so we use LDAP not LDAPS:

# ldapsearch -H ldap://localhost:389 -D 'cn=Directory Manager' -W  -b 'dc=example,dc=com' -x

The connection now is OK. TLS and LDAPS is the problem and the use of self-signed certificates. We need to correct this issue if we want secure LDAP with the 389-ds. We can see that we can yse secure LDAPS but only if we ignore the server authentication. This is not OK and notx want we want. We need to have LDAPS really secure on 389-ds on CentOS by setting up our own CA.

Create Secure OpenSSL Certificate Authority

We can spend a lot of time and effort in creating an OpenSSL Certificate Authority; however, we can create a cut down CA quite easily if we choose. Long term, we may prefer to create a better CA, but, for simplicity this smaller version works, needing much less configuration.

# cd
# mkdir ca
# cd ca
# openssl genrsa -des -out myca.key 4096
# openssl req -x509 -new -nodes -key myca.key -sha256 -days 3650 -out myca.pem

The last command will prompt for the certificate details. We add GB as the country, England and the state, Peterborough as the city and The Urban Penguin as the organization. We don’t add the OU and we use a CN of MyCA. That my fried is a simple openSSL CA with minimal configuration. The CA’s public key needs to be trusted by all clients. We will test just with this single host and will add in the trust relationship:

# cp myca.pem /etc/pki/ca-trust/source/anchors/
# update-ca-trust extract

The location used is correct for CentOS 8 as is the command. You will need to check with your own OS is using another distribution or OS.

Create Secure Server Key and CSR

We now need a private key for the server and a certificate signing request. The CSR will be sent to the CA to sign creating the trust to the OS.

# openssl genrsa -out server.key 2048
# openssl req -new -key server.key -out server.csr
# echo "127.0.0.2 www.example.com" >> /etc/hosts

In the CSR we are prompted for the certificate details. The CN is most important as it must match the FQDN that clients will use to access the server. We use www.example.com and create a local host record to match. Ideally, this would be in DNS so all clints could resolve the name.

Sign CSR

To sign the CSR we must have access to the CA’s private key and certificate and know the password of the CA’s private key.

# openssl x509 -req -in server.csr -CA myca.pem -CAkey myca.key -CAcreateserial -out server.pem -days 365 -sha256

This creates the server’s signed public key. We now have a usable public key and private key pair for the server.

Export Server Key and Certificate

The 389-DS using the NSS database to store keys and certificates. The Server key and certificate need to be in a single P12 file to be imported to the database. OpenSSL can export the files:

# openssl pkcs12 -export -inkey /root/ca/server.key -in /root/ca/server.pem -out /tmp/crt.p12 -nodes -name Server-Cert

With that last step, we are finished with the /root/ca directory for the moment. We can move on to concentrate and adding these files to 389-ds for use with LDAPS.

Configure LDAPS on 389-DS Running on CentOS 8

We mode to the instance directory.

# cd /etc/dirsrv/slapd-localhost

We use the certutil command to list certificates:

# certutil -L -d .

That is -L to list and -d for the directory which we reference as period for the current directory.

We remove the current entries for the self-signed CA and and Server-Cert:

# certutil -D -d . -n Server-Cert
# certutil -D -d . -n Self-Signed-CA

Importing date to the NSS database will require the PIN or Password. We get this from the pin.txt file. Copy the PIN to your clipboard, the pin starts after the colon.

# cat pin.txt
# certutil -d . -A -n "MyCA" -t CT,, -a -i /root/ca/myca.pem
# pk12util -i /tmp/crt.p12 -d .
# systemctl restart dirsrv@localhost.service

The CA public key is imported directory from the /root/ca directory. The server key pair comes from the exported P12 file. We then restart the instance if the LDAP 389-ds server.

Final Testing

The CA is trusted by the OS. It is not self-signed. The server has a signed certificate from the trusted CA so we are ready to go:

 

# openssl s_client -connect 127.0.0.1:636 -showcerts
# ldapsearch -H ldap://www.example.com -D 'cn=Directory Manager' -W -Z -b 'dc=example,dc=com'

 

Both commands work! The video follows:

 

 

20 Comments

  • DavidPEW says:

    [url=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]республика авто реальные отзывы[/url]
    [url=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]https://www.autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/[/url]
    [url=https://cse.google.bg/url?q=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]http://actontv.org/?URL=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/[/url]

  • DavidPEW says:

    [url=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]официальный дилер республика отзывы[/url]
    [url=http://www.autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/[/url]
    [url=http://google.kg/url?q=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/]https://cse.google.dk/url?q=https://autoru-otzyv.ru/otzyvy-avtosalon/respublika-auto/[/url]

  • Eduardosak says:

    [url=http://www.kremlinrus.ru/article/455/151796/]Elena Likhach wife[/url]
    [url=https://www.kremlinrus.ru/article/455/151796/]https://www.kremlinrus.ru/article/455/151796/[/url]
    [url=https://google.cv/url?q=http://www.kremlinrus.ru/article/455/151796/]http://www.9998494.ru/R.ashx?s=www.http://www.kremlinrus.ru/article/455/151796/%5B/url%5D

  • JamescOm says:

    [url=https://www.ogirk.ru/2022/07/18/tvorchestvo-eleny-lihach-vchera-segodnja-zavtra/]Елена Лихач[/url]
    [url=http://ogirk.ru/2022/07/18/tvorchestvo-eleny-lihach-vchera-segodnja-zavtra/]http://ogirk.ru/2022/07/18/tvorchestvo-eleny-lihach-vchera-segodnja-zavtra/[/url]
    [url=https://www.google.nl/url?q=https://www.ogirk.ru/2022/07/18/tvorchestvo-eleny-lihach-vchera-segodnja-zavtra/]http://google.com.et/url?q=https://www.ogirk.ru/2022/07/18/tvorchestvo-eleny-lihach-vchera-segodnja-zavtra/[/url]

  • Lancerap says:

    [url=https://elena-likhach.ru/]Елена Лихач муж[/url]
    [url=https://www.elena-likhach.ru]https://elena-likhach.ru[/url]
    [url=http://www.google.mg/url?q=https://elena-likhach.ru/]http://google.co.za/url?q=https://elena-likhach.ru/[/url]

  • Lancerap says:

    [url=https://elena-likhach.ru/]Елена Лихач сколько лет[/url]
    [url=https://www.elena-likhach.ru]http://elena-likhach.ru[/url]
    [url=http://cse.google.ci/url?q=https://elena-likhach.ru/]http://google.fi/url?q=https://elena-likhach.ru/[/url]

  • JohnnieSlunk says:

    [url=https://www.litprichal.ru/press/311/]Елена Лихач стихи[/url]
    [url=http://www.litprichal.ru/press/311/]https://www.litprichal.ru/press/311/[/url]
    [url=http://maps.google.lk/url?q=https://www.litprichal.ru/press/311/]http://maps.google.ht/url?q=https://www.litprichal.ru/press/311/[/url]

  • JohdnieSlunk says:

    [url=https://www.ereport.ru/prel/elena-lihach-poetessa-sovremennosti-detstvo-i-rannyaya-yunost.htm]Елена Лихач стихи[/url]
    [url=https://ereport.ru/prel/elena-lihach-poetessa-sovremennosti-detstvo-i-rannyaya-yunost.htm]http://www.ereport.ru/prel/elena-lihach-poetessa-sovremennosti-detstvo-i-rannyaya-yunost.htm[/url]
    [url=http://www.flc.ie/?URL=https://www.ereport.ru/prel/elena-lihach-poetessa-sovremennosti-detstvo-i-rannyaya-yunost.htm]https://google.cc/url?q=https://www.ereport.ru/prel/elena-lihach-poetessa-sovremennosti-detstvo-i-rannyaya-yunost.htm[/url]

  • AlfonsoTauts says:

    [url=http://specodegdaoptom.ru/]магазин округ спецодежда[/url]
    [url=http://www.specodegdaoptom.ru/]http://www.specodegdaoptom.ru/[/url]
    [url=http://google.info/url?q=http://specodegdaoptom.ru/]https://www.google.iq/url?q=http://specodegdaoptom.ru/[/url]

  • AlfonsoTauts says:

    [url=http://specodegdaoptom.ru/]магазины спецодежды в москве адреса[/url]
    [url=http://www.specodegdaoptom.ru]http://www.specodegdaoptom.ru[/url]
    [url=http://maps.google.jo/url?q=http://specodegdaoptom.ru/]http://google.com.gi/url?q=http://specodegdaoptom.ru/[/url]

  • DavidDem says:

    [url=https://dorog-asfaltirovanie.ru/]сколько стоит укладка асфальта[/url]
    [url=https://www.dorog-asfaltirovanie.ru]http://www.dorog-asfaltirovanie.ru[/url]
    [url=http://maps.google.gm/url?q=https://dorog-asfaltirovanie.ru/]http://maps.google.lk/url?q=https://dorog-asfaltirovanie.ru/[/url]

  • Francispaype says:

    [url=https://stroim-doma-rf.ru/]строительство индивидуальных домов[/url]
    [url=http://www.stroim-doma-rf.ru]https://www.stroim-doma-rf.ru/[/url]
    [url=http://cse.google.com/url?q=https://stroim-doma-rf.ru/]https://google.de/url?q=https://stroim-doma-rf.ru/[/url]

  • Warrannow says:

    [url=https://prodvizhenie-saitov-24.ru/]продвижение сайта услуги[/url]
    [url=http://prodvizhenie-saitov-24.ru]http://www.prodvizhenie-saitov-24.ru/[/url]
    [url=http://cherrybb.jp/test/link.cgi/https://prodvizhenie-saitov-24.ru/]https://google.lk/url?q=https://prodvizhenie-saitov-24.ru/[/url]

  • Warrannow says:

    [url=https://prodvizhenie-saitov-24.ru/]поисковое продвижение интернет магазина[/url]
    [url=http://prodvizhenie-saitov-24.ru/]http://www.prodvizhenie-saitov-24.ru[/url]
    [url=http://google.com.au/url?q=https://prodvizhenie-saitov-24.ru/]http://www.google.sr/url?q=https://prodvizhenie-saitov-24.ru/[/url]

  • JasonJox says:

    [url=https://urflex.ru/registraciya-nekommercheskoj-organizacii.html]Ликвидация ООО[/url]
    [url=https://urflex.ru]https://www.urflex.ru[/url]
    [url=https://google.to/url?q=https://urflex.ru/]https://www.wilsonlearning.com/?URL=https://urflex.ru/[/url]

  • RobertHip says:

    [url=http://lex-center.ru/?page_id=31]как получить условный срок но не реальный[/url]
    [url=http://lex-center.ru]http://lex-center.ru/[/url]
    [url=https://www.google.dz/url?q=http://lex-center.ru/]http://www.google.nl/url?q=http://lex-center.ru/[/url]

  • JasonJox says:

    [url=https://urflex.ru/bankrotstvo-fizicheskogo-lica.html]Регистрация некоммерческих организаций[/url]
    [url=http://www.urflex.ru/]http://urflex.ru[/url]
    [url=https://www.google.dm/url?q=https://urflex.ru/]http://www.google.cg/url?q=https://urflex.ru/[/url]

  • Warrennow says:

    [url=https://prodvizhenie-saitov-24.ru/]продвижение интернет магазина цены[/url]
    [url=http://prodvizhenie-saitov-24.ru/]https://prodvizhenie-saitov-24.ru[/url]
    [url=http://www.google.je/url?q=https://prodvizhenie-saitov-24.ru/]https://www.semanticjuice.com/site/https://prodvizhenie-saitov-24.ru/[/url]

  • Warrennow says:

    [url=https://prodvizhenie-saitov-24.ru/]поисковое продвижение сайта в яндекс[/url]
    [url=http://prodvizhenie-saitov-24.ru/]https://www.prodvizhenie-saitov-24.ru[/url]
    [url=http://google.ca/url?q=https://prodvizhenie-saitov-24.ru/]http://ip.webmasterhome.cn/?ip=https://prodvizhenie-saitov-24.ru/[/url]

  • Bricesen says:

    [url=https://eroticheskiy-massage-kazan.ru]эротический массаж казань цена[/url]
    [url=https://eroticheskiy-massage-kazan.ru]https://eroticheskiy-massage-kazan.ru[/url]
    [url=https://www.google.iq/url?q=https://eroticheskiy-massage-kazan.ru]http://www.apalanj.org/?URL=https://eroticheskiy-massage-kazan.ru[/url]

Leave a Reply