From: Elias Huhsovitz <e.huhsovitz@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Elias Huhsovitz <e.huhsovitz@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 [thread overview]
Message-ID: <20260716153959.183045-1-e.huhsovitz@proxmox.com> (raw)
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 <e.huhsovitz@proxmox.com>
---
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
reply other threads:[~2026-07-16 15:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716153959.183045-1-e.huhsovitz@proxmox.com \
--to=e.huhsovitz@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox