nspawn: fix --link-journal=host with --private-users=pick and friends

Fixes #38611.
This commit is contained in:
Yu Watanabe
2025-08-20 16:17:59 +09:00
parent 045227426e
commit 88fce09026
2 changed files with 40 additions and 7 deletions
+16 -7
View File
@@ -2566,7 +2566,7 @@ static int setup_hostname(void) {
return 0;
}
static int setup_journal(const char *directory) {
static int setup_journal(const char *directory, uid_t uid_shift, uid_t uid_range) {
_cleanup_free_ char *d = NULL;
sd_id128_t this_id;
bool try;
@@ -2693,11 +2693,20 @@ static int setup_journal(const char *directory) {
if (r < 0)
return log_error_errno(r, "Failed to create %s: %m", q);
r = mount_nofollow_verbose(LOG_DEBUG, p, q, NULL, MS_BIND, NULL);
if (r < 0)
return log_error_errno(r, "Failed to bind mount journal from host into guest: %m");
return 0;
return mount_custom(
directory,
&(CustomMount) {
.type = CUSTOM_MOUNT_BIND,
.options = (char*) (uid_is_valid(uid_shift) ? "rootidmap" : NULL),
.source = p,
.destination = p,
.destination_uid = UID_INVALID,
},
/* n = */ 1,
uid_shift,
uid_range,
arg_selinux_apifs_context,
MOUNT_NON_ROOT_ONLY);
}
static int drop_capabilities(uid_t uid) {
@@ -4270,7 +4279,7 @@ static int outer_child(
if (r < 0)
return r;
r = setup_journal(directory);
r = setup_journal(directory, chown_uid, chown_range);
if (r < 0)
return r;