Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 9c610e0

Browse files
authored
Merge pull request #2560 from tiborvass/19.03-sshfix
[19.03] ssh: avoid setting flags through hostname Upstream-commit: 92b54c256a0e2bda0da63dc85d51b7185a2114d7 Component: cli
2 parents 1721a7c + 8c9977e commit 9c610e0

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

components/cli/cli/connhelper/connhelper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func GetConnectionHelper(daemonURL string) (*ConnectionHelper, error) {
3434
}
3535
return &ConnectionHelper{
3636
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
37-
return commandconn.New(ctx, "ssh", append(sp.Args(), []string{"--", "docker", "system", "dial-stdio"}...)...)
37+
return commandconn.New(ctx, "ssh", sp.Args("docker", "system", "dial-stdio")...)
3838
},
3939
Host: "http://docker",
4040
}, nil

components/cli/cli/connhelper/ssh/ssh.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ type Spec struct {
4949
Port string
5050
}
5151

52-
// Args returns args except "ssh" itself and "-- ..."
53-
func (sp *Spec) Args() []string {
52+
// Args returns args except "ssh" itself combined with optional additional command args
53+
func (sp *Spec) Args(add ...string) []string {
5454
var args []string
5555
if sp.User != "" {
5656
args = append(args, "-l", sp.User)
5757
}
5858
if sp.Port != "" {
5959
args = append(args, "-p", sp.Port)
6060
}
61-
args = append(args, sp.Host)
61+
args = append(args, "--", sp.Host)
62+
args = append(args, add...)
6263
return args
6364
}

components/cli/cli/connhelper/ssh/ssh_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ func TestParseURL(t *testing.T) {
1616
{
1717
url: "ssh://foo",
1818
expectedArgs: []string{
19-
"foo",
19+
"--", "foo",
2020
},
2121
},
2222
{
2323
url: "ssh://me@foo:10022",
2424
expectedArgs: []string{
2525
"-l", "me",
2626
"-p", "10022",
27-
"foo",
27+
"--", "foo",
2828
},
2929
},
3030
{
@@ -53,12 +53,14 @@ func TestParseURL(t *testing.T) {
5353
},
5454
}
5555
for _, tc := range testCases {
56-
sp, err := ParseURL(tc.url)
57-
if tc.expectedError == "" {
58-
assert.NilError(t, err)
59-
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
60-
} else {
61-
assert.ErrorContains(t, err, tc.expectedError)
62-
}
56+
t.Run(tc.url, func(t *testing.T) {
57+
sp, err := ParseURL(tc.url)
58+
if tc.expectedError == "" {
59+
assert.NilError(t, err)
60+
assert.Check(t, is.DeepEqual(tc.expectedArgs, sp.Args()))
61+
} else {
62+
assert.ErrorContains(t, err, tc.expectedError)
63+
}
64+
})
6365
}
6466
}

0 commit comments

Comments
 (0)