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 2AEA31FF0E9 for ; Thu, 16 Jul 2026 17:40:07 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7E1B22143D; Thu, 16 Jul 2026 17:40:06 +0200 (CEST) From: Elias Huhsovitz To: pve-devel@lists.proxmox.com Subject: [PATCH container] fix #7164: lxc: restore: apply password and ssh keys during container restore Date: Thu, 16 Jul 2026 17:39:59 +0200 Message-ID: <20260716153959.183045-1-e.huhsovitz@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: 1784216383547 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.214 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: 42BN4GABM5VKONFQW7QW2ODUQNBQFYIS X-Message-ID-Hash: 42BN4GABM5VKONFQW7QW2ODUQNBQFYIS X-MailFrom: e.huhsovitz@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 CC: Elias Huhsovitz X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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); } 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); }; 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); $self->set_user_authorized_ssh_keys($conf, 'root', $ssh_keys) if $ssh_keys; $self->setup_init($conf); $self->setup_network($conf); -- 2.47.3