nspawn: align config PrivateUsersOwnership default with CLI

The `systemd-nspawn` manpage says:

    The `--private-users-ownership=auto` option is implied if
    `--private-users=pick` is used.

This is true for the CLI, but not when set in a `.nspawn` file.
Assuming these defaults should be the same across both.

This default was also not updated when `managed` was added by #35685.

As a result, this is a change in behavior for users who didn't set an
explicit `PrivateUsersOwnership=` value in their `.nspawn` file.
This commit is contained in:
Cathal Mullan
2026-09-14 08:10:27 +01:00
committed by Luca Boccassi
parent d04aa853bc
commit 1f66b52452
4 changed files with 15 additions and 6 deletions
+3 -1
View File
@@ -95,7 +95,9 @@ int settings_load(FILE *f, const char *path, Settings **ret) {
/* Make sure that if userns_mode is set, userns_chown is set to something appropriate, and vice versa. Either
* both fields shall be initialized or neither. */
if (s->userns_mode >= 0 && s->userns_ownership < 0)
s->userns_ownership = s->userns_mode == USER_NAMESPACE_PICK ? USER_NAMESPACE_OWNERSHIP_CHOWN : USER_NAMESPACE_OWNERSHIP_OFF;
s->userns_ownership = IN_SET(s->userns_mode, USER_NAMESPACE_PICK, USER_NAMESPACE_MANAGED)
? USER_NAMESPACE_OWNERSHIP_AUTO
: USER_NAMESPACE_OWNERSHIP_OFF;
if (s->userns_ownership >= 0 && s->userns_mode < 0)
s->userns_mode = USER_NAMESPACE_NO;