Skip to content

Add SSH_AUTH_SOCK support to Windows environments. #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions internal/sshutil/agent_windows.go
Original file line number Diff line number Diff line change
@@ -13,17 +13,28 @@ import (
// dialAgent returns an ssh.Agent client. It uses the SSH_AUTH_SOCK to connect
// to the agent.
func dialAgent() (*Agent, error) {
// Attempt unix sockets for environments like cygwin.
// Override the default windows openssh-ssh-agent pipe
if socket := os.Getenv("SSH_AUTH_SOCK"); socket != "" {
// Attempt unix sockets for environments like cygwin.
if conn, err := net.Dial("unix", socket); err == nil {
return &Agent{
ExtendedAgent: agent.NewClient(conn),
Conn: conn,
}, nil
}

// Connect to Windows pipe at the supplied address
conn, err := winio.DialPipeContext(context.Background(), socket)
if err != nil {
return nil, errors.Wrap(err, "error connecting with ssh-agent at pipe specified by environment variable SSH_AUTH_SOCK")
}
return &Agent{
ExtendedAgent: agent.NewClient(conn),
Conn: conn,
}, nil
}

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