5c8636
From b590dcef10680b4ea3181ae1caec183e5967562b Mon Sep 17 00:00:00 2001
5c8636
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5c8636
Date: Fri, 11 Dec 2020 07:35:59 +0200
5c8636
Subject: [PATCH] ipatests: add TestInstallWithoutSudo
5c8636
MIME-Version: 1.0
5c8636
Content-Type: text/plain; charset=UTF-8
5c8636
Content-Transfer-Encoding: 8bit
5c8636
5c8636
Test IPA servers and clients behavior when sudo is not installed.
5c8636
5c8636
Fixes: https://pagure.io/freeipa/issue/8530
5c8636
Signed-off-by: François Cami <fcami@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5c8636
---
5c8636
 .../nightly_ipa-4-9_latest.yaml               | 12 ++++
5c8636
 .../nightly_ipa-4-9_latest_selinux.yaml       | 13 ++++
5c8636
 .../nightly_ipa-4-9_previous.yaml             | 12 ++++
5c8636
 .../test_integration/test_installation.py     | 66 +++++++++++++++++++
5c8636
 4 files changed, 103 insertions(+)
5c8636
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
index 3acd6a13c..d91b16cab 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest.yaml
5c8636
@@ -535,6 +535,18 @@ jobs:
5c8636
         timeout: 10800
5c8636
         topology: *master_1repl
5c8636
 
5c8636
+  fedora-latest-ipa-4-9/test_installation_TestInstallWithoutSudo:
5c8636
+    requires: [fedora-latest-ipa-4-9/build]
5c8636
+    priority: 50
5c8636
+    job:
5c8636
+      class: RunPytest
5c8636
+      args:
5c8636
+        build_url: '{fedora-latest-ipa-4-9/build_url}'
5c8636
+        test_suite: test_integration/test_installation.py::TestInstallWithoutSudo
5c8636
+        template: *ci-ipa-4-9-latest
5c8636
+        timeout: 4800
5c8636
+        topology: *master_1repl_1client
5c8636
+
5c8636
   fedora-latest-ipa-4-9/test_idviews:
5c8636
     requires: [fedora-latest-ipa-4-9/build]
5c8636
     priority: 50
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
index c01192cf5..8adb06d0c 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_latest_selinux.yaml
5c8636
@@ -575,6 +575,19 @@ jobs:
5c8636
         timeout: 10800
5c8636
         topology: *master_1repl
5c8636
 
5c8636
+  fedora-latest-ipa-4-9/test_installation_TestInstallWithoutSudo:
5c8636
+    requires: [fedora-latest-ipa-4-9/build]
5c8636
+    priority: 50
5c8636
+    job:
5c8636
+      class: RunPytest
5c8636
+      args:
5c8636
+        build_url: '{fedora-latest-ipa-4-9/build_url}'
5c8636
+        selinux_enforcing: True
5c8636
+        test_suite: test_integration/test_installation.py::TestInstallWithoutSudo
5c8636
+        template: *ci-ipa-4-9-latest
5c8636
+        timeout: 4800
5c8636
+        topology: *master_1repl_1client
5c8636
+
5c8636
   fedora-latest-ipa-4-9/test_idviews:
5c8636
     requires: [fedora-latest-ipa-4-9/build]
5c8636
     priority: 50
5c8636
diff --git a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
index a6ea24f6a..2b5d4fd5e 100644
5c8636
--- a/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
+++ b/ipatests/prci_definitions/nightly_ipa-4-9_previous.yaml
5c8636
@@ -535,6 +535,18 @@ jobs:
5c8636
         timeout: 10800
5c8636
         topology: *master_1repl
5c8636
 
5c8636
+  fedora-previous-ipa-4-9/test_installation_TestInstallWithoutSudo:
5c8636
+    requires: [fedora-previous-ipa-4-9/build]
5c8636
+    priority: 50
5c8636
+    job:
5c8636
+      class: RunPytest
5c8636
+      args:
5c8636
+        build_url: '{fedora-previous-ipa-4-9/build_url}'
5c8636
+        test_suite: test_integration/test_installation.py::TestInstallWithoutSudo
5c8636
+        template: *ci-ipa-4-9-previous
5c8636
+        timeout: 4800
5c8636
+        topology: *master_1repl_1client
5c8636
+
5c8636
   fedora-previous-ipa-4-9/test_idviews:
5c8636
     requires: [fedora-previous-ipa-4-9/build]
5c8636
     priority: 50
