Skip to content

Commit 0065aee

Browse files
authored
Merge pull request #1046 from kernelkit/resctrict-mount-in-cont
confd: Add mount constraint for container config
2 parents d6d621a + dfc350a commit 0065aee

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

doc/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ All notable changes to the project are documented in this file.
2020
### Fixes
2121
- Fix containers with multiple mounts
2222
- Correct description for LAG LACP modes
23+
- Fix #1040: Add `mount` constraint for container config
2324

2425

2526
[v25.04.0][] - 2025-04-30

src/confd/src/infix-containers.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,35 @@ static int change(sr_session_ctx_t *session, uint32_t sub_id, const char *module
250250
switch (event) {
251251
case SR_EV_DONE:
252252
break;
253+
253254
case SR_EV_CHANGE:
255+
err = sr_get_data(session, CFG_XPATH "//.", 0, 0, 0, &cfg);
256+
if (err || !cfg)
257+
return SR_ERR_INTERNAL;
258+
259+
cifs = lydx_get_descendant(cfg->tree, "containers", "container", NULL);
260+
LYX_LIST_FOR_EACH(cifs, cif, "container") {
261+
struct lyd_node *mount;
262+
LYX_LIST_FOR_EACH(lyd_child(cif), mount, "mount") {
263+
const char *src = lydx_get_cattr(mount, "source");
264+
const char *id = lydx_get_cattr(mount, "name");
265+
266+
if (src && access(src, R_OK) != 0) {
267+
char errmsg[256];
268+
const char *reason = strerror(errno);
269+
snprintf(errmsg, sizeof(errmsg),
270+
"Container '%s': mount '%s' source file '%s' is invalid: %s",
271+
lydx_get_cattr(cif, "name"), id, src, reason);
272+
sr_session_set_error_message(session, errmsg);
273+
sr_release_data(cfg);
274+
return SR_ERR_VALIDATION_FAILED;
275+
}
276+
}
277+
}
278+
279+
sr_release_data(cfg);
280+
return SR_ERR_OK;
281+
254282
case SR_EV_ABORT:
255283
default:
256284
return SR_ERR_OK;

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

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

25+
revision 2025-05-14 {
26+
description
27+
"Validation improvement:
28+
- Added constraint to require either 'source' or 'content' in a container mount.";
29+
reference "internal";
30+
}
31+
2532
revision 2024-11-15 {
2633
description "Two major changes:
2734
- Add support for ftp/http/https images with checksum
@@ -342,6 +349,7 @@ module infix-containers {
342349
}
343350

344351
choice data {
352+
mandatory true;
345353
case source {
346354
leaf source {
347355
description "Host path to mount in container, may be a glob.

src/confd/yang/containers.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# REMEMBER TO UPDATE infix-interfaces ALSO IN confd.inc
33
MODULES=(
44
"[email protected] -e vlan-filtering -e containers"
5-
"infix-containers@2024-11-15.yang"
5+
"infix-containers@2025-05-14.yang"
66
)

0 commit comments

Comments
 (0)