Skip to content

Commit a0c48e7

Browse files
committed
Add support for setting mode of a container content mount
Fixes #1070 Signed-off-by: Joachim Wiberg <[email protected]>
1 parent edd2e60 commit a0c48e7

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

doc/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ All notable changes to the project are documented in this file.
1010
- Upgrade Buildroot to 2025.02.4 (LTS)
1111
- Upgrade Linux kernel to 6.12.34 (LTS)
1212
- Upgrade curiOS built-in containers to v25.06.0
13+
- Add support for setting mode of a container content mount, issue #1070
1314
- Add Wi-Fi client support and add support for some USB-Wi-Fi cards
1415
- New slogan: Infix OS — Immutable.Friendly.Secure
1516

src/confd/src/infix-containers.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,25 @@ static int add(const char *name, struct lyd_node *cif)
113113

114114
/* Content mount: create a unique file with 'content' and bind mount */
115115
if (data) {
116+
const char *mode = lydx_get_cattr(node, "mode");
116117
const char *contdir = "/run/containers/files";
118+
mode_t file_mode = 0644;
117119
char cmd[256];
120+
int pos, fd;
118121
FILE *pp;
119-
int pos;
122+
123+
if (mode) {
124+
unsigned long val;
125+
char *endptr;
126+
127+
val = strtoul(mode, &endptr, 8);
128+
if (*endptr != '\0' || val > 07777) {
129+
ERROR("%s: invalid file mode '%s'", nm, mode);
130+
continue;
131+
}
132+
133+
file_mode = (mode_t)val;
134+
}
120135

121136
/*
122137
* prefix file name with container name, shared namespace,
@@ -129,6 +144,27 @@ static int add(const char *name, struct lyd_node *cif)
129144
nm[i] = '-';
130145
}
131146

147+
/*
148+
* Always create with secure permissions, then immediately
149+
* set final mode. This takes care of both new files and
150+
* updates to existing files atomically.
151+
*/
152+
fd = open(nm, O_CREAT | O_WRONLY | O_TRUNC, 0600);
153+
if (fd < 0) {
154+
ERRNO("%s: failed creating file %s", name, nm);
155+
continue;
156+
}
157+
158+
/* Set final permissions */
159+
if (fchmod(fd, file_mode) < 0) {
160+
ERRNO("%s: failed setting file mode %s", nm, mode);
161+
close(fd);
162+
unlink(nm);
163+
continue;
164+
}
165+
close(fd);
166+
167+
/* Now decode base64 content into the properly secured file */
132168
snprintf(cmd, sizeof(cmd), "base64 -d > %s", nm);
133169
pp = popen(cmd, "w");
134170
if (!pp || fputs(data, pp) < 0) {
@@ -137,8 +173,8 @@ static int add(const char *name, struct lyd_node *cif)
137173
pclose(pp);
138174
continue;
139175
}
140-
141176
pclose(pp);
177+
142178
type = "bind"; /* discard any configured setting */
143179
src = nm; /* discard any source, not used for content mounts */
144180
}

src/confd/yang/confd/infix-containers.yang

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ module infix-containers {
2222
prefix infix-sys;
2323
}
2424

25+
revision 2025-06-25 {
26+
description "Add file mode option to content mounts, allows creating scripts.";
27+
reference "internal";
28+
}
29+
2530
revision 2025-05-14 {
2631
description
2732
"Validation improvement:
@@ -390,6 +395,16 @@ module infix-containers {
390395
}
391396
}
392397

398+
leaf mode {
399+
description "File permissions for content mounts (not used for source mounts).
400+
401+
Octal notation (e.g., '755', '0644', '4755'). When not specified,
402+
the mode will be '0644'.";
403+
type string {
404+
pattern '0?[0-7]{3,4}';
405+
}
406+
}
407+
393408
leaf read-only {
394409
description "All mounts are read-only by default.
395410
Use this option to allow containers to write to files

src/confd/yang/containers.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- sh -*-
22
MODULES=(
33
"infix-interfaces -e containers"
4-
"infix-containers@2025-05-14.yang"
4+
"infix-containers@2025-06-25.yang"
55
)

0 commit comments

Comments
 (0)