public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Erik Fastermann <e.fastermann@proxmox.com>
To: Elias Huhsovitz <e.huhsovitz@proxmox.com>, pve-devel@lists.proxmox.com
Subject: Re: [PATCH container] fix #7164: lxc: restore: apply password and ssh keys during container restore
Date: Fri, 24 Jul 2026 14:11:22 +0200	[thread overview]
Message-ID: <95a38704-543e-4820-b36c-696cf192a684@proxmox.com> (raw)
In-Reply-To: <20260716153959.183045-1-e.huhsovitz@proxmox.com>

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 <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);

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);





      reply	other threads:[~2026-07-24 12:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

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=95a38704-543e-4820-b36c-696cf192a684@proxmox.com \
    --to=e.fastermann@proxmox.com \
    --cc=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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal