From a6fba3ed55b69dae0992510798f746839f8d30e3 Mon Sep 17 00:00:00 2001 From: MaineK00n Date: Thu, 19 Jan 2023 02:55:04 +0900 Subject: [PATCH] fix(scanner): do not attach tty because there is no need to enter ssh password --- scanner/executil.go | 6 +++--- scanner/executil_test.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scanner/executil.go b/scanner/executil.go index 228c636a..0ce8bb24 100644 --- a/scanner/executil.go +++ b/scanner/executil.go @@ -185,7 +185,7 @@ func sshExecExternal(c config.ServerInfo, cmd string, sudo bool) (result execRes return execResult{Error: err} } - args := []string{"-tt"} + var args []string if c.SSHConfigPath != "" { args = append(args, "-F", c.SSHConfigPath) @@ -280,7 +280,7 @@ func dockerShell(family string) string { func decorateCmd(c config.ServerInfo, cmd string, sudo bool) string { if sudo && c.User != "root" && !c.IsContainer() { - cmd = fmt.Sprintf("sudo -S %s", cmd) + cmd = fmt.Sprintf("sudo %s", cmd) } // If you are using pipe and you want to detect preprocessing errors, remove comment out @@ -306,7 +306,7 @@ func decorateCmd(c config.ServerInfo, cmd string, sudo bool) string { c.Container.Name, dockerShell(c.Distro.Family), cmd) // LXC required root privilege if c.User != "root" { - cmd = fmt.Sprintf("sudo -S %s", cmd) + cmd = fmt.Sprintf("sudo %s", cmd) } } } diff --git a/scanner/executil_test.go b/scanner/executil_test.go index 4ed33b16..d7c70656 100644 --- a/scanner/executil_test.go +++ b/scanner/executil_test.go @@ -39,14 +39,14 @@ func TestDecorateCmd(t *testing.T) { conf: config.ServerInfo{User: "non-root"}, cmd: "ls", sudo: true, - expected: "sudo -S ls", + expected: "sudo ls", }, // non-root sudo true { conf: config.ServerInfo{User: "non-root"}, cmd: "ls | grep hoge", sudo: true, - expected: "sudo -S ls | grep hoge", + expected: "sudo ls | grep hoge", }, // -------------docker------------- // root sudo false docker @@ -192,7 +192,7 @@ func TestDecorateCmd(t *testing.T) { }, cmd: "ls", sudo: false, - expected: `sudo -S lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls'`, + expected: `sudo lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls'`, }, // non-root sudo true, lxc { @@ -203,7 +203,7 @@ func TestDecorateCmd(t *testing.T) { }, cmd: "ls", sudo: true, - expected: `sudo -S lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls'`, + expected: `sudo lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls'`, }, // non-root sudo true lxc { @@ -214,7 +214,7 @@ func TestDecorateCmd(t *testing.T) { }, cmd: "ls | grep hoge", sudo: true, - expected: `sudo -S lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls | grep hoge'`, + expected: `sudo lxc-attach -n def 2>/dev/null -- /bin/sh -c 'ls | grep hoge'`, }, }