7e1b55
From a1eb13cdbc109da8c028bb886a1207ea2cc23cee Mon Sep 17 00:00:00 2001
7e1b55
From: Christian Heimes <cheimes@redhat.com>
7e1b55
Date: Tue, 27 Jul 2021 11:54:20 +0200
7e1b55
Subject: [PATCH] Fix ldapupdate.get_sub_dict() for missing named user
7e1b55
MIME-Version: 1.0
7e1b55
Content-Type: text/plain; charset=UTF-8
7e1b55
Content-Transfer-Encoding: 8bit
7e1b55
7e1b55
The named user may not be present when ipa-server-dns and bind are not
7e1b55
installed. NAMED_UID and NAMED_GID constants are only used with local
7e1b55
DNS support.
7e1b55
7e1b55
Fixes: https://pagure.io/freeipa/issue/8936
7e1b55
Signed-off-by: Christian Heimes <cheimes@redhat.com>
7e1b55
Co-authored-by: François Cami <fcami@redhat.com>
7e1b55
Reviewed-By: Francois Cami <fcami@redhat.com>
7e1b55
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
7e1b55
Reviewed-By: Francois Cami <fcami@redhat.com>
7e1b55
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
7e1b55
---
7e1b55
 ipaserver/install/ldapupdate.py               | 14 +++++++---
7e1b55
 .../nightly_ipa-4-9_latest.yaml               | 12 +++++++++
7e1b55
 .../nightly_ipa-4-9_previous.yaml             | 12 +++++++++
7e1b55
 .../test_integration/test_installation.py     | 27 +++++++++++++++++++
7e1b55
 4 files changed, 62 insertions(+), 3 deletions(-)
7e1b55
7e1b55
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py
7e1b55
index 06cb78e0b..f0e7d6162 100644
7e1b55
--- a/ipaserver/install/ldapupdate.py
7e1b55
+++ b/ipaserver/install/ldapupdate.py
7e1b55
@@ -64,6 +64,15 @@ def get_sub_dict(realm, domain, suffix, fqdn, idstart=None, idmax=None):
7e1b55
         idrange_size = idmax - idstart + 1
7e1b55
         subid_base_rid = constants.SUBID_RANGE_START - idrange_size
7e1b55
 
7e1b55
+    # uid / gid for autobind
7e1b55
+    # user is only defined when ipa-server-dns and bind are installed
7e1b55
+    try:
7e1b55
+        named_uid = platformconstants.NAMED_USER.uid
7e1b55
+        named_gid = platformconstants.NAMED_GROUP.gid
7e1b55
+    except ValueError:
7e1b55
+        named_uid = None
7e1b55
+        named_gid = None
7e1b55
+
7e1b55
     return dict(
7e1b55
         REALM=realm,
7e1b55
         DOMAIN=domain,
7e1b55
@@ -99,9 +108,8 @@ def get_sub_dict(realm, domain, suffix, fqdn, idstart=None, idmax=None):
7e1b55
         DEFAULT_ADMIN_SHELL=platformconstants.DEFAULT_ADMIN_SHELL,
7e1b55
         SELINUX_USERMAP_DEFAULT=platformconstants.SELINUX_USERMAP_DEFAULT,
7e1b55
         SELINUX_USERMAP_ORDER=platformconstants.SELINUX_USERMAP_ORDER,
7e1b55
-        # uid / gid for autobind
7e1b55
-        NAMED_UID=platformconstants.NAMED_USER.uid,
7e1b55
-        NAMED_GID=platformconstants.NAMED_GROUP.gid,
7e1b55
+        NAMED_UID=named_uid,
7e1b55
+        NAMED_GID=named_gid,
7e1b55
     )
7e1b55
 
7e1b55
 
7e1b55
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
7e1b55
index 939ee2b7d..1c8c5ddfc 100644
7e1b55
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
7e1b55
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
7e1b55
@@ -547,6 +547,18 @@ jobs:
7e1b55
         timeout: 4800
7e1b55
         topology: *master_1repl_1client
7e1b55
 
7e1b55
+  fedora-latest-ipa-4-9/test_installation_TestInstallWithoutNamed:
7e1b55
+    requires: [fedora-latest-ipa-4-9/build]
7e1b55
+    priority: 50
7e1b55
+    job:
7e1b55
+      class: RunPytest
7e1b55
+      args:
7e1b55
+        build_url: '{fedora-latest-ipa-4-9/build_url}'
7e1b55
+        test_suite: test_integration/test_installation.py::TestInstallWithoutNamed
7e1b55
+        template: *ci-ipa-4-9-latest
7e1b55
+        timeout: 4800
7e1b55
+        topology: *master_1repl
7e1b55
+
7e1b55
   fedora-latest-ipa-4-9/test_idviews:
7e1b55
     requires: [fedora-latest-ipa-4-9/build]
7e1b55
     priority: 50
7e1b55
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
7e1b55
index 03658a934..6d121d59f 100644
7e1b55
--- a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
7e1b55
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
7e1b55
@@ -547,6 +547,18 @@ jobs:
7e1b55
         timeout: 4800
7e1b55
         topology: *master_1repl_1client
7e1b55
 
7e1b55
+  fedora-previous-ipa-4-9/test_installation_TestInstallWithoutNamed:
7e1b55
+    requires: [fedora-previous-ipa-4-9/build]
7e1b55
+    priority: 50
7e1b55
+    job:
7e1b55
+      class: RunPytest
7e1b55
+      args:
7e1b55
+        build_url: '{fedora-previous-ipa-4-9/build_url}'
7e1b55
+        test_suite: test_integration/test_installation.py::TestInstallWithoutNamed
7e1b55
+        template: *ci-ipa-4-9-previous
7e1b55
+        timeout: 4800
7e1b55
+        topology: *master_1repl
7e1b55
+
7e1b55
   fedora-previous-ipa-4-9/test_idviews:
7e1b55
     requires: [fedora-previous-ipa-4-9/build]
7e1b55
     priority: 50
7e1b55
diff --git a/ipatests/test_integration/test_installation.py b/ipatests/test_integration/test_installation.py
7e1b55
index e76fd0efe..e3c41eaa1 100644
7e1b55
--- a/ipatests/test_integration/test_installation.py
7e1b55
+++ b/ipatests/test_integration/test_installation.py
7e1b55
@@ -1853,3 +1853,30 @@ class TestInstallWithoutSudo(IntegrationTest):
7e1b55
         result = tasks.install_client(self.master, self.clients[0])
7e1b55
         assert self.no_sudo_str not in result.stderr_text
7e1b55
         assert self.sudo_version_str not in result.stdout_text
7e1b55
+
7e1b55
+
7e1b55
+class TestInstallWithoutNamed(IntegrationTest):
7e1b55
+    num_replicas = 1
7e1b55
+
7e1b55
+    @classmethod
7e1b55
+    def remove_named(cls, host):
7e1b55
+        # remove the bind package and make sure the named user does not exist.
7e1b55
+        # https://pagure.io/freeipa/issue/8936
7e1b55
+        result = host.run_command(['id', 'named'], raiseonerr=False)
7e1b55
+        if result.returncode == 0:
7e1b55
+            tasks.uninstall_packages(host, ['bind'])
7e1b55
+            host.run_command(['userdel', constants.NAMED_USER])
7e1b55
+        assert host.run_command(
7e1b55
+            ['id', 'named'], raiseonerr=False
7e1b55
+        ).returncode == 1
7e1b55
+
7e1b55
+    @classmethod
7e1b55
+    def install(cls, mh):
7e1b55
+        for tgt in (cls.master, cls.replicas[0]):
7e1b55
+            cls.remove_named(tgt)
7e1b55
+        tasks.install_master(cls.master, setup_dns=False)
7e1b55
+
7e1b55
+    def test_replica0_install(self):
7e1b55
+        tasks.install_replica(
7e1b55
+            self.master, self.replicas[0], setup_ca=False, setup_dns=False
7e1b55
+        )
7e1b55
-- 
7e1b55
2.31.1
7e1b55