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

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