all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH container] fix #7164: lxc: restore: apply password and ssh keys during container restore
@ 2026-07-16 15:39 Elias Huhsovitz
  0 siblings, 0 replies; only message in thread
From: Elias Huhsovitz @ 2026-07-16 15:39 UTC (permalink / raw)
  To: pve-devel; +Cc: Elias Huhsovitz

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





^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-16 15:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 15:39 [PATCH container] fix #7164: lxc: restore: apply password and ssh keys during container restore Elias Huhsovitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal