Blame SOURCES/0016-Set-mode-of-etc-ipa-ca.crt-to-0644-in-CA-less-instal_rhbz#1870202.patch

91acb2
From 4a97145c3a76a4d9ebf52b3905410a0bd7bec856 Mon Sep 17 00:00:00 2001
91acb2
From: Rob Crittenden <rcritten@redhat.com>
91acb2
Date: Tue, 4 Aug 2020 15:09:56 -0400
91acb2
Subject: [PATCH] Set mode of /etc/ipa/ca.crt to 0644 in CA-less installations
91acb2
91acb2
It was previously being set to 0444 which triggered a warning
91acb2
in freeipa-healthcheck.
91acb2
91acb2
Even root needs DAC_OVERRIDE capability to write to a 0o444 file
91acb2
which may not be available in some environments.
91acb2
91acb2
https://pagure.io/freeipa/issue/8441
91acb2
91acb2
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
91acb2
---
91acb2
 ipaserver/install/certs.py          | 2 +-
91acb2
 ipaserver/install/server/install.py | 5 ++---
91acb2
 2 files changed, 3 insertions(+), 4 deletions(-)
91acb2
91acb2
diff --git a/ipaserver/install/certs.py b/ipaserver/install/certs.py
91acb2
index 22ee79bd1..51d9f9221 100644
91acb2
--- a/ipaserver/install/certs.py
91acb2
+++ b/ipaserver/install/certs.py
91acb2
@@ -329,7 +329,7 @@ class CertDB:
91acb2
         ipautil.backup_file(cacert_fname)
91acb2
         root_nicknames = self.find_root_cert(nickname)[:-1]
91acb2
         with open(cacert_fname, "w") as f:
91acb2
-            os.fchmod(f.fileno(), stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
91acb2
+            os.fchmod(f.fileno(), 0o644)
91acb2
             for root in root_nicknames:
91acb2
                 result = self.run_certutil(["-L", "-n", root, "-a"],
91acb2
                                            capture_output=True)
91acb2
diff --git a/ipaserver/install/server/install.py b/ipaserver/install/server/install.py
91acb2
index b53c58e2a..6a593602f 100644
91acb2
--- a/ipaserver/install/server/install.py
91acb2
+++ b/ipaserver/install/server/install.py
91acb2
@@ -891,9 +891,8 @@ def install(installer):
91acb2
 
91acb2
         ca.install_step_0(False, None, options, custodia=custodia)
91acb2
     else:
91acb2
-        # Put the CA cert where other instances expect it
91acb2
-        x509.write_certificate(http_ca_cert, paths.IPA_CA_CRT)
91acb2
-        os.chmod(paths.IPA_CA_CRT, 0o444)
91acb2
+        # /etc/ipa/ca.crt is created as a side-effect of
91acb2
+        # dsinstance::enable_ssl() via export_ca_cert()
91acb2
 
91acb2
         if not options.no_pkinit:
91acb2
             x509.write_certificate(http_ca_cert, paths.KDC_CA_BUNDLE_PEM)
91acb2
-- 
91acb2
2.26.2
91acb2
91acb2
From da2079ce2cc841aec56da872131112eb24326f81 Mon Sep 17 00:00:00 2001
91acb2
From: Rob Crittenden <rcritten@redhat.com>
91acb2
Date: Tue, 4 Aug 2020 15:12:20 -0400
91acb2
Subject: [PATCH] ipatests: Check permissions of /etc/ipa/ca.crt new
91acb2
 installations
91acb2
91acb2
It should be 0644 root:root for both CA-ful and CA-less installs.
91acb2
91acb2
https://pagure.io/freeipa/issue/8441
91acb2
91acb2
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
91acb2
---
91acb2
 ipatests/test_integration/test_caless.py       |  8 ++++++++
91acb2
 ipatests/test_integration/test_installation.py | 10 ++++++++++
91acb2
 2 files changed, 18 insertions(+)
91acb2
91acb2
diff --git a/ipatests/test_integration/test_caless.py b/ipatests/test_integration/test_caless.py
91acb2
index 1ea7d9896..16dfbb320 100644
91acb2
--- a/ipatests/test_integration/test_caless.py
91acb2
+++ b/ipatests/test_integration/test_caless.py
91acb2
@@ -394,6 +394,14 @@ class CALessBase(IntegrationTest):
91acb2
                          host, cert_from_ldap.public_bytes(x509.Encoding.PEM))
91acb2
             assert cert_from_ldap == expected_cacrt
91acb2
 
91acb2
+            result = host.run_command(
91acb2
+                ["/usr/bin/stat", "-c", "%U:%G:%a", paths.IPA_CA_CRT]
91acb2
+            )
91acb2
+            (owner, group, mode) = result.stdout_text.strip().split(':')
91acb2
+            assert owner == "root"
91acb2
+            assert group == "root"
91acb2
+            assert mode == "644"
91acb2
+
91acb2
             # Verify certmonger was not started
91acb2
             result = host.run_command(['getcert', 'list'], raiseonerr=False)
91acb2
             assert result.returncode == 0
91acb2
diff --git a/ipatests/test_integration/test_installation.py b/ipatests/test_integration/test_installation.py
91acb2
index 100a5a766..fb1990083 100644
91acb2
--- a/ipatests/test_integration/test_installation.py
91acb2
+++ b/ipatests/test_integration/test_installation.py
91acb2
@@ -346,6 +346,16 @@ class TestInstallCA(IntegrationTest):
91acb2
         status = tasks.wait_for_request(self.master, request_id[0], 300)
91acb2
         assert status == "MONITORING"
91acb2
 
91acb2
+    def test_ipa_ca_crt_permissions(self):
91acb2
+        """Verify that /etc/ipa/ca.cert is mode 0644 root:root"""
91acb2
+        result = self.master.run_command(
91acb2
+            ["/usr/bin/stat", "-c", "%U:%G:%a", paths.IPA_CA_CRT]
91acb2
+        )
91acb2
+        out = str(result.stdout_text.strip())
91acb2
+        (owner, group, mode) = out.split(':')
91acb2
+        assert mode == "644"
91acb2
+        assert owner == "root"
91acb2
+        assert group == "root"
91acb2
 
91acb2
 class TestInstallWithCA_KRA1(InstallTestBase1):
91acb2
 
91acb2
-- 
91acb2
2.26.2
91acb2