Add support for SSH Key Authentication with ESX builder

This commit is contained in:
michael 2015-11-03 19:08:35 -08:00
parent 70e7e953b1
commit 499bd5a362
3 changed files with 13 additions and 1 deletions

View File

@ -57,6 +57,7 @@ type Config struct {
RemotePort uint `mapstructure:"remote_port"`
RemoteUser string `mapstructure:"remote_username"`
RemotePassword string `mapstructure:"remote_password"`
RemotePrivateKey string `mapstructure:"remote_private_key_file"`
ctx interpolate.Context
}

View File

@ -21,6 +21,7 @@ func NewDriver(config *Config) (vmwcommon.Driver, error) {
Port: config.RemotePort,
Username: config.RemoteUser,
Password: config.RemotePassword,
PrivateKey: config.RemotePrivateKey,
Datastore: config.RemoteDatastore,
CacheDatastore: config.RemoteCacheDatastore,
CacheDirectory: config.RemoteCacheDirectory,

View File

@ -15,6 +15,7 @@ import (
"time"
"github.com/mitchellh/multistep"
commonssh "github.com/mitchellh/packer/common/ssh"
"github.com/mitchellh/packer/communicator/ssh"
"github.com/mitchellh/packer/packer"
gossh "golang.org/x/crypto/ssh"
@ -27,6 +28,7 @@ type ESX5Driver struct {
Port uint
Username string
Password string
PrivateKey string
Datastore string
CacheDatastore string
CacheDirectory string
@ -340,7 +342,15 @@ func (d *ESX5Driver) connect() error {
ssh.PasswordKeyboardInteractive(d.Password)),
}
// TODO(dougm) KeyPath support
if d.PrivateKey != "" {
signer, err := commonssh.FileSigner(d.PrivateKey)
if err != nil {
return err
}
auth = append(auth, gossh.PublicKeys(signer))
}
sshConfig := &ssh.Config{
Connection: ssh.ConnectFunc("tcp", address),
SSHConfig: &gossh.ClientConfig{