From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 6E2681FF0E6 for ; Fri, 24 Jul 2026 14:11:26 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3BAC721493; Fri, 24 Jul 2026 14:11:26 +0200 (CEST) Message-ID: <95a38704-543e-4820-b36c-696cf192a684@proxmox.com> Date: Fri, 24 Jul 2026 14:11:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Beta Subject: Re: [PATCH container] fix #7164: lxc: restore: apply password and ssh keys during container restore To: Elias Huhsovitz , pve-devel@lists.proxmox.com References: <20260716153959.183045-1-e.huhsovitz@proxmox.com> Content-Language: en-US From: Erik Fastermann In-Reply-To: <20260716153959.183045-1-e.huhsovitz@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784895051373 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.230 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_LOW -0.7 Sender listed at https://www.dnswl.org/, low 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: ES6ONGJUTUB7AOFLYGGDOC5EJ4K6FQS7 X-Message-ID-Hash: ES6ONGJUTUB7AOFLYGGDOC5EJ4K6FQS7 X-MailFrom: e.fastermann@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: See comments inline. > When restoring a container with `pct restore`, the `--password` and > `--ssh-public-keys` options are silently ignored. The `create_vm` API > endpoint only invokes the `post_create_hook` during initial container > creation, skipping it entirely for restores. > > To resolve this, make the credential updates in > `PVE::LXC::Setup::Base::post_create_hook` conditional. The > hook now applies the password or SSH keys only if they are explicitly > defined. > > Invoke the hook for create/restore. > > Signed-off-by: Elias Huhsovitz > --- > src/PVE/API2/LXC.pm | 5 ++--- > src/PVE/LXC/Setup/Base.pm | 2 +- > 2 files changed, 3 insertions(+), 4 deletions(-) > > diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm > index 88067dd..8e6e7e8 100644 > --- a/src/PVE/API2/LXC.pm > +++ b/src/PVE/API2/LXC.pm > @@ -570,6 +570,7 @@ __PACKAGE__->register_method({ > ); > } > > + my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); > if ($restore) { > print "merging backed-up and given configuration..\n"; > PVE::LXC::Create::restore_configuration( > @@ -583,13 +584,11 @@ __PACKAGE__->register_method({ > $skip_fw_config_restore, > ); > PVE::LXC::create_ifaces_ipams_ips($conf, $vmid) if $unique; > - my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); > $lxc_setup->template_fixup($conf); Calling `template_fixup` here should have no effect as it's now called again by `post_create_hook` below. > } else { > - my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir); # detect OS > PVE::LXC::Config->write_config($vmid, $conf); # safe config (after OS detection) > - $lxc_setup->post_create_hook($password, $ssh_keys); > } > + $lxc_setup->post_create_hook($password, $ssh_keys); Calling `post_create_hook` unconditionally has some unintended consequences. E.g. now `clear_machine_id` unlinks `/etc/machine-id`, which we probably don't want. There might be a lot of other issues, but I haven't looked further into this. > }; > my $err = $@; > PVE::LXC::umount_all($vmid, $storage_cfg, $conf, $err ? 1 : 0); > diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm > index 567f9d6..13dd6b9 100644 > --- a/src/PVE/LXC/Setup/Base.pm > +++ b/src/PVE/LXC/Setup/Base.pm > @@ -724,7 +724,7 @@ sub post_create_hook { > > &$randomize_crontab($self, $conf); > > - $self->set_user_password($conf, 'root', $root_password); > + $self->set_user_password($conf, 'root', $root_password) if defined($root_password); This breaks the non-restore path, because if the password is undef, `set_user_password` previously disabled the password based login by setting the password to an asterisk in `/etc/shadow`. Now this depends on the behavior of the template, as `set_user_password` is not called anymore in this case. > $self->set_user_authorized_ssh_keys($conf, 'root', $ssh_keys) if $ssh_keys; > $self->setup_init($conf); > $self->setup_network($conf);