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 5E49B1FF066 for ; Tue, 24 Nov 2026 15:57:20 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0F425216EA; Tue, 24 Nov 2026 15:57:06 +0100 (CET) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Subject: [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Date: Tue, 24 Nov 2026 15:56:45 +0100 Message-ID: <20261124145651.335234-2-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124145651.335234-1-s.hanreich@proxmox.com> References: <20261124145651.335234-1-s.hanreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795532219701 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.183 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: CVD2CRGEE6FETAGX2OBS67TO4D3A7YQS X-Message-ID-Hash: CVD2CRGEE6FETAGX2OBS67TO4D3A7YQS X-MailFrom: s.hanreich@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: For a network device without 'hwaddr', parse_lxc_network() generates a random MAC address with the prefix configured in datacenter.cfg. The setup code parses the network devices from within the root of the container, where pmxcfs cannot be reached. Starting a container with such a device thus fails in the pre-start hook: Transport endpoint is not connected error in setup task PVE::LXC::Setup::pre_start_hook The setup code never uses the MAC address, so parse the network devices there without generating one, which avoids reading datacenter.cfg. Other code paths rely on the generated MAC address, so add a flag to parse_lxc_network() for opting out of it, and set it in the setup code. This is needed even with the generated MAC addresses persisted on start: hotplugging a network device into a running container sets up all of its network devices, and the others can still lack a MAC address, for example if the container was started before. Also make the setup tests reject any read from pmxcfs, instead of answering reads of datacenter.cfg, so that they catch such reads. Signed-off-by: Stefan Hanreich --- src/PVE/LXC.pm | 2 +- src/PVE/LXC/Config.pm | 4 ++-- src/PVE/LXC/Setup/Alpine.pm | 2 +- src/PVE/LXC/Setup/Base.pm | 2 +- src/PVE/LXC/Setup/CentOS.pm | 4 ++-- src/PVE/LXC/Setup/Debian.pm | 2 +- src/PVE/LXC/Setup/Gentoo.pm | 2 +- src/PVE/LXC/Setup/SUSE.pm | 2 +- src/test/run_setup_tests.pl | 3 +-- 9 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index fa498e0..53464de 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -960,7 +960,7 @@ sub get_primary_ips { # return data from net0 return undef if !defined($conf->{net0}); - my $net = PVE::LXC::Config->parse_lxc_network($conf->{net0}); + my $net = PVE::LXC::Config->parse_lxc_network($conf->{net0}, 1); my $ipv4 = $net->{ip}; if ($ipv4) { diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm index d6f1eeb..a12b975 100644 --- a/src/PVE/LXC/Config.pm +++ b/src/PVE/LXC/Config.pm @@ -1616,14 +1616,14 @@ sub print_lxc_network { } sub parse_lxc_network { - my ($class, $data) = @_; + my ($class, $data, $disable_mac_autogen) = @_; return {} if !$data; my $res = PVE::JSONSchema::parse_property_string($netconf_desc, $data); $res->{type} = 'veth'; - if (!$res->{hwaddr}) { + if (!$res->{hwaddr} && !$disable_mac_autogen) { my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg'); $res->{hwaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix}); } diff --git a/src/PVE/LXC/Setup/Alpine.pm b/src/PVE/LXC/Setup/Alpine.pm index ade9e1d..4fbb3ee 100644 --- a/src/PVE/LXC/Setup/Alpine.pm +++ b/src/PVE/LXC/Setup/Alpine.pm @@ -91,7 +91,7 @@ sub setup_network { my $netstring = $value; # check for dhcp6: - my $d = PVE::LXC::Config->parse_lxc_network($netstring); + my $d = PVE::LXC::Config->parse_lxc_network($netstring, 1); if (defined($d->{ip6}) && ($d->{ip6} eq 'dhcp' || $d->{ip6} eq 'auto')) { $d->{ip6} = 'manual'; $netstring = PVE::LXC::Config->print_lxc_network($d); diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm index bb75690..20c8688 100644 --- a/src/PVE/LXC/Setup/Base.pm +++ b/src/PVE/LXC/Setup/Base.pm @@ -257,7 +257,7 @@ sub setup_systemd_networkd { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); next if !$d->{name}; my $filename = "/etc/systemd/network/$d->{name}.network"; diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm index 7e8140b..a487948 100644 --- a/src/PVE/LXC/Setup/CentOS.pm +++ b/src/PVE/LXC/Setup/CentOS.pm @@ -208,7 +208,7 @@ sub setup_network_with_networkmanager { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); next if !$d->{name}; my $filename = "/etc/NetworkManager/system-connections/$d->{name}.nmconnection"; @@ -295,7 +295,7 @@ sub setup_network_with_network_scripts { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); next if !$d->{name}; $has_ipv4 = 1 if defined($d->{ip}); $has_ipv6 = 1 if defined($d->{ip6}); diff --git a/src/PVE/LXC/Setup/Debian.pm b/src/PVE/LXC/Setup/Debian.pm index 81941d7..ccf0e46 100644 --- a/src/PVE/LXC/Setup/Debian.pm +++ b/src/PVE/LXC/Setup/Debian.pm @@ -254,7 +254,7 @@ sub setup_network { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; my $ind = $1; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); if ($d->{name}) { my $net = {}; my $cidr; diff --git a/src/PVE/LXC/Setup/Gentoo.pm b/src/PVE/LXC/Setup/Gentoo.pm index 6034f27..238ebcf 100644 --- a/src/PVE/LXC/Setup/Gentoo.pm +++ b/src/PVE/LXC/Setup/Gentoo.pm @@ -83,7 +83,7 @@ sub setup_network { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); my $name = $d->{name}; next if !$name; diff --git a/src/PVE/LXC/Setup/SUSE.pm b/src/PVE/LXC/Setup/SUSE.pm index dfe1798..5496f81 100644 --- a/src/PVE/LXC/Setup/SUSE.pm +++ b/src/PVE/LXC/Setup/SUSE.pm @@ -76,7 +76,7 @@ sub setup_network { foreach my $k (keys %$conf) { next if $k !~ m/^net(\d+)$/; - my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); + my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}, 1); next if !$d->{name}; my $filename = "/etc/sysconfig/network/ifcfg-$d->{name}"; diff --git a/src/test/run_setup_tests.pl b/src/test/run_setup_tests.pl index b269ffe..84fa21e 100755 --- a/src/test/run_setup_tests.pl +++ b/src/test/run_setup_tests.pl @@ -113,11 +113,10 @@ sub run_test { print "TEST $testdir => OK\n"; } +# the setup code runs inside the container's root, where pmxcfs is not reachable my $cluster_module = Test::MockModule->new("PVE::Cluster"); $cluster_module->mock( cfs_read_file => sub { - my ($filename) = @_; - return {} if $filename eq 'datacenter.cfg'; die "illegal access to pmxcfs in test!\n"; }, cfs_write_file => sub { -- 2.47.3