Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 32055c3

Browse files
authored
Merge pull request #70 from codercom/ssh-auth-sock
Pass in SSH_AUTH_SOCK if it exists
2 parents 1aa6d07 + 8d83d1e commit 32055c3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

runner.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,16 @@ func (r *runner) runContainer(image string) error {
8888
cmd = r.testCmd + "; exit 1"
8989
}
9090

91+
var envs []string
92+
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
93+
if exists {
94+
s := fmt.Sprintf("SSH_AUTH_SOCK=%s", sshAuthSock)
95+
envs = append(envs, s)
96+
}
97+
9198
containerConfig := &container.Config{
9299
Hostname: r.hostname,
100+
Env: envs,
93101
Cmd: strslice.StrSlice{
94102
"bash", "-c", cmd,
95103
},
@@ -143,6 +151,19 @@ func (r *runner) mounts(mounts []mount.Mount, image string) ([]mount.Mount, erro
143151
Target: "~/.vscode/extensions",
144152
})
145153

154+
// 'SSH_AUTH_SOCK' is provided by a running ssh-agent. Passing in the
155+
// socket to the container allows for using the user's existing setup for
156+
// ssh authentication instead of having to create a new keys or explicity
157+
// pass them in.
158+
sshAuthSock, exists := os.LookupEnv("SSH_AUTH_SOCK")
159+
if exists {
160+
mounts = append(mounts, mount.Mount{
161+
Type: "bind",
162+
Source: sshAuthSock,
163+
Target: sshAuthSock,
164+
})
165+
}
166+
146167
localGlobalStorageDir := filepath.Join(metaRoot(), r.cntName, "globalStorage")
147168
err := os.MkdirAll(localGlobalStorageDir, 0750)
148169
if err != nil {

0 commit comments

Comments
 (0)