Skip to content

Commit

Permalink
Merge pull request #4323 from svanharmelen/f-ssh-agent-windows
Browse files Browse the repository at this point in the history
Add SSH agent support for Windows
  • Loading branch information
phinze committed Jan 6, 2016
2 parents 7a01653 + c72342e commit 0d3b862
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 9 additions & 9 deletions communicator/ssh/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/helper/pathorcontents"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/mapstructure"
"github.com/xanzy/ssh-agent"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
Expand Down Expand Up @@ -245,22 +246,17 @@ func connectToAgent(connInfo *connectionInfo) (*sshAgent, error) {
return nil, nil
}

sshAuthSock := os.Getenv("SSH_AUTH_SOCK")

if sshAuthSock == "" {
return nil, fmt.Errorf("SSH Requested but SSH_AUTH_SOCK not-specified")
}

conn, err := net.Dial("unix", sshAuthSock)
agent, conn, err := sshagent.New()
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
return &sshAgent{
agent: agent.NewClient(conn),
agent: agent,
conn: conn,
}, nil

}

// A tiny wrapper around an agent.Agent to expose the ability to close its
Expand All @@ -271,6 +267,10 @@ type sshAgent struct {
}

func (a *sshAgent) Close() error {
if a.conn == nil {
return nil
}

return a.conn.Close()
}

Expand Down
4 changes: 3 additions & 1 deletion website/source/docs/provisioners/connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ provisioner "file" {
function](/docs/configuration/interpolation.html#file_path_). This takes
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:**

Expand Down

0 comments on commit 0d3b862

Please sign in to comment.