pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0131-renew-agent-always-export-CSR-on-IPA-CA-certificate-.patch

483b06
From da3e6ab68f4f40b2851770fcc928b5bb93831c42 Mon Sep 17 00:00:00 2001
483b06
From: Jan Cholasta <jcholast@redhat.com>
483b06
Date: Mon, 24 Apr 2017 06:20:07 +0000
483b06
Subject: [PATCH] renew agent: always export CSR on IPA CA certificate renewal
483b06
483b06
Make sure a CSR is exported for the IPA CA whenever certmonger detects that
483b06
the CA certificate is about to expire.
483b06
483b06
This is a pre-requisite for using the `dogtag-ipa-ca-renew-agent-reuse` CA
483b06
instead of the `ipaCSRExport` virtual profile to export the CSR.
483b06
483b06
https://pagure.io/freeipa/issue/5799
483b06
483b06
Reviewed-By: David Kupka <dkupka@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 install/certmonger/dogtag-ipa-ca-renew-agent-submit | 11 +++++++++++
483b06
 1 file changed, 11 insertions(+)
483b06
483b06
diff --git a/install/certmonger/dogtag-ipa-ca-renew-agent-submit b/install/certmonger/dogtag-ipa-ca-renew-agent-submit
483b06
index 7b5489555d069856a6da7a21b5ab2b0f4dd4a41c..657a1bc638e1da680522c638e92914098fc6ab4b 100755
483b06
--- a/install/certmonger/dogtag-ipa-ca-renew-agent-submit
483b06
+++ b/install/certmonger/dogtag-ipa-ca-renew-agent-submit
483b06
@@ -451,6 +451,10 @@ def renew_ca_cert(reuse_existing, **kwargs):
483b06
     """
483b06
     This is used for automatic CA certificate renewal.
483b06
     """
483b06
+    csr = os.environ.get('CERTMONGER_CSR')
483b06
+    if not csr:
483b06
+        return (UNCONFIGURED, "Certificate request not provided")
483b06
+
483b06
     cert = os.environ.get('CERTMONGER_CERTIFICATE')
483b06
     if not cert:
483b06
         return (REJECTED, "New certificate requests not supported")
483b06
@@ -462,6 +466,13 @@ def renew_ca_cert(reuse_existing, **kwargs):
483b06
 
483b06
         if is_self_signed and not reuse_existing and is_renewal_master():
483b06
             state = 'request'
483b06
+
483b06
+        csr_file = paths.IPA_CA_CSR
483b06
+        try:
483b06
+            with open(csr_file, 'wb') as f:
483b06
+                f.write(csr)
483b06
+        except Exception as e:
483b06
+            return (UNREACHABLE, "Failed to write %s: %s" % (csr_file, e))
483b06
     elif operation == 'POLL':
483b06
         cookie = os.environ.get('CERTMONGER_CA_COOKIE')
483b06
         if not cookie:
483b06
-- 
483b06
2.9.3
483b06