ssh: avoid setting flags through hostname

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2020-05-18 11:12:52 -07:00 committed by Tibor Vass
parent 263bb539f6
commit d30970e3b1
3 changed files with 16 additions and 13 deletions

View File

@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
} }
return &ConnectionHelper{ return &ConnectionHelper{
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) { Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...) return commandconn.New(ctx, "ssh", sp.Args("docker", "system", "dial-stdio")...)
}, },
Host: "http://docker", Host: "http://docker",
}, nil }, nil

View File

@ -49,8 +49,8 @@ type Spec struct {
Port string Port string
} }
// Args returns args except "ssh" itself and "-- ..." // Args returns args except "ssh" itself combined with optional additional command args
func (sp *Spec) Args() []string { func (sp *Spec) Args(add ...string) []string {
var args []string var args []string
if sp.User != "" { if sp.User != "" {
args = append(args, "-l", sp.User) args = append(args, "-l", sp.User)
@ -58,6 +58,7 @@ func (sp *Spec) Args() []string {
if sp.Port != "" { if sp.Port != "" {
args = append(args, "-p", sp.Port) args = append(args, "-p", sp.Port)
} }
args = append(args, sp.Host) args = append(args, "--", sp.Host)
args = append(args, add...)
return args return args
} }

View File

@ -16,7 +16,7 @@ func TestParseURL(t *testing.T) {
{ {
url: "ssh://foo", url: "ssh://foo",
expectedArgs: []string{ expectedArgs: []string{
"foo", "--", "foo",
}, },
}, },
{ {
@ -24,7 +24,7 @@ func TestParseURL(t *testing.T) {
expectedArgs: []string{ expectedArgs: []string{
"-l", "me", "-l", "me",
"-p", "10022", "-p", "10022",
"foo", "--", "foo",
}, },
}, },
{ {
@ -53,6 +53,7 @@ func TestParseURL(t *testing.T) {
}, },
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.url, func(t *testing.T) {
sp, err := ParseURL(tc.url) sp, err := ParseURL(tc.url)
if tc.expectedError == "" { if tc.expectedError == "" {
assert.NilError(t, err) assert.NilError(t, err)
@ -60,5 +61,6 @@ func TestParseURL(t *testing.T) {
} else { } else {
assert.ErrorContains(t, err, tc.expectedError) assert.ErrorContains(t, err, tc.expectedError)
} }
})
} }
} }