Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| technical:fr-ldap [2026/07/24 10:10] – system | technical:fr-ldap [2026/07/26 18:39] (current) – [Configure OpenLDAP for ldaps] system | ||
|---|---|---|---|
| Line 287: | Line 287: | ||
| <code bash> | <code bash> | ||
| openssl req -new -x509 -days 3650 -key ca.key -sha256 -out ca.crt | openssl req -new -x509 -days 3650 -key ca.key -sha256 -out ca.crt | ||
| + | #### This is what we filled in #### | ||
| + | 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 ' | ||
| + | ----- | ||
| + | Country Name (2 letter code) [AU]:ZA | ||
| + | State or Province Name (full name) [Some-State]: | ||
| + | Locality Name (eg, city) []: | ||
| + | Organization Name (eg, company) [Internet Widgits Pty Ltd]: | ||
| + | Organizational Unit Name (eg, section) []:PKI | ||
| + | Common Name (e.g. server FQDN or YOUR name) []: | ||
| + | Email Address []: | ||
| + | </ | ||
| + | * Keep **ca.key** secret. | ||
| + | |||
| + | ==== Generate the LDAP server key ==== | ||
| + | * Issue the following command: | ||
| + | <code bash> | ||
| + | openssl genpkey -algorithm RSA -out ldap.key -pkeyopt rsa_keygen_bits: | ||
| + | </ | ||
| + | ==== Create an OpenSSL configuration ==== | ||
| + | * Create ldap.conf. Use the following as reference. | ||
| + | < | ||
| + | [req] | ||
| + | default_bits = 4096 | ||
| + | prompt = no | ||
| + | distinguished_name = dn | ||
| + | req_extensions = req_ext | ||
| + | |||
| + | [dn] | ||
| + | CN = ldap.radiusdesk.com | ||
| + | |||
| + | [req_ext] | ||
| + | subjectAltName = @alt_names | ||
| + | |||
| + | [alt_names] | ||
| + | DNS.1 = ldap.radiusdesk.com | ||
| + | DNS.2 = ldap | ||
| + | IP.1 = 127.0.0.1 | ||
| + | </ | ||
| + | * **Please Note**: The subjectAltName (SAN) is important. Modern TLS ignores the Common Name. | ||
| + | |||
| + | ==== Create the CSR ==== | ||
| + | * The following command will create the sign request: | ||
| + | <code bash> | ||
| + | openssl req -new -key ldap.key -out ldap.csr -config ldap.cnf | ||
| + | </ | ||
| + | |||
| + | ==== Sign the request ==== | ||
| + | * The following command will use the sign request to create a certificate: | ||
| + | <code bash> | ||
| + | openssl x509 -req -in ldap.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out ldap.crt -days 825 -sha256 -copy_extensions copy | ||
| + | </ | ||
| + | * Now you have the following files: | ||
| + | * **ca.crt** - The CA public file | ||
| + | * **ca.key** - The CA private file | ||
| + | * **ldap.key** - The LDAP private file | ||
| + | * **ldap.crt** | ||
| + | |||
| + | * Everything is now in place in terms of our PKI for us to configure slapd (OpenLDAP) to support ldaps. | ||
| + | |||
| + | ===== Configure OpenLDAP for ldaps ===== | ||
| + | * Issue the following commands | ||
| + | <code bash> | ||
| + | sudo mkdir / | ||
| + | #Copy the following files over | ||
| + | sudo cp ca.crt ldap.key ldap.crt / | ||
| + | #Change their permissions | ||
| + | sudo chown openldap: | ||
| + | sudo chmod 600 / | ||
| + | sudo chmod 644 / | ||
| + | </ | ||
| + | * Configure slapd to use those files. | ||
| + | * Create **tls.ldif** with the following contents | ||
| + | < | ||
| + | dn: cn=config | ||
| + | changetype: modify | ||
| + | replace: olcTLSCertificateFile | ||
| + | olcTLSCertificateFile: | ||
| + | - | ||
| + | replace: olcTLSCertificateKeyFile | ||
| + | olcTLSCertificateKeyFile: | ||
| + | - | ||
| + | replace: olcTLSCACertificateFile | ||
| + | olcTLSCACertificateFile: | ||
| + | </ | ||
| + | * Apply it to the directory with the following commnand: | ||
| + | < | ||
| + | sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f tls.ldif | ||
| + | </ | ||
| + | * Enable LDAPS by editing **/ | ||
| + | * Look for the following section and change accordingly: | ||
| + | <code bash> | ||
| + | # slapd normally serves ldap only on all TCP-ports 389. slapd can also | ||
| + | # service requests on TCP-port 636 (ldaps) and requests via unix | ||
| + | # sockets. | ||
| + | # Example usage: | ||
| + | # SLAPD_SERVICES=" | ||
| + | # | ||
| + | SLAPD_SERVICES=" | ||
| + | </code bash> | ||
| + | * Restart **slapd**. | ||
| + | < | ||
| + | sudo systemctl restart slapd | ||
| + | </ | ||
| + | * Confirm that it is now listening on port 636 also: | ||
| + | <code bash> | ||
| + | sudo ss -lnpt | grep 636 | ||
| + | LISTEN 0 2048 | ||
| + | LISTEN 0 2048 [:: | ||
| + | </ | ||
| + | * To make the cert's FQDN work smooth add it to the /etc/hosts file (ldap.radiusdesk.com in our case). | ||
| + | < | ||
| + | 127.0.0.1 localhost | ||
| + | 127.0.1.1 xubuntu-24-4 | ||
| + | 127.0.0.1 ldap.radiusdesk.com | ||
| + | |||
| + | # The following lines are desirable for IPv6 capable hosts | ||
| + | ::1 | ||
| + | fe00::0 ip6-localnet | ||
| + | ff00::0 ip6-mcastprefix | ||
| + | ff02::1 ip6-allnodes | ||
| + | ff02::2 ip6-allrouters | ||
| + | </ | ||
| + | * Test the certificate with the following command: | ||
| + | < | ||
| + | openssl s_client -connect ldap.radiusdesk.com: | ||
| + | |||
| + | #IT should end with something like this: | ||
| + | --- | ||
| + | SSL handshake has read 3905 bytes and written 401 bytes | ||
| + | Verification: | ||
| + | --- | ||
| + | New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384 | ||
| + | Server public key is 4096 bit | ||
| + | Secure Renegotiation IS NOT supported | ||
| + | Compression: | ||
| + | Expansion: NONE | ||
| + | No ALPN negotiated | ||
| + | Early data was not sent | ||
| + | Verify return code: 0 (ok) | ||
| + | |||
| + | </ | ||
| + | * You can now test with the ldapsearch utility. | ||
| + | <WRAP center round important> | ||
| + | Important is to specify the CA cert (LDAPTLS_CACERT) that ldapsearch needs to use else if **will fail**. | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | LDAPTLS_CACERT=/ | ||
| + | </ | ||
| + | <WRAP center round tip> | ||
| + | * If you want this CA to be part of the list of trusted CA's on the system you can do the following: | ||
| + | <code bash> | ||
| + | sudo cp / | ||
| + | sudo update-ca-certificates | ||
| + | #This is the output on our system | ||
| + | Updating certificates in / | ||
| + | rehash: warning: skipping ca-certificates.crt, | ||
| + | 1 added, 0 removed; done. | ||
| + | Running hooks in / | ||
| + | Processing triggers for ca-certificates-java (20240118) ... | ||
| + | Adding debian: | ||
| + | done. | ||
| + | done. | ||
| + | #Now we can just use plain ldapsearch | ||
| + | ldapsearch -H ldaps:// | ||
| + | </ | ||
| + | </ | ||
| + | ==== What does update-ca-certificates do? ==== | ||
| + | I like to know how things work. If you also like to know how things work the following insert is for you :-) | ||
| + | * The primary master CA file that is updated and can be used on Ubuntu is **/ | ||
| + | * This command rebuilds the system' | ||
| + | * **System Certificates: | ||
| + | * **Local Certificates: | ||
| + | * **Output:** It then generates the single, concatenated bundle file at **/ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ==== Update FreeRADIUS for ldaps:// ==== | ||
| + | * Do the following steps. | ||
| + | <code bash> | ||
| + | sudo su | ||
| + | #Copy the OpenLDAP' | ||
| + | cp / | ||
| + | </ | ||
| + | * Edit **/ | ||
| + | <code bash> | ||
| + | #Look for these items... | ||
| + | #server = ' | ||
| + | #---This has to match the cert' | ||
| + | server = ' | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # Port to connect on, defaults to 389, will be ignored for LDAP URIs. | ||
| + | ##port = 389 | ||
| + | #--We specify the ldaps port-- | ||
| + | port = 636 | ||
| + | |||
| + | #--- Then loop for the tls section | ||
| + | tls { | ||
| + | # Set this to ' | ||
| + | # to the LDAP database by using the StartTLS extended | ||
| + | # operation. | ||
| + | # | ||
| + | # The StartTLS operation is supposed to be | ||
| + | # used with normal ldap connections instead of | ||
| + | # using ldaps (port 636) connections | ||
| + | | ||
| + | #--- Disable start_tls since we are forcing ssl/tls --- | ||
| + | | ||
| + | #start_tls = yes | ||
| + | |||
| + | # | ||
| + | |||
| + | #--- The CA file from OpenLDAP-- | ||
| + | |||
| + | ca_file = / | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # Certificate Verification requirements. | ||
| + | # ' | ||
| + | # ' | ||
| + | # | ||
| + | # ' | ||
| + | # ' | ||
| + | # | ||
| + | # | ||
| + | # The default is libldap' | ||
| + | # on the contents of ldap.conf. | ||
| + | |||
| + | #---Enforce FreeRADIUS to check the validity of the certificate --- | ||
| + | | ||
| + | require_cert | ||
| + | |||
| + | # | ||
| + | # Check the CRL, as with the EAP module. | ||
| + | # | ||
| + | </ | ||
| + | * After you made these changes, restart FreeRADIUS in debug mode and to a test authentication to confirm that it is now using ldaps (port 636) | ||
| + | * See the results from out setup below: | ||
| + | <code bash> | ||
| + | rlm_ldap (ldap): Reserved connection (3) | ||
| + | (3) ldap: EXPAND (uid=%{%{Stripped-User-Name}: | ||
| + | (3) ldap: --> (uid=testuser) | ||
| + | (3) ldap: Performing search in " | ||
| + | (3) ldap: Waiting for search result... | ||
| + | (3) ldap: User object found at DN " | ||
| + | (3) ldap: Processing user attributes | ||
| + | (3) ldap: control: | ||
| + | rlm_ldap (ldap): Released connection (3) | ||
| + | Need more connections to reach 10 spares | ||
| + | rlm_ldap (ldap): Opening additional connection (7), 1 of 25 pending slots used | ||
| + | rlm_ldap (ldap): Connecting to ldap:// | ||
| + | rlm_ldap (ldap): Waiting for bind result... | ||
| + | rlm_ldap (ldap): Bind successful | ||
| + | |||
| </ | </ | ||
| - | ==== Install OpenLDAP ==== | ||