Skip to content

Commit 54b74f7

Browse files
committed
feat: Add SSH agent forwarding support to coder agent
1 parent 34b1e19 commit 54b74f7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

agent/agent.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ func (a *agent) handleSSHSession(session ssh.Session) error {
380380
return err
381381
}
382382

383+
if ssh.AgentRequested(session) {
384+
l, err := ssh.NewAgentListener()
385+
if err != nil {
386+
return xerrors.Errorf("new agent listener: %w", err)
387+
}
388+
defer l.Close()
389+
go ssh.ForwardAgentConnections(l, session)
390+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", "SSH_AUTH_SOCK", l.Addr().String()))
391+
}
392+
383393
sshPty, windowSize, isPty := session.Pty()
384394
if isPty {
385395
cmd.Env = append(cmd.Env, fmt.Sprintf("TERM=%s", sshPty.Term))

0 commit comments

Comments
 (0)