diff --git a/stages/org.osbuild.selinux b/stages/org.osbuild.selinux index 5ec319f6..5aa924f9 100755 --- a/stages/org.osbuild.selinux +++ b/stages/org.osbuild.selinux @@ -33,6 +33,13 @@ SCHEMA = """ "file_contexts": { "type": "string", "description": "Path to the active SELinux policy's `file_contexts`" + }, + "labels": { + "type": "object", + "description": "Labels to set of the specified files or folders", + "items": { + "type": "object" + } } } """ @@ -40,9 +47,14 @@ SCHEMA = """ def main(tree, options): file_contexts = os.path.join(f"{tree}", options["file_contexts"]) + labels = options.get("labels", {}) subprocess.run(["setfiles", "-F", "-r", f"{tree}", f"{file_contexts}", f"{tree}"], check=True) + for path, label in labels.items(): + fullpath = os.path.join(tree, path.lstrip("/")) + subprocess.run(["chcon", "-v", label, fullpath], check=True) + if __name__ == '__main__': args = json.load(sys.stdin)