Blame SOURCES/0009-ipa-client-install-use-the-authselect-backup-during_rhbz#1810179.patch

5144c6
From ca880cfb117fc870a6e2710b9e31b2f67d5651e1 Mon Sep 17 00:00:00 2001
5144c6
From: Florence Blanc-Renaud <flo@redhat.com>
5144c6
Date: Wed, 29 Jul 2020 13:35:49 +0200
5144c6
Subject: [PATCH] ipa-client-install: use the authselect backup during
5144c6
 uninstall
5144c6
5144c6
When ipa-client-install is run on a system with no existing
5144c6
authselect configuration (for instance a fedora 31 new install),
5144c6
uninstallation is picking sssd profile but this may lead to
5144c6
a configuration with differences compared to the pre-ipa-client
5144c6
state.
5144c6
5144c6
Now that authselect provides an option to backup the existing
5144c6
configuration prior to setting a profile, the client install
5144c6
can save the backup name and uninstall is able to apply the
5144c6
backup in order to go back to the pre-ipa-client state.
5144c6
5144c6
Fixes: https://pagure.io/freeipa/issue/8189
5144c6
Reviewed-By: Francois Cami <fcami@redhat.com>
5144c6
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5144c6
---
5144c6
 ipaplatform/redhat/authconfig.py | 37 ++++++++++++++------------------
5144c6
 1 file changed, 16 insertions(+), 21 deletions(-)
5144c6
5144c6
diff --git a/ipaplatform/redhat/authconfig.py b/ipaplatform/redhat/authconfig.py
5144c6
index 758376f2b..89f452d66 100644
5144c6
--- a/ipaplatform/redhat/authconfig.py
5144c6
+++ b/ipaplatform/redhat/authconfig.py
5144c6
@@ -27,6 +27,7 @@ from ipaplatform.paths import paths
5144c6
 from ipapython import ipautil
5144c6
 from ipapython.admintool import ScriptError
5144c6
 import os
5144c6
+import time
5144c6
 
5144c6
 FILES_TO_NOT_BACKUP = ['passwd', 'group', 'shadow', 'gshadow']
5144c6
 
5144c6
@@ -103,28 +104,16 @@ class RedHatAuthSelect(RedHatAuthToolBase):
5144c6
     def configure(self, sssd, mkhomedir, statestore, sudo=True):
5144c6
         # In the statestore, the following keys are used for the
5144c6
         # 'authselect' module:
5144c6
+        # Old method:
5144c6
         # profile: name of the profile configured pre-installation
5144c6
         # features_list: list of features configured pre-installation
5144c6
         # mkhomedir: True if installation was called with --mkhomedir
5144c6
         # profile and features_list are used when reverting to the
5144c6
         # pre-install state
5144c6
-        cfg = self._parse_authselect_output()
5144c6
-        if cfg:
5144c6
-            statestore.backup_state('authselect', 'profile', cfg[0])
5144c6
-            statestore.backup_state(
5144c6
-                    'authselect', 'features_list', " ".join(cfg[1]))
5144c6
-        else:
5144c6
-            # cfg = None means that the current conf is not managed by
5144c6
-            # authselect but by authconfig.
5144c6
-            # As we are using authselect to configure the host,
5144c6
-            # it will not be possible to revert to a custom authconfig
5144c6
-            # configuration later (during uninstall)
5144c6
-            # Best thing to do will be to use sssd profile at this time
5144c6
-            logger.warning(
5144c6
-                "WARNING: The configuration pre-client installation is not "
5144c6
-                "managed by authselect and cannot be backed up. "
5144c6
-                "Uninstallation may not be able to revert to the original "
5144c6
-                "state.")
5144c6
+        # New method:
5144c6
+        # backup: name of the authselect backup
5144c6
+        backup_name = "pre_ipaclient_{}".format(time.strftime("%Y%m%d%H%M%S"))
5144c6
+        statestore.backup_state('authselect', 'backup', backup_name)
5144c6
 
5144c6
         cmd = [paths.AUTHSELECT, "select", "sssd"]
5144c6
         if mkhomedir:
5144c6
@@ -133,6 +122,7 @@ class RedHatAuthSelect(RedHatAuthToolBase):
5144c6
         if sudo:
5144c6
             cmd.append("with-sudo")
5144c6
         cmd.append("--force")
5144c6
+        cmd.append("--backup={}".format(backup_name))
5144c6
 
5144c6
         ipautil.run(cmd)
5144c6
 
5144c6
@@ -179,10 +169,15 @@ class RedHatAuthSelect(RedHatAuthToolBase):
5144c6
             else:
5144c6
                 features = []
5144c6
 
5144c6
-        cmd = [paths.AUTHSELECT, "select", profile]
5144c6
-        cmd.extend(features)
5144c6
-        cmd.append("--force")
5144c6
-        ipautil.run(cmd)
5144c6
+        backup = statestore.restore_state('authselect', 'backup')
5144c6
+        if backup:
5144c6
+            cmd = [paths.AUTHSELECT, "backup-restore", backup]
5144c6
+            ipautil.run(cmd)
5144c6
+        else:
5144c6
+            cmd = [paths.AUTHSELECT, "select", profile]
5144c6
+            cmd.extend(features)
5144c6
+            cmd.append("--force")
5144c6
+            ipautil.run(cmd)
5144c6
 
