第 22 章 Recovering from expired system certificates
If Identity Management (IdM) certificates expire, core services such as the Web UI, LDAP, and certificate issuance fail. Commands like ipa-certupdate and ipa-cacert-manage do not work because the system cannot establish secure connections. The following sections provide procedures for several critical failure scenarios.
Before making any changes, create a full backup of your IdM servers. At a minimum, create a file-level backup of critical data on each server:
# tar czvf /root/pki-backup_$(hostname -f)_$(date +%F).tar.gz /etc/dirsrv/slapd-* /etc/pki/pki-tomcat/ /var/lib/ipa/ /var/kerberos/krb5kdc/
Do not proceed without a reliable backup.
Use the ipa-cert-fix command with extreme caution. ipa-cert-fix is a powerful but intrusive tool designed for a specific failure scenario: expired service certificates on the renewal server.
-
Do not run
ipa-cert-fixif the CA certificate itself is expired. -
Do not run
ipa-cert-fixon a replica server, except if the renewal server is in an unrecoverable state. Open a support ticket if you find yourself in this situation. -
Do not run
ipa-cert-fixas a general troubleshooting tool.
Misusing this tool can make the situation worse.
In this failure scenario, the renewal server is healthy, but one or more replicas have failed to renew their certificates and are now offline. The goal is to manually synchronize or re-issue the necessary certificates from the server to restore the replica.
This procedure covers four critical certificates: the RA Agent certificate, the Subsystem certificate, the Directory Server (LDAP) certificate, and the PKI Tomcat (Web Server) certificate.
If you are unsure which server is the renewal server, run the following command on any IdM server. The command output is the distinguished name (DN) of the CA renewal server:
# ldapsearch -Y GSSAPI -b cn=masters,cn=ipa,cn=etc,dc=example,dc=com ipaConfigString=caRenewalMaster dn
If Kerberos is unavailable, use the following command with the Directory Manager password:
# ldapsearch -x -D 'cn=Directory Manager' -W -b cn=masters,cn=ipa,cn=etc,dc=example,dc=com ipaConfigString=caRenewalMaster dn
Procedure
Verify that the IdM services are running:
# ipactl statusOptional. If any of the services are not running, force them to start:
# ipactl start -fThe
-for--forceflag bypasses some of the startup checks, which is necessary when services cannot communicate due to expired certificates.Compare RA Agent and Subsystem certificates between the renewal server and the failing replica.
On both the healthy renewal server and the failing replica, retrieve the serial numbers of the RA agent and subsystem certificates, and verify that they are identical.
RA Agent certificate and its corresponding LDAP entry. The serial number is the second value in the semicolon-separated
descriptionattribute string, for example2;SERIAL;…:# openssl x509 -in /var/lib/ipa/ra-agent.pem -noout -serial # ldapsearch -D "cn=directory manager" -W -b "uid=ipara,ou=people,o=ipaca" descriptionSubsystem certificate and its corresponding LDAP entry. The serial number is the second value in the semicolon-separated
descriptionattribute string, for example2;SERIAL;…:# certutil -L -d /etc/pki/pki-tomcat/alias/ -n 'subsystemCert cert-pki-ca' | grep "Serial Number" # ldapsearch -D "cn=directory manager" -W -b "uid=pkidbuser,ou=People,o=ipaca" descriptionIf the serial numbers on the replica do not match those on the CA renewal server, proceed with the next steps to synchronize them.
Manually copy the healthy certificates to the replica. From the renewal server, copy the
ra-agent.pemand the subsystem certificate to the failing replica.Copy the RA agent certificate file:
# scp /var/lib/ipa/ra-agent.pem root@failed-replica.idm.example.com:/tmp/Export the subsystem certificate:
# certutil -L -d /etc/pki/pki-tomcat/alias -n 'subsystemCert cert-pki-ca' -a > /tmp/subsystem.pemCopy the subsystem certificate:
# scp /tmp/subsystem.pem root@failed-replica.idm.example.com:/tmp/
On the failing replica, replace the expired RA agent certificate.
Copy the healthy certificate into place:
# cp /tmp/ra-agent.pem /var/lib/ipa/ra-agent.pemUpdate the corresponding entry in LDAP to ensure it contains the correct certificate blob and serial number. This step requires the Directory Manager password.
Prepare the new RA agent certificate for LDAP by converting it to a single-line blob and storing it in a variable:
# RA_CERT_BLOB=$(sed -rn '/^-----BEGIN CERTIFICATE-----$/{:1;n;/^-----END CERTIFICATE-----$/b2;H;b1};:2;${x;s/\s//g;p}' /tmp/ra-agent.pem)Extract the serial number from the new certificate and store it in a variable:
# RA_CERT_SERIAL=$(openssl x509 -in /tmp/ra-agent.pem -noout -serial | cut -d'=' -f2)Ensure the IdM services are running before attempting to modify the LDAP database:
# ipactl start -fUpdate the LDAP entry for the RA agent with the new certificate blob and serial number. You will be prompted for the Directory Manager password:
# ldapmodify -D "cn=Directory Manager" -W -x <<EOF dn: uid=ipara,ou=people,o=ipaca changetype: modify add: userCertificate userCertificate:: ${RA_CERT_BLOB} replace: description description: 2;${RA_CERT_SERIAL};CN=Certificate Authority,O=IDM.EXAMPLE.COM;CN=IPA RA,O=IDM.EXAMPLE.COM EOFReplace
IDM.EXAMPLE.COMwith your IdM realm or use your custom certificate subject base.
On the failing replica, replace the expired subsystem certificate.
Import the healthy certificate into the NSS database. This requires the NSS database password, which can be found in
/etc/pki/pki-tomcat/password.conf.Set a variable for the location of the NSS database password file for easier use in the following commands:
# PWDFILE=/etc/pki/pki-tomcat/alias/pwdfile.txtRemove the old, expired subsystem certificate from the NSS database:
# certutil -D -d /etc/pki/pki-tomcat/alias -n 'subsystemCert cert-pki-ca' -f $PWDFILEAdd the new, healthy subsystem certificate from the
/tmp/subsystem.pemfile to the NSS database:# certutil -A -d /etc/pki/pki-tomcat/alias -n 'subsystemCert cert-pki-ca' -t ",," -i /tmp/subsystem.pem -f $PWDFILE
Update the corresponding entry in LDAP, similar to the RA agent step:
# SUBSYS_CERT_BLOB=$(cat /tmp/subsystem.pem | sed -rn '/^-----BEGIN CERTIFICATE-----$/{:1;n;/^-----END CERTIFICATE-----$/b2;H;b1};:2;${x;s/\s//g;p}') # SUBSYS_CERT_SERIAL=$(openssl x509 -in /tmp/subsystem.pem -noout -serial | cut -d'=' -f2) # ldapmodify -D "cn=Directory Manager" -W -x <<EOF dn: uid=pkidbuser,ou=people,o=ipaca changetype: modify add: userCertificate userCertificate:: ${SUBSYS_CERT_BLOB} replace: description description: 2;${SUBSYS_CERT_SERIAL};CN=Certificate Authority,O=IDM.EXAMPLE.COM;CN=CA Subsystem,O=IDM.EXAMPLE.COM EOFReplace
IDM.EXAMPLE.COMwith your IdM realm or use your custom certificate subject base.
Manually issue a temporary certificate for the replica’s LDAP service.
On the failing replica, generate a Certificate Signing Request (CSR) from the existing key in the Directory Server’s NSS database:
# DS_INSTANCE=$(grep ldap_uri /etc/ipa/default.conf | sed -n 's|.%2Frun%2F\(slapd-\)\.socket.|\1|p')* # LDAP_CERT_NICKNAME=$(grep nsSSLPersonalitySSL "/etc/dirsrv/${DS_INSTANCE}/dse.ldif" | awk '{ print $2 }') # HOSTNAME=$(hostname -f) # PWDFILE="/etc/dirsrv/${DS_INSTANCE}/pwdfile.txt" # certutil -R -d "/etc/dirsrv/${DS_INSTANCE}" -k ${LDAP_CERT_NICKNAME} -n ${LDAP_CERT_NICKNAME} -s "CN=${HOSTNAME}" -a -f "${PWDFILE}" -8 "${HOSTNAME}" -o /tmp/ldap.csr注意The command above creates
/tmp/ldap.csr. Some versions ofcertutilmay add extra text to the file. Ensure the file contains only the-----BEGIN NEW CERTIFICATE REQUEST-----block and nothing else.If the certificate is signed by the IdM CA:
On the failing replica, copy the CSR to the renewal server:
# scp /tmp/ldap.csr root@renewal-master.idm.example.com:/tmp/On the renewal server, sign the CSR. Use the
ldap/principal to ensure the certificate is valid for GSSAPI binds:# ipa cert-request /tmp/ldap.csr --principal="ldap/$(hostname -f)" --certificate-out=/tmp/ldap.pemOn the renewal server, copy the new certificate back to the replica:
# scp /tmp/ldap.pem root@failed-replica.idm.example.com:/tmp/On the failing replica, import the new certificate into the Directory Server’s NSS database:
# certutil -D -d "/etc/dirsrv/${DS_INSTANCE}" -n ${LDAP_CERT_NICKNAME} -f "${PWDFILE}" # certutil -A -d "/etc/dirsrv/${DS_INSTANCE}" -n ${LDAP_CERT_NICKNAME} -t ",," -i /tmp/ldap.pem -f "${PWDFILE}"
If the certificate is signed by an external CA:
-
Take the
/tmp/ldap.csrfile and submit it to your external Certificate Authority for signing. -
Once you receive the new certificate file (for example,
new_ldap_cert.pem), copy it securely to the/tmp/directory on the failing replica and rename it toldap.pem. On the failing replica, import the new certificate into the Directory Server’s NSS database:
# certutil -D -d "/etc/dirsrv/${DS_INSTANCE}" -n ${ LDAP_CERT_NICKNAME} -f "${PWDFILE}" # certutil -A -d "/etc/dirsrv/${DS_INSTANCE}" -n ${ LDAP_CERT_NICKNAME} -t ",," -i /tmp/ldap.pem -f "${PWDFILE}"
-
Take the
Manually issue a temporary certificate for the replica’s PKI Tomcat service.
On the affected replica, generate a CSR using the existing key stored in the PKI Tomcat NSS database:
# HOSTNAME=$(hostname -f) # PWDFILE="/etc/pki/pki-tomcat/alias/pwdfile.txt" # certutil -R -d /etc/pki/pki-tomcat/alias -k 'Server-Cert cert-pki-ca' -n 'Server-Cert cert-pki-ca' -s "CN=${HOSTNAME},O=IDM.EXAMPLE.COM" -a -f "${PWDFILE}" -o /tmp/server-cert.csrReplace
IDM.EXAMPLE.COMwith your IdM realm or use your custom certificate subject base.On the failing replica, copy the CSR to the renewal server:
# scp /tmp/server-cert.csr root@renewal-master.idm.example.com:/tmp/On the renewal server, sign the CSR. Use the
host/principal for the web server certificate:# ipa cert-request /tmp/server-cert.csr --principal="host/$(hostname -f)" --certificate-out=/tmp/server-cert.pemOn the renewal server, copy the new certificate back to the replica:
# scp /tmp/server-cert.pem root@failed-replica.idm.example.com:/tmp/On the failing replica, import the new certificate into the PKI Tomcat NSS database:
# certutil -D -d /etc/pki/pki-tomcat/alias -n 'Server-Cert cert-pki-ca' -f "${PWDFILE}" # certutil -A -d /etc/pki/pki-tomcat/alias -n 'Server-Cert cert-pki-ca' -t ",," -i /tmp/server-cert.pem -f "${PWDFILE}"
Restart services and renew remaining certificates.
Restart the IdM services on the replica to use the new certificates:
# ipactl restartRestart the
certmongerservice to apply the manual changes. Once restarted, it should begin attempting to renew any remaining certificates:# systemctl restart certmonger-
You can watch the renewal process by periodically running
getcert list | grep -E "Request ID|status|expires". Once all certificates are in theMONITORINGstate, the process is complete. The
certmongerservice should now be able to communicate with the CA. If one or more certificates remain unrenewed after a few minutes, consider renewing them manually:# getcert list # getcert resubmit -i <REQUEST_ID>