Blame SOURCES/0072-sysprep-add-IPA-offline-unenrollment-RHBZ-1789592.patch

da373f
From 90bb3cd1793275da50d509570d07d279989e2c45 Mon Sep 17 00:00:00 2001
3efd08
From: Pino Toscano <ptoscano@redhat.com>
3efd08
Date: Thu, 7 May 2020 13:53:21 +0200
3efd08
Subject: [PATCH] sysprep: add IPA offline unenrollment (RHBZ#1789592)
3efd08
MIME-Version: 1.0
3efd08
Content-Type: text/plain; charset=UTF-8
3efd08
Content-Transfer-Encoding: 8bit
3efd08
3efd08
This new operation unenrolls the guest from a IPA server offline, by
3efd08
removing the configuration files and certificates.
3efd08
3efd08
Thanks to Christian Heimes and François Cami for the hints.
3efd08
3efd08
(cherry picked from commit 0a53e2c7fc4fe2aa69052134230db0804849b470)
3efd08
---
3efd08
 sysprep/Makefile.am                     |  1 +
3efd08
 sysprep/sysprep_operation_ipa_client.ml | 66 +++++++++++++++++++++++++
3efd08
 2 files changed, 67 insertions(+)
3efd08
 create mode 100644 sysprep/sysprep_operation_ipa_client.ml
3efd08
3efd08
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
3efd08
index e6269c3f7..79266314b 100644
3efd08
--- a/sysprep/Makefile.am
3efd08
+++ b/sysprep/Makefile.am
3efd08
@@ -43,6 +43,7 @@ operations = \
3efd08
 	flag_reconfiguration \
3efd08
 	firewall_rules \
3efd08
 	fs_uuids \
3efd08
+	ipa_client \
3efd08
 	kerberos_data \
3efd08
 	lvm_uuids \
3efd08
 	logfiles \
3efd08
diff --git a/sysprep/sysprep_operation_ipa_client.ml b/sysprep/sysprep_operation_ipa_client.ml
3efd08
new file mode 100644
3efd08
index 000000000..6e64a754a
3efd08
--- /dev/null
3efd08
+++ b/sysprep/sysprep_operation_ipa_client.ml
3efd08
@@ -0,0 +1,66 @@
3efd08
+(* virt-sysprep
3efd08
+ * Copyright (C) 2020 Red Hat Inc.
3efd08
+ *
3efd08
+ * This program is free software; you can redistribute it and/or modify
3efd08
+ * it under the terms of the GNU General Public License as published by
3efd08
+ * the Free Software Foundation; either version 2 of the License, or
3efd08
+ * (at your option) any later version.
3efd08
+ *
3efd08
+ * This program is distributed in the hope that it will be useful,
3efd08
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
3efd08
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3efd08
+ * GNU General Public License for more details.
3efd08
+ *
3efd08
+ * You should have received a copy of the GNU General Public License along
3efd08
+ * with this program; if not, write to the Free Software Foundation, Inc.,
3efd08
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
3efd08
+ *)
3efd08
+
3efd08
+open Sysprep_operation
3efd08
+open Common_gettext.Gettext
3efd08
+
3efd08
+module G = Guestfs
3efd08
+
3efd08
+let ipa_client_perform (g : Guestfs.guestfs) root side_effects =
3efd08
+  let typ = g#inspect_get_type root in
3efd08
+  if typ = "linux" then (
3efd08
+    (* Simple paths with no side effects. *)
3efd08
+    let paths = [ "/etc/ipa/ca.crt";
3efd08
+                  "/etc/ipa/default.conf";
3efd08
+                  "/var/lib/ipa-client/sysrestore/*";
3efd08
+                  "/var/lib/ipa-client/pki/*" ] in
3efd08
+    let paths = List.concat (List.map Array.to_list (List.map g#glob_expand paths)) in
3efd08
+    List.iter (
3efd08
+      fun filename ->
3efd08
+        try g#rm filename with G.Error _ -> ()
3efd08
+    ) paths;
3efd08
+
3efd08
+    (* Certificates in the system CA store. *)
3efd08
+    let certs = [ "/etc/pki/ca-trust/source/anchors/ipa-ca.crt";
3efd08
+                  "/usr/local/share/ca-certificates/ipa-ca.crt";
3efd08
+                  "/etc/pki/ca-trust/source/ipa.p11-kit" ] in
3efd08
+    List.iter (
3efd08
+      fun filename ->
3efd08
+        try
3efd08
+          g#rm filename;
3efd08
+          side_effects#update_system_ca_store ()
3efd08
+        with
3efd08
+          G.Error _ -> ()
3efd08
+    ) certs
3efd08
+  )
3efd08
+
3efd08
+let op = {
3efd08
+  defaults with
3efd08
+    name = "ipa-client";
3efd08
+    enabled_by_default = true;
3efd08
+    heading = s_"Remove the IPA files";
3efd08
+    pod_description = Some (s_"\
3efd08
+Remove all the files related to an IPA (Identity, Policy, Audit) system.
3efd08
+This effectively unenrolls the guest from an IPA server without interacting
3efd08
+with it.
3efd08
+
3efd08
+This operation does not run C<ipa-client>.");
3efd08
+    perform_on_filesystems = Some ipa_client_perform;
3efd08
+}
3efd08
+
3efd08
+let () = register_operation op
3efd08
-- 
da373f
2.18.4
3efd08