From 8186387b6151c1ad56c6b9a8a7a9cb83047b46d9 Mon Sep 17 00:00:00 2001 From: 9547 Date: Tue, 6 Jul 2021 15:11:29 +0800 Subject: [PATCH] cluster/ssh: don't quote ssh options (#1469) --- pkg/cluster/executor/ssh.go | 4 +++- pkg/cluster/executor/ssh_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/executor/ssh.go b/pkg/cluster/executor/ssh.go index 4b2a755e1f..82cc8778fc 100644 --- a/pkg/cluster/executor/ssh.go +++ b/pkg/cluster/executor/ssh.go @@ -261,7 +261,9 @@ func (e *NativeSSHExecutor) configArgs(args []string, isScp bool) []string { proxyArgs = append([]string{"sshpass", "-p", proxy.Passphrase, "-P", e.prompt("passphrase")}, proxyArgs...) } } - args = append(args, []string{"-o", fmt.Sprintf(`ProxyCommand="%s %s@%s -p %d -W %%h:%%p"`, strings.Join(proxyArgs, " "), proxy.User, proxy.Host, proxy.Port)}...) + // Don't need to extra quote it, exec.Command will handle it right + // ref https://stackoverflow.com/a/26473771/2298986 + args = append(args, []string{"-o", fmt.Sprintf(`ProxyCommand=%s %s@%s -p %d -W %%h:%%p`, strings.Join(proxyArgs, " "), proxy.User, proxy.Host, proxy.Port)}...) } return args } diff --git a/pkg/cluster/executor/ssh_test.go b/pkg/cluster/executor/ssh_test.go index c90753ae3b..6104ad5022 100644 --- a/pkg/cluster/executor/ssh_test.go +++ b/pkg/cluster/executor/ssh_test.go @@ -92,7 +92,7 @@ func TestNativeSSHConfigArgs(t *testing.T) { }, }, false, - `-o ConnectTimeout=60 -i id_rsa -o ProxyCommand="ssh -i b.id_rsa root@proxy1 -p 222 -W %h:%p"`, + "-o ConnectTimeout=60 -i id_rsa -o ProxyCommand=ssh -i b.id_rsa root@proxy1 -p 222 -W %h:%p", }, { &SSHConfig{ @@ -108,7 +108,7 @@ func TestNativeSSHConfigArgs(t *testing.T) { }, }, false, - `-p 1203 -o ConnectTimeout=60 -i id_rsa -o ProxyCommand="ssh -o ConnectTimeout=10 -i b.id_rsa root@proxy1 -p 222 -W %h:%p"`, + "-p 1203 -o ConnectTimeout=60 -i id_rsa -o ProxyCommand=ssh -o ConnectTimeout=10 -i b.id_rsa root@proxy1 -p 222 -W %h:%p", }, { &SSHConfig{ @@ -123,7 +123,7 @@ func TestNativeSSHConfigArgs(t *testing.T) { }, }, false, - `sshpass -p pass -P password -o ConnectTimeout=60 -o ProxyCommand="sshpass -p word -P password ssh -o ConnectTimeout=10 root@proxy1 -p 222 -W %h:%p"`, + "sshpass -p pass -P password -o ConnectTimeout=60 -o ProxyCommand=sshpass -p word -P password ssh -o ConnectTimeout=10 root@proxy1 -p 222 -W %h:%p", }, }