ac7d03
From 488c433c369bfcd13e95d910b500c455a01715b6 Mon Sep 17 00:00:00 2001
ac7d03
From: Martin Basti <mbasti@redhat.com>
ac7d03
Date: Wed, 3 May 2017 13:51:02 +0200
ac7d03
Subject: [PATCH] Use proper SELinux context with http.keytab
ac7d03
ac7d03
During upgrade keytab is moved to a new location using "move" operation.
ac7d03
This commit replaces move operation with "copy" and "remove" that
ac7d03
ensures a proper selinux context.
ac7d03
ac7d03
https://pagure.io/freeipa/issue/6924
ac7d03
ac7d03
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
ac7d03
---
ac7d03
 ipaserver/install/server/upgrade.py | 10 +++++++++-
ac7d03
 1 file changed, 9 insertions(+), 1 deletion(-)
ac7d03
ac7d03
diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py
ac7d03
index 0f27428dd492bb44dd8c69a7e7f47abb531843f5..4d8fd666dfd4e918103b449d4c31bb7661727115 100644
ac7d03
--- a/ipaserver/install/server/upgrade.py
ac7d03
+++ b/ipaserver/install/server/upgrade.py
ac7d03
@@ -1427,7 +1427,15 @@ def update_ipa_httpd_service_conf(http):
ac7d03
 def update_http_keytab(http):
ac7d03
     root_logger.info('[Moving HTTPD service keytab to gssproxy]')
ac7d03
     if os.path.exists(paths.OLD_IPA_KEYTAB):
ac7d03
-        shutil.move(paths.OLD_IPA_KEYTAB, http.keytab)
ac7d03
+        # ensure proper SELinux context by using copy operation
ac7d03
+        shutil.copy(paths.OLD_IPA_KEYTAB, http.keytab)
ac7d03
+        try:
ac7d03
+            os.remove(paths.OLD_IPA_KEYTAB)
ac7d03
+        except OSError as e:
ac7d03
+            root_logger.error(
ac7d03
+                'Cannot remove file %s (%s). Please remove the file manually.',
ac7d03
+                paths.OLD_IPA_KEYTAB, e
ac7d03
+            )
ac7d03
     pent = pwd.getpwnam(http.keytab_user)
ac7d03
     os.chown(http.keytab, pent.pw_uid, pent.pw_gid)
ac7d03
 
ac7d03
-- 
ac7d03
2.12.2
ac7d03