Skip to content

Commit

Permalink
fix: insecure host key
Browse files Browse the repository at this point in the history
Uses the knownhosts package to validate the host key.

Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
  • Loading branch information
tenthirtyam committed Oct 15, 2024
1 parent 3b080bf commit 8ffe005
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion builder/vmware/common/driver_esxi.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/sdk-internals/communicator/ssh"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
)

// EsxiDriver is a driver for building virtual machines on an ESXi host.
Expand Down Expand Up @@ -747,12 +748,18 @@ func (d *EsxiDriver) connect() error {
auth = append(auth, gossh.PublicKeys(signer))
}

knownHostsFile := filepath.Join(os.Getenv("HOME"), ".ssh", "known_hosts")
hostKeyCallback, err := knownhosts.New(knownHostsFile)
if err != nil {
return err
}

sshConfig := &ssh.Config{
Connection: ssh.ConnectFunc("tcp", address),
SSHConfig: &gossh.ClientConfig{
User: d.Username,
Auth: auth,
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
HostKeyCallback: hostKeyCallback,
},
}

Expand Down

0 comments on commit 8ffe005

Please sign in to comment.