Skip to content

Commit 11db312

Browse files
manifests: set proper SELinux labels for '/boot/efi' and '/boot/lost+found'
Issue: osbuild/osbuild#1877
1 parent af1468c commit 11db312

11 files changed

+835
-45
lines changed

build.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ patch_osbuild() {
173173
mv /usr/bin/osbuild-mpp /usr/lib/osbuild/tools/
174174

175175
# Now all the software is under the /usr/lib/osbuild dir and we can patch
176-
patch -d /usr/lib/osbuild -p1 < /usr/lib/coreos-assembler/0001-hacks-for-coreos-selinux-issues.patch
176+
cat /usr/lib/coreos-assembler/0001-org.osbuild.mkdir-support-creating-dirs-on-mounts.patch \
177+
/usr/lib/coreos-assembler/0001-parsing-add-parse_location_into_parts.patch \
178+
/usr/lib/coreos-assembler/0002-parsing-treat-locations-without-scheme-as-belonging-.patch \
179+
/usr/lib/coreos-assembler/0003-org.osbuild.selinux-support-operating-on-mounts.patch \
180+
/usr/lib/coreos-assembler/0004-org.osbuild.selinux-support-for-specifying-where-fil.patch \
181+
| patch -d /usr/lib/osbuild -p1
177182

178183
# And then move the files back; supermin appliance creation will need it back
179184
# in the places delivered by the RPM.

src/0001-hacks-for-coreos-selinux-issues.patch

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
From 362a1ea2485ea2c49e6c250a0446bd5a33b2062c Mon Sep 17 00:00:00 2001
2+
From: Nikita Dubrovskii <[email protected]>
3+
Date: Mon, 30 Sep 2024 15:46:31 +0200
4+
Subject: [PATCH] org.osbuild.mkdir: support creating dirs on mounts
5+
6+
This allows creating new directories on mounts:
7+
```
8+
- type: org.osbuild.mkdir
9+
options:
10+
paths:
11+
- path: mount:///boot/efi
12+
devices:
13+
disk: ...
14+
mounts:
15+
- name: boot
16+
target: /boot
17+
...
18+
```
19+
---
20+
stages/org.osbuild.mkdir | 22 ++++++++++++----------
21+
stages/org.osbuild.mkdir.meta.json | 21 ++++++++++++++++++---
22+
2 files changed, 30 insertions(+), 13 deletions(-)
23+
24+
diff --git a/stages/org.osbuild.mkdir b/stages/org.osbuild.mkdir
25+
index f04549f6..d2d11a7a 100755
26+
--- a/stages/org.osbuild.mkdir
27+
+++ b/stages/org.osbuild.mkdir
28+
@@ -3,23 +3,26 @@ import os
29+
import sys
30+
31+
import osbuild.api
32+
-from osbuild.util.path import in_tree
33+
+from osbuild.util import parsing
34+
35+
36+
-def main(tree, options):
37+
+def main(args):
38+
+ options = args["options"]
39+
+
40+
for item in options["paths"]:
41+
path = item["path"]
42+
mode = item.get("mode", 0o777)
43+
parents = item.get("parents", False)
44+
exist_ok = item.get("exist_ok", False)
45+
46+
- if not path.startswith("/"):
47+
- print("WARNING: relative path used, this is discouraged!")
48+
-
49+
- target = os.path.join(tree, path.lstrip("/"))
50+
- if not in_tree(target, tree):
51+
- raise ValueError(f"path {path} not in tree")
52+
+ if "://" not in path:
53+
+ if not path.startswith("/"):
54+
+ print("WARNING: relative path used, this is discouraged!")
55+
+ path = f"tree:///{path}"
56+
+ else:
57+
+ path = f"tree://{path}"
58+
59+
+ target = parsing.parse_location(path, args)
60+
if parents:
61+
os.makedirs(target, mode=mode, exist_ok=exist_ok)
62+
else:
63+
@@ -33,5 +36,4 @@ def main(tree, options):
64+
65+
66+
if __name__ == "__main__":
67+
- args = osbuild.api.arguments()
68+
- sys.exit(main(args["tree"], args["options"]))
69+
+ sys.exit(main(osbuild.api.arguments()))
70+
diff --git a/stages/org.osbuild.mkdir.meta.json b/stages/org.osbuild.mkdir.meta.json
71+
index 5534120a..6cebaaf5 100644
72+
--- a/stages/org.osbuild.mkdir.meta.json
73+
+++ b/stages/org.osbuild.mkdir.meta.json
74+
@@ -1,5 +1,5 @@
75+
{
76+
- "summary": "Create directories within the tree.",
77+
+ "summary": "Create directories within the tree or mount.",
78+
"description": [
79+
"Can create one or more directories, optionally also the",
80+
"intermediate directories. The stage can gracefully handle",
81+
@@ -31,8 +31,23 @@
82+
],
83+
"properties": {
84+
"path": {
85+
- "type": "string",
86+
- "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
87+
+ "anyOf": [
88+
+ {
89+
+ "type": "string",
90+
+ "description": "Target path, if a tree",
91+
+ "pattern": "^\\/?(?!\\.\\.)((?!\\/\\.\\.\\/).)+$"
92+
+ },
93+
+ {
94+
+ "type": "string",
95+
+ "description": "Target path, if a mount",
96+
+ "pattern": "^mount://.+"
97+
+ },
98+
+ {
99+
+ "type": "string",
100+
+ "description": "Target path, if a tree",
101+
+ "pattern": "^tree://.+"
102+
+ }
103+
+ ]
104+
},
105+
"mode": {
106+
"type": "number",
107+
--
108+
2.47.0
109+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From 762ef314a0da81cf33da750e3208007704459e59 Mon Sep 17 00:00:00 2001
2+
From: Nikita Dubrovskii <[email protected]>
3+
Date: Fri, 18 Oct 2024 12:28:32 +0200
4+
Subject: [PATCH 1/4] parsing: add parse_location_into_parts
5+
6+
New fucntion returns tuple of 'root' and relative 'file path', which could be
7+
useful in contexts, where knowing 'root' is required, for example setting
8+
selinux labels.
9+
---
10+
osbuild/util/parsing.py | 25 +++++++++++++++++++------
11+
1 file changed, 19 insertions(+), 6 deletions(-)
12+
13+
diff --git a/osbuild/util/parsing.py b/osbuild/util/parsing.py
14+
index f8fb2768..f75ffd67 100644
15+
--- a/osbuild/util/parsing.py
16+
+++ b/osbuild/util/parsing.py
17+
@@ -2,7 +2,7 @@
18+
19+
import os
20+
import re
21+
-from typing import Dict, Union
22+
+from typing import Dict, Tuple, Union
23+
from urllib.parse import ParseResult, urlparse
24+
25+
26+
@@ -72,9 +72,9 @@ def parse_input(url: ParseResult, args: Dict) -> os.PathLike:
27+
return root
28+
29+
30+
-def parse_location(location: str, args: Dict) -> str:
31+
+def parse_location_into_parts(location: str, args: Dict) -> Tuple[str, str]:
32+
"""
33+
- Parses the location URL to derive the corresponding file path.
34+
+ Parses the location URL to derive the corresponding root and url path.
35+
36+
Parameters:
37+
- location (str): The location URL to be parsed.
38+
@@ -97,11 +97,24 @@ def parse_location(location: str, args: Dict) -> str:
39+
if not url.path.startswith("/"):
40+
raise ValueError(f"url.path from location must start with '/', got: {url.path}")
41+
42+
- path = os.path.relpath(url.path, "/")
43+
+ return root, url.path
44+
+
45+
+
46+
+def parse_location(location: str, args: Dict) -> str:
47+
+ """
48+
+ Parses the location URL to derive the corresponding file path.
49+
+
50+
+ Parameters:
51+
+ - location (str): The location URL to be parsed.
52+
+ - args (Dict): A dictionary containing arguments including mounts and
53+
+ path information as passed by osbuild.api.arguments()
54+
+ """
55+
+
56+
+ root, urlpath = parse_location_into_parts(location, args)
57+
+ path = os.path.relpath(urlpath, "/")
58+
path = os.path.join(root, path)
59+
path = os.path.normpath(path)
60+
-
61+
- if url.path.endswith("/"):
62+
+ if urlpath.endswith("/"):
63+
path = os.path.join(path, ".")
64+
65+
return path
66+
--
67+
2.47.0
68+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 14f0d823d4541a564df5fc6624c149b50fb8e88b Mon Sep 17 00:00:00 2001
2+
From: Nikita Dubrovskii <[email protected]>
3+
Date: Mon, 28 Oct 2024 11:20:23 +0100
4+
Subject: [PATCH 2/4] parsing: treat locations without scheme as belonging to
5+
'tree://'
6+
7+
---
8+
osbuild/util/parsing.py | 8 ++++++++
9+
stages/org.osbuild.mkdir | 7 -------
10+
2 files changed, 8 insertions(+), 7 deletions(-)
11+
12+
diff --git a/osbuild/util/parsing.py b/osbuild/util/parsing.py
13+
index f75ffd67..6a907a1d 100644
14+
--- a/osbuild/util/parsing.py
15+
+++ b/osbuild/util/parsing.py
16+
@@ -82,6 +82,14 @@ def parse_location_into_parts(location: str, args: Dict) -> Tuple[str, str]:
17+
path information as passed by osbuild.api.arguments()
18+
"""
19+
20+
+ if "://" not in location:
21+
+ print("INFO: location has no scheme, assuming 'tree://'")
22+
+ if location.startswith("/"):
23+
+ location = f"tree://{location}"
24+
+ else:
25+
+ print("WARNING: relative path used, this is discouraged!")
26+
+ location = f"tree:///{location}"
27+
+
28+
url = urlparse(location)
29+
30+
scheme = url.scheme
31+
diff --git a/stages/org.osbuild.mkdir b/stages/org.osbuild.mkdir
32+
index d2d11a7a..6861b131 100755
33+
--- a/stages/org.osbuild.mkdir
34+
+++ b/stages/org.osbuild.mkdir
35+
@@ -15,13 +15,6 @@ def main(args):
36+
parents = item.get("parents", False)
37+
exist_ok = item.get("exist_ok", False)
38+
39+
- if "://" not in path:
40+
- if not path.startswith("/"):
41+
- print("WARNING: relative path used, this is discouraged!")
42+
- path = f"tree:///{path}"
43+
- else:
44+
- path = f"tree://{path}"
45+
-
46+
target = parsing.parse_location(path, args)
47+
if parents:
48+
os.makedirs(target, mode=mode, exist_ok=exist_ok)
49+
--
50+
2.47.0
51+

0 commit comments

Comments
 (0)