5c8636
diff --git a/ipatests/test_integration/test_installation.py b/ipatests/test_integration/test_installation.py
5c8636
index eb6f7d78e..6e8af024c 100644
5c8636
--- a/ipatests/test_integration/test_installation.py
5c8636
+++ b/ipatests/test_integration/test_installation.py
5c8636
@@ -1537,3 +1537,69 @@ class TestInstallReplicaAgainstSpecificServer(IntegrationTest):
5c8636
                                             self.replicas[0].hostname],
5c8636
                                            stdin_text=dirman_password)
5c8636
         assert self.replicas[0].hostname not in cmd.stdout_text
5c8636
+
5c8636
+
5c8636
+class TestInstallWithoutSudo(IntegrationTest):
5c8636
+
5c8636
+    num_clients = 1
5c8636
+    num_replicas = 1
5c8636
+    no_sudo_str = "The sudo binary does not seem to be present on this"
5c8636
+
5c8636
+    @classmethod
5c8636
+    def install(cls, mh):
5c8636
+        pass
5c8636
+
5c8636
+    def test_sudo_removal(self):
5c8636
+        # ipa-client makes sudo depend on libsss_sudo.
5c8636
+
5c8636
+        # --nodeps is mandatory because dogtag uses sudo at install
5c8636
+        # time until commit 49585867207922479644a03078c29548de02cd03
5c8636
+        # which is scheduled to land in 10.10.
5c8636
+
5c8636
+        # This also means sudo+libsss_sudo cannot be uninstalled on
5c8636
+        # IPA servers with a CA.
5c8636
+        assert tasks.is_package_installed(self.clients[0], 'sudo')
5c8636
+        assert tasks.is_package_installed(self.clients[0], 'libsss_sudo')
5c8636
+        tasks.uninstall_packages(
5c8636
+            self.clients[0], ['sudo', 'libsss_sudo'], nodeps=True
5c8636
+        )
5c8636
+
5c8636
+    def test_ipa_installation_without_sudo(self):
5c8636
+        # FixMe: When Dogtag 10.10 is out, test installation without sudo
5c8636
+        tasks.install_master(self.master, setup_dns=True)
5c8636
+
5c8636
+    def test_replica_installation_without_sudo(self):
5c8636
+        # FixMe: When Dogtag 10.10 is out, test replica installation
5c8636
+        # without sudo and with CA
5c8636
+        tasks.uninstall_packages(
5c8636
+            self.replicas[0], ['sudo', 'libsss_sudo'], nodeps=True
5c8636
+        )
5c8636
+        # One-step install is needed.
5c8636
+        # With promote=True, two-step install is done and that only captures
5c8636
+        # the ipa-replica-install stdout/stderr, not ipa-client-install's.
5c8636
+        result = tasks.install_replica(
5c8636
+            self.master, self.replicas[0], promote=False,
5c8636
+            setup_dns=True, setup_ca=False
5c8636
+        )
5c8636
+        assert self.no_sudo_str in result.stderr_text
5c8636
+
5c8636
+    def test_client_installation_without_sudo(self):
5c8636
+        result = tasks.install_client(self.master, self.clients[0])
5c8636
+        assert self.no_sudo_str in result.stderr_text
5c8636
+
5c8636
+    def test_remove_sudo_on_ipa(self):
5c8636
+        tasks.uninstall_packages(
5c8636
+            self.master, ['sudo', 'libsss_sudo'], nodeps=True
5c8636
+        )
5c8636
+        self.master.run_command(
5c8636
+            ['ipactl', 'restart']
5c8636
+        )
5c8636
+
5c8636
+    def test_install_sudo_on_client(self):
5c8636
+        """ Check that installing sudo pulls libsss_sudo in"""
5c8636
+        for pkg in ('sudo', 'libsss_sudo'):
5c8636
+            assert tasks.is_package_installed(self.clients[0], pkg) is False
5c8636
+        tasks.uninstall_client(self.clients[0])
5c8636
+        tasks.install_packages(self.clients[0], ['sudo'])
5c8636
+        for pkg in ('sudo', 'libsss_sudo'):
5c8636
+            assert tasks.is_package_installed(self.clients[0], pkg)
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From 0c2741af9f353d2fbb21a5768e6433c0e99da0e9 Mon Sep 17 00:00:00 2001
5c8636
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5c8636
Date: Thu, 10 Dec 2020 08:35:12 +0200
5c8636
Subject: [PATCH] ipatests: tasks: handle uninstalling packages with nodeps
5c8636
MIME-Version: 1.0
5c8636
Content-Type: text/plain; charset=UTF-8
5c8636
Content-Transfer-Encoding: 8bit
5c8636
5c8636
Handle package removal without taking dependencies into account.
5c8636
E.g. add frontends for rpm -e --nodeps.
5c8636
5c8636
Related: ipatests/pytest_ipa/integration/tasks.py
5c8636
Signed-off-by: François Cami <fcami@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5c8636
---
5c8636
 ipatests/pytest_ipa/integration/tasks.py | 51 +++++++++++++++++++-----
