communicator/ssh: expand user path for bastion private key

Signed-off-by: Mikhail Ushanov <gm.mephisto@gmail.com>
pull/6946/head
Mikhail Ushanov 8 years ago
parent 6d2a0ab0df
commit 1c503b86d9

@ -277,6 +277,18 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
if c.SSHBastionPassword == "" && c.SSHBastionPrivateKeyFile == "" {
errs = append(errs, errors.New(
"ssh_bastion_password or ssh_bastion_private_key_file must be specified"))
} else if c.SSHBastionPrivateKeyFile != "" {
path, err := homedir.Expand(c.SSHBastionPrivateKeyFile)
if err != nil {
errs = append(errs, fmt.Errorf(
"ssh_bastion_private_key_file is invalid: %s", err))
} else if _, err := os.Stat(path); err != nil {
errs = append(errs, fmt.Errorf(
"ssh_bastion_private_key_file is invalid: %s", err))
} else if _, err := helperssh.FileSigner(path); err != nil {
errs = append(errs, fmt.Errorf(
"ssh_bastion_private_key_file is invalid: %s", err))
}
}
}

@ -14,6 +14,7 @@ import (
"github.com/hashicorp/packer/helper/multistep"
helperssh "github.com/hashicorp/packer/helper/ssh"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/go-homedir"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/net/proxy"
@ -226,7 +227,12 @@ func sshBastionConfig(config *Config) (*gossh.ClientConfig, error) {
}
if config.SSHBastionPrivateKeyFile != "" {
signer, err := helperssh.FileSigner(config.SSHBastionPrivateKeyFile)
path, err := homedir.Expand(config.SSHBastionPrivateKeyFile)
if err != nil {
return nil, fmt.Errorf(
"Error expanding path for SSH bastion private key: %s", err)
}
signer, err := helperssh.FileSigner(path)
if err != nil {
return nil, err
}

Loading…
Cancel
Save