summaryrefslogtreecommitdiffstats
path: root/src/nspawn/nspawn.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-12-05 10:24:13 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2023-12-07 00:07:26 +0100
commitdd78141c530a141f170867b3fc5572b577168759 (patch)
tree54d51610460552807ddcf59feb320fdb0b5edfa3 /src/nspawn/nspawn.c
parentgpt-auto-generator: Pass cryptsetup credentials to cryptsetup (diff)
downloadsystemd-dd78141c530a141f170867b3fc5572b577168759.tar.xz
systemd-dd78141c530a141f170867b3fc5572b577168759.zip
nspawn: Check later whether to keep/drop CAP_NET_BIND_SERVICE
Currently the check doesn't take any settings from nspawn settings files into account, so let's delay the check until after we've loaded any settings file.
Diffstat (limited to 'src/nspawn/nspawn.c')
-rw-r--r--src/nspawn/nspawn.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 8ac86eeb55..6ab604d3dc 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1632,13 +1632,6 @@ static int parse_argv(int argc, char *argv[]) {
arg_caps_retain |= plus;
arg_caps_retain |= arg_private_network ? UINT64_C(1) << CAP_NET_ADMIN : 0;
-
- /* If we're not unsharing the network namespace and are unsharing the user namespace, we won't have
- * permissions to bind ports in the container, so let's drop the CAP_NET_BIND_SERVICE capability to
- * indicate that. */
- if (!arg_private_network && arg_userns_mode != USER_NAMESPACE_NO && arg_uid_shift > 0)
- arg_caps_retain &= ~(UINT64_C(1) << CAP_NET_BIND_SERVICE);
-
arg_caps_retain &= ~minus;
/* Make sure to parse environment before we reset the settings mask below */
@@ -5420,6 +5413,12 @@ static int run(int argc, char *argv[]) {
if (r < 0)
goto finish;
+ /* If we're not unsharing the network namespace and are unsharing the user namespace, we won't have
+ * permissions to bind ports in the container, so let's drop the CAP_NET_BIND_SERVICE capability to
+ * indicate that. */
+ if (!arg_private_network && arg_userns_mode != USER_NAMESPACE_NO && arg_uid_shift > 0)
+ arg_caps_retain &= ~(UINT64_C(1) << CAP_NET_BIND_SERVICE);
+
r = cg_unified();
if (r < 0) {
log_error_errno(r, "Failed to determine whether the unified cgroups hierarchy is used: %m");