builder/scaleway: support ssh agent authentication
This commit is contained in:
parent
1f7c32db98
commit
22b12432db
|
@ -2,10 +2,13 @@ package scaleway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
packerssh "github.com/hashicorp/packer/communicator/ssh"
|
packerssh "github.com/hashicorp/packer/communicator/ssh"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
|
"golang.org/x/crypto/ssh/agent"
|
||||||
)
|
)
|
||||||
|
|
||||||
func commHost(state multistep.StateBag) (string, error) {
|
func commHost(state multistep.StateBag) (string, error) {
|
||||||
|
@ -19,12 +22,27 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
|
||||||
|
|
||||||
var auth []ssh.AuthMethod
|
var auth []ssh.AuthMethod
|
||||||
|
|
||||||
if config.Comm.SSHPassword != "" {
|
if config.Comm.SSHAgentAuth {
|
||||||
|
authSock := os.Getenv("SSH_AUTH_SOCK")
|
||||||
|
if authSock == "" {
|
||||||
|
return nil, fmt.Errorf("SSH_AUTH_SOCK is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
sshAgent, err := net.Dial("unix", authSock)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Cannot connect to SSH Agent socket %q: %s", authSock, err)
|
||||||
|
}
|
||||||
auth = []ssh.AuthMethod{
|
auth = []ssh.AuthMethod{
|
||||||
|
ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Comm.SSHPassword != "" {
|
||||||
|
auth = append(auth,
|
||||||
ssh.Password(config.Comm.SSHPassword),
|
ssh.Password(config.Comm.SSHPassword),
|
||||||
ssh.KeyboardInteractive(
|
ssh.KeyboardInteractive(
|
||||||
packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
|
packerssh.PasswordKeyboardInteractive(config.Comm.SSHPassword)),
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Comm.SSHPrivateKey != "" {
|
if config.Comm.SSHPrivateKey != "" {
|
||||||
|
|
Loading…
Reference in New Issue