5c8636
 1 file changed, 41 insertions(+), 10 deletions(-)
5c8636
5c8636
diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
5c8636
index b91859816..2fe78367f 100755
5c8636
--- a/ipatests/pytest_ipa/integration/tasks.py
5c8636
+++ b/ipatests/pytest_ipa/integration/tasks.py
5c8636
@@ -29,6 +29,7 @@ import re
5c8636
 import collections
5c8636
 import itertools
5c8636
 import shutil
5c8636
+import shlex
5c8636
 import copy
5c8636
 import subprocess
5c8636
 import tempfile
5c8636
@@ -2381,20 +2382,33 @@ def download_packages(host, pkgs):
5c8636
     return tmpdir
5c8636
 
5c8636
 
5c8636
-def uninstall_packages(host, pkgs):
5c8636
+def uninstall_packages(host, pkgs, nodeps=False):
5c8636
     """Uninstall packages on a remote host.
5c8636
-    :param host: the host where the uninstallation takes place
5c8636
-    :param pkgs: packages to uninstall, provided as a list of strings
5c8636
+    :param host: the host where the uninstallation takes place.
5c8636
+    :param pkgs: packages to uninstall, provided as a list of strings.
5c8636
+    :param nodeps: ignore dependencies (dangerous!).
5c8636
     """
5c8636
     platform = get_platform(host)
5c8636
-    # Only supports RHEL 8+ and Fedora for now
5c8636
-    if platform in ('rhel', 'fedora'):
5c8636
-        install_cmd = ['/usr/bin/dnf', 'remove', '-y']
5c8636
-    elif platform in ('ubuntu'):
5c8636
-        install_cmd = ['apt-get', 'remove', '-y']
5c8636
+    if platform not in ('rhel', 'fedora', 'ubuntu'):
5c8636
+        raise ValueError('uninstall_packages: unknown platform %s' % platform)
5c8636
+    if nodeps:
5c8636
+        if platform in ('rhel', 'fedora'):
5c8636
+            cmd = "rpm -e --nodeps"
5c8636
+        elif platform in ('ubuntu'):
5c8636
+            cmd = "dpkg -P --force-depends"
5c8636
+        for package in pkgs:
5c8636
+            uninstall_cmd = shlex.split(cmd)
5c8636
+            uninstall_cmd.append(package)
5c8636
+            # keep raiseonerr=True here. --fcami
5c8636
+            host.run_command(uninstall_cmd)
5c8636
     else:
5c8636
-        raise ValueError('install_packages: unknown platform %s' % platform)
5c8636
-    host.run_command(install_cmd + pkgs, raiseonerr=False)
5c8636
+        if platform in ('rhel', 'fedora'):
5c8636
+            cmd = "/usr/bin/dnf remove -y"
5c8636
+        elif platform in ('ubuntu'):
5c8636
+            cmd = "apt-get remove -y"
5c8636
+        uninstall_cmd = shlex.split(cmd)
5c8636
+        uninstall_cmd.extend(pkgs)
5c8636
+        host.run_command(uninstall_cmd, raiseonerr=False)
5c8636
 
5c8636
 
5c8636
 def wait_for_request(host, request_id, timeout=120):