5144c6
     def backup(self, path):
5144c6
         current = self._get_authselect_current_output()
5144c6
-- 
5144c6
2.26.2
5144c6
5144c6
# Not needed for 4.7.8 release
5144c6
#
5144c6
#From 3eaab97e317584bc47d4a27a607267ed90df7ff7 Mon Sep 17 00:00:00 2001
5144c6
#From: Florence Blanc-Renaud <flo@redhat.com>
5144c6
#Date: Wed, 29 Jul 2020 13:40:26 +0200
5144c6
#Subject: [PATCH] ipatests: remove the xfail for test_nfs.py
5144c6
#
5144c6
#Related: https://pagure.io/freeipa/issue/8189
5144c6
#Reviewed-By: Francois Cami <fcami@redhat.com>
5144c6
#Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5144c6
#---
5144c6
# ipatests/test_integration/test_nfs.py | 4 ----
5144c6
# 1 file changed, 4 deletions(-)
5144c6
#
5144c6
#diff --git a/ipatests/test_integration/test_nfs.py b/ipatests/test_integration/test_nfs.py
5144c6
#index 7272b0d44..832c56cca 100644
5144c6
#--- a/ipatests/test_integration/test_nfs.py
5144c6
#+++ b/ipatests/test_integration/test_nfs.py
5144c6
#@@ -363,10 +363,6 @@ class TestIpaClientAutomountFileRestore(IntegrationTest):
5144c6
#         cmd = self.clients[0].run_command(sha256nsswitch_cmd)
5144c6
#         assert cmd.stdout_text == orig_sha256
5144c6
# 
5144c6
#-    @pytest.mark.xfail(
5144c6
#-        reason="https://pagure.io/freeipa/issue/8189",
5144c6
#-        strict=True
5144c6
#-    )
5144c6
#     def test_nsswitch_backup_restore_sssd(self):
5144c6
#         self.nsswitch_backup_restore()
5144c6
# 
5144c6
#-- 
5144c6
#2.26.2
5144c6
5144c6
From 4baf6b292f28481ece483bb8ecbd6a0807d9d45a Mon Sep 17 00:00:00 2001
5144c6
From: Florence Blanc-Renaud <flo@redhat.com>
5144c6
Date: Wed, 29 Jul 2020 17:57:53 +0200
5144c6
Subject: [PATCH] ipatests: fix test_authselect
5144c6
5144c6
Before the code fix, install/uninstall on a config without
5144c6
any authselect profile was not able to restore the exact
5144c6
state but configured sssd profile instead.
5144c6
5144c6
Now that the code is doing a pre-install backup, uninstall
5144c6
restores the exact state and the test needs to be updated
5144c6
accordingly.
5144c6
5144c6
Related: https://pagure.io/freeipa/issue/8189
5144c6
Reviewed-By: Francois Cami <fcami@redhat.com>
5144c6
Reviewed-By: Michal Polovka <mpolovka@redhat.com>
5144c6
---
5144c6
 ipatests/test_integration/test_authselect.py | 13 ++++++++-----
5144c6
 1 file changed, 8 insertions(+), 5 deletions(-)
5144c6
5144c6
diff --git a/ipatests/test_integration/test_authselect.py b/ipatests/test_integration/test_authselect.py
5144c6
index bdf7d9f77..cba23e707 100644
5144c6
--- a/ipatests/test_integration/test_authselect.py
5144c6
+++ b/ipatests/test_integration/test_authselect.py
5144c6
@@ -100,7 +100,9 @@ class TestClientInstallation(IntegrationTest):
5144c6
             ['rm', '-f', '/etc/authselect/authselect.conf'])
5144c6
         result = self._install_client()
5144c6
         assert result.returncode == 0
5144c6
-        assert self.msg_warn_install in result.stderr_text
5144c6
+        # With the fix for 8189, there is no warning any more
5144c6
+        # because install is performing a pre-install backup
5144c6
+        assert self.msg_warn_install not in result.stderr_text
5144c6
         # Client installation must configure the 'sssd' profile
5144c6
         # with sudo
5144c6
         check_authselect_profile(self.client, default_profile, ('with-sudo',))
5144c6
@@ -109,12 +111,13 @@ class TestClientInstallation(IntegrationTest):
5144c6
         """
5144c6
         Test client un-installation when there was no authselect profile
5144c6
         """
5144c6
-        # As the client did not have any authselect profile before install,
5144c6
-        # uninstall must print a warning about restoring 'sssd' profile
5144c6
-        # by default
5144c6
+        # The client did not have any authselect profile before install,
5144c6
+        # but uninstall must be able to restore the backup
5144c6
+        # Check that no profile is configured after uninstall
5144c6
         result = self._uninstall_client()
5144c6
         assert result.returncode == 0
5144c6
-        check_authselect_profile(self.client, default_profile)
5144c6
+        assert not self.client.transport.file_exists(
5144c6
+            '/etc/authselect/authselect.conf')
5144c6
 
5144c6
     def test_install_client_preconfigured_profile(self):
5144c6
         """
5144c6
-- 
5144c6
2.26.2
5144c6