|
| 1 | +From 281b0795fb4cc43ea05039627ebb5ff7130d70e9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dusty Mabe < [email protected]> |
| 3 | +Date: Tue, 17 Sep 2024 12:22:16 -0400 |
| 4 | +Subject: [PATCH 2/3] stages/selinux: don't require file_contexts if labels |
| 5 | + passed |
| 6 | + |
| 7 | +With the labels option the user is specifying the exact context |
| 8 | +they want to set on the path so it's not necessary to supply a |
| 9 | +context here. This can be also useful in the case where you want |
| 10 | +to set some labels and you haven't yet populated the tree yet. |
| 11 | +--- |
| 12 | + stages/org.osbuild.selinux | 11 +++++++---- |
| 13 | + stages/org.osbuild.selinux.meta.json | 13 +++++++++++-- |
| 14 | + 2 files changed, 18 insertions(+), 6 deletions(-) |
| 15 | + |
| 16 | +diff --git a/stages/org.osbuild.selinux b/stages/org.osbuild.selinux |
| 17 | +index bb45298d..563d827b 100755 |
| 18 | +--- a/stages/org.osbuild.selinux |
| 19 | ++++ b/stages/org.osbuild.selinux |
| 20 | +@@ -8,11 +8,14 @@ from osbuild.util import selinux |
| 21 | + |
| 22 | + |
| 23 | + def main(tree, options): |
| 24 | +- file_contexts = os.path.join(f"{tree}", options["file_contexts"]) |
| 25 | ++ file_contexts = options.get("file_contexts") |
| 26 | + exclude_paths = options.get("exclude_paths") |
| 27 | +- if exclude_paths: |
| 28 | +- exclude_paths = [os.path.join(tree, p.lstrip("/")) for p in exclude_paths] |
| 29 | +- selinux.setfiles(file_contexts, os.fspath(tree), "", exclude_paths=exclude_paths) |
| 30 | ++ |
| 31 | ++ if file_contexts: |
| 32 | ++ file_contexts = os.path.join(f"{tree}", options["file_contexts"]) |
| 33 | ++ if exclude_paths: |
| 34 | ++ exclude_paths = [os.path.join(tree, p.lstrip("/")) for p in exclude_paths] |
| 35 | ++ selinux.setfiles(file_contexts, os.fspath(tree), "", exclude_paths=exclude_paths) |
| 36 | + |
| 37 | + labels = options.get("labels", {}) |
| 38 | + for path, label in labels.items(): |
| 39 | +diff --git a/stages/org.osbuild.selinux.meta.json b/stages/org.osbuild.selinux.meta.json |
| 40 | +index ea1bb3ef..151839e5 100644 |
| 41 | +--- a/stages/org.osbuild.selinux.meta.json |
| 42 | ++++ b/stages/org.osbuild.selinux.meta.json |
| 43 | +@@ -20,8 +20,17 @@ |
| 44 | + "schema_2": { |
| 45 | + "options": { |
| 46 | + "additionalProperties": false, |
| 47 | +- "required": [ |
| 48 | +- "file_contexts" |
| 49 | ++ "oneOf": [ |
| 50 | ++ { |
| 51 | ++ "required": [ |
| 52 | ++ "file_contexts" |
| 53 | ++ ] |
| 54 | ++ }, |
| 55 | ++ { |
| 56 | ++ "required": [ |
| 57 | ++ "labels" |
| 58 | ++ ] |
| 59 | ++ } |
| 60 | + ], |
| 61 | + "properties": { |
| 62 | + "file_contexts": { |
| 63 | +-- |
| 64 | +2.46.0 |
| 65 | + |
0 commit comments