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

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