]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: Restore SELinux context 23296/head
authorBoris Ranto <branto@redhat.com>
Tue, 10 Jul 2018 20:52:38 +0000 (22:52 +0200)
committerBoris Ranto <branto@redhat.com>
Fri, 27 Jul 2018 22:56:02 +0000 (00:56 +0200)
We need to reset the root context of the file system after mounting it.
Otherwise, the SELinux policy rules will not be preserved.

Fixes: https://tracker.ceph.com/issues/24785
Signed-off-by: Boris Ranto <branto@redhat.com>
(cherry picked from commit 61dbf4ac2af7d1e9da927bbc4006c9fbccb55478)

src/ceph-volume/ceph_volume/util/prepare.py
src/ceph-volume/ceph_volume/util/system.py

index 4ea0f29ddaf7873de259360fc69eac1f1640e887..2c36ba0ec450cdadbec0f90cb27ac5299bcaa820 100644 (file)
@@ -120,6 +120,9 @@ def mount_tmpfs(path):
         path
     ])
 
+    # Restore SELinux context
+    system.set_context(path)
+
 
 def create_osd_path(osd_id, tmpfs=False):
     path = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
@@ -219,6 +222,9 @@ def mount_osd(device, osd_id, **kw):
     command.append(destination)
     process.run(command)
 
+    # Restore SELinux context
+    system.set_context(destination)
+
 
 def _link_device(device, device_type, osd_id):
     """
index b4b7d17c4c946648e17c1548a7f53d961a65b3ba..928c88934ad9a86f20f662116f597d4464d455cc 100644 (file)
@@ -260,3 +260,12 @@ def get_mounts(devices=False, paths=False, realpath=False):
         return devices_mounted
     else:
         return paths_mounted
+
+
+def set_context(path, recursive = False):
+    # restore selinux context to default policy values
+    if which('restorecon').startswith('/'):
+        if recursive:
+            process.run(['restorecon', '-R', path])
+        else:
+            process.run(['restorecon', path])