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

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