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
  2026-07-24 12:11 ` Erik Fastermann
  2026-07-29  8:34 ` superseded: " Elias Huhsovitz
  0 siblings, 2 replies; 3+ messages 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] 3+ messages in thread

end of thread, other threads:[~2026-07-29  8:34 UTC | newest]

Thread overview: 3+ messages (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
2026-07-24 12:11 ` Erik Fastermann
2026-07-29  8:34 ` superseded: " 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