[A recent breaking change upstream in Golang's crypto
library](e4e2799dd7
)
has broken SSH connectivity for a few builders:
```
==> qemu: Waiting for SSH to become available...
2017/05/20 16:23:58 ui: ==> qemu: Waiting for SSH to become available...
2017/05/20 16:23:58 packer: 2017/05/20 16:23:58 [INFO] Attempting SSH connection...
2017/05/20 16:23:58 packer: 2017/05/20 16:23:58 reconnecting to TCP connection for SSH
2017/05/20 16:23:58 packer: 2017/05/20 16:23:58 handshaking with SSH
2017/05/20 16:23:58 packer: 2017/05/20 16:23:58 handshake error: ssh: must specify HostKeyCallback
2017/05/20 16:23:58 packer: 2017/05/20 16:23:58 [DEBUG] SSH handshake err: ssh: must specify HostKeyCallback
2017/05/20 16:24:05 packer: 2017/05/20 16:24:05 [INFO] Attempting SSH connection...
2017/05/20 16:24:05 packer: 2017/05/20 16:24:05 reconnecting to TCP connection for SSH
2017/05/20 16:24:05 packer: 2017/05/20 16:24:05 handshaking with SSH
2017/05/20 16:24:05 packer: 2017/05/20 16:24:05 handshake error: ssh: must specify HostKeyCallback
2017/05/20 16:24:05 packer: 2017/05/20 16:24:05 [DEBUG] SSH handshake err: ssh: must specify HostKeyCallback
```
Specifying HostKeyCallback as insecure should make things work again
and would make sense for packer's use case.
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package null
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/hashicorp/packer/communicator/ssh"
|
|
"github.com/mitchellh/multistep"
|
|
gossh "golang.org/x/crypto/ssh"
|
|
"io/ioutil"
|
|
)
|
|
|
|
func CommHost(host string) func(multistep.StateBag) (string, error) {
|
|
return func(state multistep.StateBag) (string, error) {
|
|
return host, nil
|
|
}
|
|
}
|
|
|
|
// SSHConfig returns a function that can be used for the SSH communicator
|
|
// config for connecting to the specified host via SSH
|
|
// private_key_file has precedence over password!
|
|
func SSHConfig(username string, password string, privateKeyFile string) func(multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
return func(state multistep.StateBag) (*gossh.ClientConfig, error) {
|
|
|
|
if privateKeyFile != "" {
|
|
// key based auth
|
|
|
|
bytes, err := ioutil.ReadFile(privateKeyFile)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
}
|
|
privateKey := string(bytes)
|
|
|
|
signer, err := gossh.ParsePrivateKey([]byte(privateKey))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Error setting up SSH config: %s", err)
|
|
}
|
|
|
|
return &gossh.ClientConfig{
|
|
User: username,
|
|
Auth: []gossh.AuthMethod{
|
|
gossh.PublicKeys(signer),
|
|
},
|
|
}, nil
|
|
} else {
|
|
// password based auth
|
|
|
|
return &gossh.ClientConfig{
|
|
User: username,
|
|
Auth: []gossh.AuthMethod{
|
|
gossh.Password(password),
|
|
gossh.KeyboardInteractive(
|
|
ssh.PasswordKeyboardInteractive(password)),
|
|
},
|
|
HostKeyCallback: gossh.InsecureIgnoreHostKey(),
|
|
}, nil
|
|
}
|
|
}
|
|
}
|