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

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