]> git.proxmox.com Git - pve-cluster.git/commitdiff
fix #4886: SSH: pin node's host key if available
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 11 Jan 2024 10:51:16 +0000 (11:51 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 25 Mar 2024 17:00:31 +0000 (18:00 +0100)
if the target node has already stored their SSH host key on pmxcfs, pin it and
ignore the global known hosts information.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Hannes Duerr <h.duerr@proxmox.com>
src/PVE/SSHInfo.pm

index c351148cbe43e1e4166647f9b579915a2e202832..16ed85a6818f9c9262ea873759f61de067feccb9 100644 (file)
@@ -49,11 +49,24 @@ sub get_ssh_info {
 
 sub ssh_info_to_command_base {
     my ($info, @extra_options) = @_;
+
+    my $nodename = $info->{name};
+
+    my $known_hosts_file = "/etc/pve/nodes/$nodename/ssh_known_hosts";
+    my $known_hosts_options = undef;
+    if (-f $known_hosts_file) {
+       $known_hosts_options = [
+           '-o', "UserKnownHostsFile=$known_hosts_file",
+           '-o', 'GlobalKnownHostsFile=none',
+       ];
+    }
+
     return [
        '/usr/bin/ssh',
        '-e', 'none',
        '-o', 'BatchMode=yes',
-       '-o', 'HostKeyAlias='.$info->{name},
+       '-o', 'HostKeyAlias='.$nodename,
+       defined($known_hosts_options) ? @$known_hosts_options : (),
        @extra_options
     ];
 }