5c8636
@@ -2649,3 +2663,20 @@ def run_ssh_cmd(
5c8636
             assert "Authentication succeeded" not in stderr
5c8636
             assert "No more authentication methods to try." in stderr
5c8636
     return (return_code, stdout, stderr)
5c8636
+
5c8636
+
5c8636
+def is_package_installed(host, pkg):
5c8636
+    platform = get_platform(host)
5c8636
+    if platform in ('rhel', 'fedora'):
5c8636
+        result = host.run_command(
5c8636
+            ['rpm', '-q', pkg], raiseonerr=False
5c8636
+        )
5c8636
+    elif platform in ['ubuntu']:
5c8636
+        result = host.run_command(
5c8636
+            ['dpkg', '-s', pkg], raiseonerr=False
5c8636
+        )
5c8636
+    else:
5c8636
+        raise ValueError(
5c8636
+            'is_package_installed: unknown platform %s' % platform
5c8636
+        )
5c8636
+    return result.returncode == 0
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From fe157ca349e3146a53884e90e6e588efb4e97eeb Mon Sep 17 00:00:00 2001
5c8636
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5c8636
Date: Thu, 10 Dec 2020 08:15:22 +0200
5c8636
Subject: [PATCH] ipa-client-install: output a warning if sudo is not present
5c8636
MIME-Version: 1.0
5c8636
Content-Type: text/plain; charset=UTF-8
5c8636
Content-Transfer-Encoding: 8bit
5c8636
5c8636
Fixes: https://pagure.io/freeipa/issue/8530
5c8636
Signed-off-by: François Cami <fcami@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5c8636
---
5c8636
 ipaclient/install/client.py | 14 +++++++++++++-
5c8636
 1 file changed, 13 insertions(+), 1 deletion(-)
5c8636
5c8636
diff --git a/ipaclient/install/client.py b/ipaclient/install/client.py
5c8636
index 8acfa0cd1..0e478fa26 100644
5c8636
--- a/ipaclient/install/client.py
5c8636
+++ b/ipaclient/install/client.py
5c8636
@@ -24,6 +24,7 @@ import re
5c8636
 import SSSDConfig
5c8636
 import shutil
5c8636
 import socket
5c8636
+import subprocess
5c8636
 import sys
5c8636
 import tempfile
5c8636
 import textwrap
5c8636
@@ -2200,7 +2201,18 @@ def install_check(options):
5c8636
             "authentication resources",
5c8636
             rval=CLIENT_INSTALL_ERROR)
5c8636
 
5c8636
-    # when installing with '--no-sssd' option, check whether nss-ldap is
5c8636
+    # When installing without the "--no-sudo" option, check whether sudo is
5c8636
+    # available.
5c8636
+    if options.conf_sudo:
5c8636
+        try:
5c8636
+            subprocess.Popen(['sudo -V'])
5c8636
+        except FileNotFoundError:
5c8636
+            logger.info(
5c8636
+                "The sudo binary does not seem to be present on this "
5c8636
+                "system. Please consider installing sudo if required."
5c8636
+            )
5c8636
+
5c8636
+    # when installing with the '--no-sssd' option, check whether nss-ldap is
5c8636
     # installed
5c8636
     if not options.sssd:
5c8636
         if not os.path.exists(paths.PAM_KRB5_SO):
5c8636
-- 
5c8636
2.29.2
5c8636
5c8636
From ee0ba2df41cf545b82d3d26e7e7e42447bb0f63e Mon Sep 17 00:00:00 2001
5c8636
From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= <fcami@redhat.com>
5c8636
Date: Thu, 10 Dec 2020 07:55:16 +0200
5c8636
Subject: [PATCH] freeipa.spec: client: depend on libsss_sudo and sudo
5c8636
MIME-Version: 1.0
5c8636
Content-Type: text/plain; charset=UTF-8
5c8636
Content-Transfer-Encoding: 8bit
5c8636
5c8636
On 10.10+ releases of Dogtag, the PKI installer will not depend
5c8636
on sudo anymore. This opens the possibility of creating IPA servers
5c8636
without a properly configured sudo.
5c8636
In fact, even IPA clients should have sudo and libsss_sudo installed
5c8636
in most cases, so add a weak dependency on both of them to the client
5c8636
subpackage.
5c8636
Also make sure libsss_sudo is installed if sudo is present.
5c8636
5c8636
Fixes: https://pagure.io/freeipa/issue/8530
5c8636
Signed-off-by: François Cami <fcami@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
5c8636
Reviewed-By: Armando Neto <abiagion@redhat.com>
5c8636
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5c8636
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
5c8636
---
5c8636
 freeipa.spec.in | 5 +++++
5c8636
 1 file changed, 5 insertions(+)
5c8636
5c8636
diff --git a/freeipa.spec.in b/freeipa.spec.in
5c8636
index ba52a3834..93e473ac4 100755
5c8636
--- a/freeipa.spec.in
5c8636
+++ b/freeipa.spec.in
5c8636
@@ -640,6 +640,11 @@ Requires: nfs-utils
5c8636
 Requires: sssd-tools >= %{sssd_version}
5c8636
 Requires(post): policycoreutils
5c8636
 
5c8636
+# https://pagure.io/freeipa/issue/8530
5c8636
+Recommends: libsss_sudo
5c8636
+Recommends: sudo
5c8636
+Requires: (libsss_sudo if sudo)
5c8636
+
5c8636
 Provides: %{alt_name}-client = %{version}
5c8636
 Conflicts: %{alt_name}-client
5c8636
 Obsoletes: %{alt_name}-client < %{version}
5c8636
-- 
5c8636
2.29.2
5c8636