From f6f6f83dca22fb23ee2a7dd1b2925a74fe395afe Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Fri, 17 May 2019 16:30:47 +1000 Subject: [PATCH] upgrade: add profile to Dogtag tracking requests To use profile-based renewal (rather than "renewal existing cert" renewal which is brittle against database corruption or deleted certificate / request objects), Certmonger tracking requests for Dogtag system certs must record the profile to be used. Update the upgrade method that checks tracking requests to look for the profile. Tracking requests will be recreated if the expected data are not found. The code that actually adds the tracking requests was updated in a previous commit. Part of: https://pagure.io/freeipa/issue/7991 Reviewed-By: Rob Crittenden --- ipaserver/install/cainstance.py | 3 ++ ipaserver/install/krainstance.py | 3 ++ ipaserver/install/server/upgrade.py | 57 +++++++++-------------------- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py index a609b9953..b732e1b9a 100644 --- a/ipaserver/install/cainstance.py +++ b/ipaserver/install/cainstance.py @@ -267,6 +267,9 @@ class CAInstance(DogtagInstance): 2 = have signed cert, continue installation """ + # Mapping of nicknames for tracking requests, and the profile to + # use for that certificate. 'configure_renewal()' reads this + # dict. The profile MUST be specified. tracking_reqs = { 'auditSigningCert cert-pki-ca': 'caSignedLogCert', 'ocspSigningCert cert-pki-ca': 'caOCSPCert', diff --git a/ipaserver/install/krainstance.py b/ipaserver/install/krainstance.py index e083400f1..4f8849b73 100644 --- a/ipaserver/install/krainstance.py +++ b/ipaserver/install/krainstance.py @@ -60,6 +60,9 @@ class KRAInstance(DogtagInstance): be the same for both the CA and KRA. """ + # Mapping of nicknames for tracking requests, and the profile to + # use for that certificate. 'configure_renewal()' reads this + # dict. The profile MUST be specified. tracking_reqs = { 'auditSigningCert cert-pki-kra': 'caInternalAuthAuditSigningCert', 'transportCert cert-pki-kra': 'caInternalAuthTransportCert', diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py index 07991204f..40f607117 100644 --- a/ipaserver/install/server/upgrade.py +++ b/ipaserver/install/server/upgrade.py @@ -972,48 +972,27 @@ def certificate_renewal_update(ca, ds, http): template = paths.CERTMONGER_COMMAND_TEMPLATE serverid = ipaldap.realm_to_serverid(api.env.realm) - requests = [ - { + requests = [] + + dogtag_system_nicks = ( + list(cainstance.CAInstance.tracking_reqs) + + [cainstance.CAInstance.server_cert_name] + ) + for nick in dogtag_system_nicks: + req = { 'cert-database': paths.PKI_TOMCAT_ALIAS_DIR, - 'cert-nickname': 'auditSigningCert cert-pki-ca', + 'cert-nickname': nick, 'ca-name': 'dogtag-ipa-ca-renew-agent', 'cert-presave-command': template % 'stop_pkicad', 'cert-postsave-command': - (template % 'renew_ca_cert "auditSigningCert cert-pki-ca"'), - }, - { - 'cert-database': paths.PKI_TOMCAT_ALIAS_DIR, - 'cert-nickname': 'ocspSigningCert cert-pki-ca', - 'ca-name': 'dogtag-ipa-ca-renew-agent', - 'cert-presave-command': template % 'stop_pkicad', - 'cert-postsave-command': - (template % 'renew_ca_cert "ocspSigningCert cert-pki-ca"'), - }, - { - 'cert-database': paths.PKI_TOMCAT_ALIAS_DIR, - 'cert-nickname': 'subsystemCert cert-pki-ca', - 'ca-name': 'dogtag-ipa-ca-renew-agent', - 'cert-presave-command': template % 'stop_pkicad', - 'cert-postsave-command': - (template % 'renew_ca_cert "subsystemCert cert-pki-ca"'), - }, - { - 'cert-database': paths.PKI_TOMCAT_ALIAS_DIR, - 'cert-nickname': 'caSigningCert cert-pki-ca', - 'ca-name': 'dogtag-ipa-ca-renew-agent', - 'cert-presave-command': template % 'stop_pkicad', - 'cert-postsave-command': - (template % 'renew_ca_cert "caSigningCert cert-pki-ca"'), - 'template-profile': None, - }, - { - 'cert-database': paths.PKI_TOMCAT_ALIAS_DIR, - 'cert-nickname': 'Server-Cert cert-pki-ca', - 'ca-name': 'dogtag-ipa-ca-renew-agent', - 'cert-presave-command': template % 'stop_pkicad', - 'cert-postsave-command': - (template % 'renew_ca_cert "Server-Cert cert-pki-ca"'), - }, + (template % 'renew_ca_cert "{}"'.format(nick)), + } + profile = cainstance.CAInstance.tracking_reqs.get(nick) + if profile: + req['template-profile'] = profile + requests.append(req) + + requests.append( { 'cert-file': paths.RA_AGENT_PEM, 'key-file': paths.RA_AGENT_KEY, @@ -1021,7 +1000,7 @@ def certificate_renewal_update(ca, ds, http): 'cert-presave-command': template % 'renew_ra_cert_pre', 'cert-postsave-command': template % 'renew_ra_cert', }, - ] + ) logger.info("[Update certmonger certificate renewal configuration]") if not ca.is_configured():