Skip to content

Commit 4c51516

Browse files
committed
Add SSH_AUTH_SOCK support to Windows environments.
- Presently dialing Windows SSH agents respects the SSH_AUTH_SOCK environment variable only if step cli is run in specific Unix-like environments (i.e. cygwin). If defined, the agent specified at SSH_AUTH_SOCK will be dialed through a unix pipe with `net.Dial`. In a full Windows environment, the SSH_AUTH_SOCK variable is ignored and the default OpenSSH Agent pipe is dialed instead. - But some Windows agents (like Pageant) may open Named Pipes at arbitrary paths. - This commit adds support for SSH_AUTH_SOCK in a full Windows Context. So, if SSH_AUTH_SOCK is defined, the agent specified at SSH_AUTH_SOCK will be dialed through the Windows Named Pipe with winio.DialPipeContext. If SSH_AUTH_SOCK is not specified (or blank), the default `\\.\\pipe\\openssh-ssh-agent` will be dialed instead.
1 parent af579f3 commit 4c51516

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

internal/sshutil/agent_windows.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@ import (
1313
// dialAgent returns an ssh.Agent client. It uses the SSH_AUTH_SOCK to connect
1414
// to the agent.
1515
func dialAgent() (*Agent, error) {
16-
// Attempt unix sockets for environments like cygwin.
16+
// Override the default windows openssh-ssh-agent pipe
1717
if socket := os.Getenv("SSH_AUTH_SOCK"); socket != "" {
18+
// Attempt unix sockets for environments like cygwin.
1819
if conn, err := net.Dial("unix", socket); err == nil {
1920
return &Agent{
2021
ExtendedAgent: agent.NewClient(conn),
2122
Conn: conn,
2223
}, nil
2324
}
25+
26+
// Connect to Windows pipe at the supplied address
27+
conn, err := winio.DialPipeContext(context.Background(), socket)
28+
if err != nil {
29+
return nil, errors.Wrap(err, "error connecting with ssh-agent at pipe specified by environment variable SSH_AUTH_SOCK")
30+
}
31+
return &Agent{
32+
ExtendedAgent: agent.NewClient(conn),
33+
Conn: conn,
34+
}, nil
2435
}
2536

26-
// Windows OpenSSH agent
37+
// DEFAULT: Windows OpenSSH agent
2738
conn, err := winio.DialPipeContext(context.Background(), `\\.\\pipe\\openssh-ssh-agent`)
2839
if err != nil {
2940
return nil, errors.Wrap(err, "error connecting with ssh-agent")

0 commit comments

Comments
 (0)