From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 259D41FF09B for ; Mon, 09 Nov 2026 15:52:02 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 27B7F214DD; Mon, 09 Nov 2026 15:51:59 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Subject: [PATCH container] fix #8254: oci create: do not require /etc/ files for numeric ids Date: Mon, 9 Nov 2026 15:50:00 +0100 Message-ID: <20261109145146.105652-1-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794235914351 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.265 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 3KZTL36OWKHCS6VDO6NJCHEKRX5BIGDG X-Message-ID-Hash: 3KZTL36OWKHCS6VDO6NJCHEKRX5BIGDG X-MailFrom: f.schauer@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: resolve_oci_user() used to always die if /etc/passwd or /etc/group could not be resolved in the container rootfs, even when the image config set a numeric User that needs no lookup. Only treat the files as unresolvable when they are actually needed. This also changes behavior when a name cannot be resolved. It now fails with an error instead of silently continuing without a UID or GID, which let the container's init run as root even though the image asked for a different user. This is also required by the OCI image spec, in the "Conversion to OCI Runtime Configuration" section: "If Config.User does not correspond to a user in the container's context, the converter MUST return an error." Signed-off-by: Filip Schauer --- src/PVE/LXC/Create.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm index 64a6f66..3c07911 100644 --- a/src/PVE/LXC/Create.pm +++ b/src/PVE/LXC/Create.pm @@ -801,12 +801,13 @@ sub resolve_oci_user { # Prevent symlinks from escaping out of container rootdir chroot($rootdir) or die "failed to change root to: $rootdir: $!\n"; chdir('/') or die "failed to change to root directory\n"; - my $etc_passwd = abs_path('/etc/passwd') - or die "cannot resolve /etc/passwd path in container rootfs\n"; - my $etc_group = abs_path('/etc/group') - or die "cannot resolve /etc/group path in container rootfs\n"; + my $etc_passwd = abs_path('/etc/passwd'); + my $etc_group = abs_path('/etc/group'); - return [$rootdir . $etc_passwd, $rootdir . $etc_group]; + return [ + defined($etc_passwd) ? $rootdir . $etc_passwd : undef, + defined($etc_group) ? $rootdir . $etc_group : undef, + ]; }) }; @@ -858,6 +859,7 @@ sub resolve_oci_user { } else { $username = $user; $uid = $lookup_field->($etc_passwd, 0, $username, 2); + die "cannot resolve username '$username' to uid\n" if !defined($uid); } if (defined($group)) { @@ -865,6 +867,7 @@ sub resolve_oci_user { $gid = $group; } else { $gid = $lookup_field->($etc_group, 0, $group, 2); + die "cannot resolve group '$group' to gid\n" if !defined($gid); } } else { $gid = $lookup_field->($etc_passwd, 2, $uid, 3) if defined($uid); -- 2.47.3