From: Juan Miguel Olmo Martínez Date: Thu, 11 Feb 2021 16:51:49 +0000 (+0100) Subject: cephadm: Mounting folder for selinux only if it is needed X-Git-Tag: v16.2.0~179^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=855cdd76dd6ce3f1e5e93e6e9aeb6e10ccde74d3;p=ceph.git cephadm: Mounting folder for selinux only if it is needed There are OSs without folder. And selinux can be enabled or not. Signed-off-by: Juan Miguel Olmo Martínez (cherry picked from commit c6e1cfbde241c70f31f19c00d18c7c4e51a13f7b) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 098726051037..34f07fbd3d1f 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -2284,7 +2284,11 @@ def get_container_mounts(ctx, fsid, daemon_type, daemon_id, if daemon_type == 'osd': mounts['/sys'] = '/sys' # for numa.cc, pick_address, cgroups, ... # selinux-policy in the container may not match the host. - mounts['/usr/share/empty'] = '/sys/fs/selinux:ro' + if HostFacts(ctx).selinux_enabled: + selinux_folder = '/var/lib/ceph/%s/selinux' % fsid + if not os.path.exists(selinux_folder): + os.makedirs(selinux_folder, mode=0o755) + mounts[selinux_folder] = '/sys/fs/selinux:ro' mounts['/run/lvm'] = '/run/lvm' mounts['/run/lock/lvm'] = '/run/lock/lvm' @@ -6199,9 +6203,9 @@ class HostFacts(): @property def kernel_security(self): - # type: () -> Optional[Dict[str, str]] + # type: () -> Dict[str, str] """Determine the security features enabled in the kernel - SELinux, AppArmor""" - def _fetch_selinux() -> Optional[Dict[str, str]]: + def _fetch_selinux() -> Dict[str, str]: """Read the selinux config file to determine state""" security = {} for selinux_path in HostFacts._selinux_path_list: @@ -6218,9 +6222,9 @@ class HostFacts(): else: security['description'] = "SELinux: Enabled({}, {})".format(security['SELINUX'], security['SELINUXTYPE']) return security - return None + return {} - def _fetch_apparmor() -> Optional[Dict[str, str]]: + def _fetch_apparmor() -> Dict[str, str]: """Read the apparmor profiles directly, returning an overview of AppArmor status""" security = {} for apparmor_path in HostFacts._apparmor_path_list: @@ -6245,9 +6249,9 @@ class HostFacts(): security['description'] += "({})".format(summary_str) return security - return None + return {} - ret = None + ret = {} if os.path.exists('/sys/kernel/security/lsm'): lsm = read_file(['/sys/kernel/security/lsm']).strip() if 'selinux' in lsm: @@ -6260,7 +6264,7 @@ class HostFacts(): "description": "Linux Security Module framework is active, but is not using SELinux or AppArmor" } - if ret is not None: + if ret: return ret return { @@ -6268,6 +6272,11 @@ class HostFacts(): "description": "Linux Security Module framework is not available" } + @property + def selinux_enabled(self): + return (self.kernel_security["type"] == "SELinux") and \ + (self.kernel_security["description"] != "SELinux: Disabled") + @property def kernel_parameters(self): # type: () -> Dict[str, str]