Add SSH agent support for Windows
The Windows support is limited to the Pageant SSH authentication agent. This fixes #3423
This commit is contained in:
parent
e842ad33d6
commit
c72342eefc
|
@ -11,6 +11,7 @@ import (
|
||||||
"github.com/hashicorp/terraform/helper/pathorcontents"
|
"github.com/hashicorp/terraform/helper/pathorcontents"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
"github.com/xanzy/ssh-agent"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"golang.org/x/crypto/ssh/agent"
|
"golang.org/x/crypto/ssh/agent"
|
||||||
)
|
)
|
||||||
|
@ -245,22 +246,17 @@ func connectToAgent(connInfo *connectionInfo) (*sshAgent, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sshAuthSock := os.Getenv("SSH_AUTH_SOCK")
|
agent, conn, err := sshagent.New()
|
||||||
|
|
||||||
if sshAuthSock == "" {
|
|
||||||
return nil, fmt.Errorf("SSH Requested but SSH_AUTH_SOCK not-specified")
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := net.Dial("unix", sshAuthSock)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error connecting to SSH_AUTH_SOCK: %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// connection close is handled over in Communicator
|
// connection close is handled over in Communicator
|
||||||
return &sshAgent{
|
return &sshAgent{
|
||||||
agent: agent.NewClient(conn),
|
agent: agent,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A tiny wrapper around an agent.Agent to expose the ability to close its
|
// A tiny wrapper around an agent.Agent to expose the ability to close its
|
||||||
|
@ -271,6 +267,10 @@ type sshAgent struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *sshAgent) Close() error {
|
func (a *sshAgent) Close() error {
|
||||||
|
if a.conn == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return a.conn.Close()
|
return a.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,9 @@ provisioner "file" {
|
||||||
function](/docs/configuration/interpolation.html#file_path_). This takes
|
function](/docs/configuration/interpolation.html#file_path_). This takes
|
||||||
preference over the password if provided.
|
preference over the password if provided.
|
||||||
|
|
||||||
* `agent` - Set to false to disable using ssh-agent to authenticate.
|
* `agent` - Set to false to disable using ssh-agent to authenticate. On Windows the
|
||||||
|
only supported SSH authentication agent is
|
||||||
|
[Pageant](http://the.earth.li/~sgtatham/putty/0.66/htmldoc/Chapter9.html#pageant)
|
||||||
|
|
||||||
**Additional arguments only supported by the "winrm" connection type:**
|
**Additional arguments only supported by the "winrm" connection type:**
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue