Skip to content
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

sshprovider: on Windows, ModeSocket might not be set on the ssh socket #1695

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion session/sshforward/sshprovider/agentprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"net"
"os"
"runtime"
"strings"
"time"

"github.com/moby/buildkit/session"
Expand Down Expand Up @@ -139,7 +141,7 @@ func toAgentSource(paths []string) (source, error) {
socket = p
continue
}
keys = true

f, err := os.Open(p)
if err != nil {
return source{}, errors.Wrapf(err, "failed to open %s", p)
Expand All @@ -151,11 +153,24 @@ func toAgentSource(paths []string) (source, error) {

k, err := ssh.ParseRawPrivateKey(dt)
if err != nil {
// On Windows, os.ModeSocket isn't appropriately set on the file mode.
// https://github.com/golang/go/issues/33357
// If parsing the file fails, check to see if it kind of looks like socket-shaped.
if runtime.GOOS == "windows" && strings.Contains(string(dt), "socket") {
if keys {
return source{}, errors.Errorf("invalid combination of keys and sockets")
}
socket = p
continue
}

return source{}, errors.Wrapf(err, "failed to parse %s", p) // TODO: prompt passphrase?
}
if err := a.Add(agent.AddedKey{PrivateKey: k}); err != nil {
return source{}, errors.Wrapf(err, "failed to add %s to agent", p)
}

keys = true
}

if socket != "" {
Expand Down
21 changes: 21 additions & 0 deletions session/sshforward/sshprovider/agentprovider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package sshprovider_test

import (
"strings"
"testing"

"github.com/moby/buildkit/cmd/buildctl/build"
"github.com/moby/buildkit/session/sshforward/sshprovider"
)

func TestToAgentSource(t *testing.T) {
configs, err := build.ParseSSH([]string{"default"})
if err != nil {
t.Fatal(err)
}
_, err = sshprovider.NewSSHAgentProvider(configs)
ok := err == nil || strings.Contains(err.Error(), "invalid empty ssh agent socket")
if !ok {
t.Fatal(err)
}
}