From 193d37029f0ae26a86f528d0c6ea51b6179abae0 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 14 Apr 2022 12:47:14 -0400 Subject: [PATCH] Relabel target path if selinux disabled on build host --- imgutil/imgutil | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index f097d6c3..ae0efbe4 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -590,10 +590,18 @@ class ElHandler(OsHandler): cmd.extend(glob.glob(os.path.join(targdir, '*'))) subprocess.check_call(cmd) subprocess.check_call(['yum'] + self.yumargs) - # note that in some cases, may need to fix labels for function even without selinux - # for now a TODO, but note the command to repair a scratch directery if needed - # can be done by unpack, setfiles, then pack again too - #setfiles -r buildscratch /etc/selinux/targeted/contexts/files/file_contexts buildscratch + with open('/proc/mounts') as mountinfo: + for line in mountinfo.readlines(): + if line.startswith('selinuxfs '): + break + else: + self.relabel_targdir() + + def relabel_targdir(self): + subprocess.check_call( + ['setfiles', '-r', self.targpath, + '/etc/selinux/targeted/contexts/files/file_contexts', + self.targpath]) def versionize_string(key):