|
|
|
|
@ -15,6 +15,7 @@ import (
|
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
|
gossh "golang.org/x/crypto/ssh"
|
|
|
|
|
"golang.org/x/crypto/ssh/agent"
|
|
|
|
|
"golang.org/x/net/proxy"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// StepConnectSSH is a step that only connects to SSH.
|
|
|
|
|
@ -88,6 +89,8 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
|
|
|
|
|
// do this one before entering the retry loop.
|
|
|
|
|
var bProto, bAddr string
|
|
|
|
|
var bConf *gossh.ClientConfig
|
|
|
|
|
var pAddr string
|
|
|
|
|
var pAuth *proxy.Auth
|
|
|
|
|
if s.Config.SSHBastionHost != "" {
|
|
|
|
|
// The protocol is hardcoded for now, but may be configurable one day
|
|
|
|
|
bProto = "tcp"
|
|
|
|
|
@ -101,6 +104,16 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
|
|
|
|
|
bConf = conf
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if s.Config.SSHProxyHost != "" {
|
|
|
|
|
pAddr = fmt.Sprintf("%s:%d", s.Config.SSHProxyHost, s.Config.SSHProxyPort)
|
|
|
|
|
if s.Config.SSHProxyUsername != "" {
|
|
|
|
|
pAuth = new(proxy.Auth)
|
|
|
|
|
pAuth.User = s.Config.SSHBastionUsername
|
|
|
|
|
pAuth.Password = s.Config.SSHBastionPassword
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handshakeAttempts := 0
|
|
|
|
|
|
|
|
|
|
var comm packer.Communicator
|
|
|
|
|
@ -146,6 +159,9 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, cancel <-chan stru
|
|
|
|
|
// We're using a bastion host, so use the bastion connfunc
|
|
|
|
|
connFunc = ssh.BastionConnectFunc(
|
|
|
|
|
bProto, bAddr, bConf, "tcp", address)
|
|
|
|
|
} else if pAddr != "" {
|
|
|
|
|
// Connect via SOCKS5 proxy
|
|
|
|
|
connFunc = ssh.ProxyConnectFunc(pAddr, pAuth, "tcp", address)
|
|
|
|
|
} else {
|
|
|
|
|
// No bastion host, connect directly
|
|
|
|
|
connFunc = ssh.ConnectFunc("tcp", address)
|
|
|
|
|
|