From: Boris Ranto Date: Tue, 10 Jul 2018 20:52:38 +0000 (+0200) Subject: ceph-volume: Restore SELinux context X-Git-Tag: v14.0.1~747^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F23278%2Fhead;p=ceph.git ceph-volume: Restore SELinux context 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 --- diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index 32d5fe20d53b..c1fd5e64d34a 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -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): """ diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index eeb7bdc04383..b637f023a441 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -273,3 +273,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])