Skip to content

Commit 399dacf

Browse files
committed
sshprovider: on Windows, ModeSocket might not be set on the ssh socket
Fixes #914 Signed-off-by: Nick Santos <[email protected]>
1 parent b0a3ab1 commit 399dacf

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

session/sshforward/sshprovider/agentprovider.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"io/ioutil"
77
"net"
88
"os"
9+
"runtime"
10+
"strings"
911
"time"
1012

1113
"github.com/moby/buildkit/session"
@@ -139,7 +141,7 @@ func toAgentSource(paths []string) (source, error) {
139141
socket = p
140142
continue
141143
}
142-
keys = true
144+
143145
f, err := os.Open(p)
144146
if err != nil {
145147
return source{}, errors.Wrapf(err, "failed to open %s", p)
@@ -151,11 +153,24 @@ func toAgentSource(paths []string) (source, error) {
151153

152154
k, err := ssh.ParseRawPrivateKey(dt)
153155
if err != nil {
156+
// On Windows, os.ModeSocket isn't appropriately set on the file mode.
157+
// https://github.com/golang/go/issues/33357
158+
// If parsing the file fails, check to see if it kind of looks like socket-shaped.
159+
if runtime.GOOS == "windows" && strings.Contains(string(dt), "socket") {
160+
if keys {
161+
return source{}, errors.Errorf("invalid combination of keys and sockets")
162+
}
163+
socket = p
164+
continue
165+
}
166+
154167
return source{}, errors.Wrapf(err, "failed to parse %s", p) // TODO: prompt passphrase?
155168
}
156169
if err := a.Add(agent.AddedKey{PrivateKey: k}); err != nil {
157170
return source{}, errors.Wrapf(err, "failed to add %s to agent", p)
158171
}
172+
173+
keys = true
159174
}
160175

161176
if socket != "" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package sshprovider_test
2+
3+
import (
4+
"strings"
5+
"testing"
6+
7+
"github.com/moby/buildkit/cmd/buildctl/build"
8+
"github.com/moby/buildkit/session/sshforward/sshprovider"
9+
)
10+
11+
func TestToAgentSource(t *testing.T) {
12+
configs, err := build.ParseSSH([]string{"default"})
13+
if err != nil {
14+
t.Fatal(err)
15+
}
16+
_, err = sshprovider.NewSSHAgentProvider(configs)
17+
ok := err == nil || strings.Contains(err.Error(), "invalid empty ssh agent socket")
18+
if !ok {
19+
t.Fatal(err)
20+
}
21+
}

0 commit comments

Comments
 (0)