Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit c72342e

Browse files
author
Sander van Harmelen
committed
Add SSH agent support for Windows
The Windows support is limited to the Pageant SSH authentication agent. This fixes hashicorp#3423
1 parent e842ad3 commit c72342e

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

communicator/ssh/provisioner.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/hashicorp/terraform/helper/pathorcontents"
1212
"github.com/hashicorp/terraform/terraform"
1313
"github.com/mitchellh/mapstructure"
14+
"github.com/xanzy/ssh-agent"
1415
"golang.org/x/crypto/ssh"
1516
"golang.org/x/crypto/ssh/agent"
1617
)
@@ -245,22 +246,17 @@ func connectToAgent(connInfo *connectionInfo) (*sshAgent, error) {
245246
return nil, nil
246247
}
247248

248-
sshAuthSock := os.Getenv("SSH_AUTH_SOCK")
249-
250-
if sshAuthSock == "" {
251-
return nil, fmt.Errorf("SSH Requested but SSH_AUTH_SOCK not-specified")
252-
}
253-
254-
conn, err := net.Dial("unix", sshAuthSock)
249+
agent, conn, err := sshagent.New()
255250
if err != nil {
256-
return nil, fmt.Errorf("Error connecting to SSH_AUTH_SOCK: %v", err)
251+
return nil, err
257252
}
258253

259254
// connection close is handled over in Communicator
260255
return &sshAgent{
261-
agent: agent.NewClient(conn),
256+
agent: agent,
262257
conn: conn,
263258
}, nil
259+
264260
}
265261

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

273269
func (a *sshAgent) Close() error {
270+
if a.conn == nil {
271+
return nil
272+
}
273+
274274
return a.conn.Close()
275275
}
276276

website/source/docs/provisioners/connection.html.markdown

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ provisioner "file" {
7373
function](/docs/configuration/interpolation.html#file_path_). This takes
7474
preference over the password if provided.
7575

76-
* `agent` - Set to false to disable using ssh-agent to authenticate.
76+
* `agent` - Set to false to disable using ssh-agent to authenticate. On Windows the
77+
only supported SSH authentication agent is
78+
[Pageant](http://the.earth.li/~sgtatham/putty/0.66/htmldoc/Chapter9.html#pageant)
7779

7880
**Additional arguments only supported by the "winrm" connection type:**
7981

0 commit comments

Comments
 (0)