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