Merge pull request #2560 from tiborvass/19.03-sshfix

[19.03] ssh: avoid setting flags through hostname
This commit is contained in:
Tibor Vass 2020-05-28 13:34:20 -07:00 committed by GitHub
commit 92b54c256a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View File

@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
}
return &ConnectionHelper{
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",
}, nil

View File

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

View File

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