fix: change ControlPath to .vuls of SSH option (#618)
This commit is contained in:
8
Gopkg.lock
generated
8
Gopkg.lock
generated
@@ -264,6 +264,12 @@
|
||||
packages = ["."]
|
||||
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/go-homedir"
|
||||
packages = ["."]
|
||||
revision = "b8bc1bf767474819792c23f32d8286a45736f1c6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/moul/http2curl"
|
||||
@@ -377,6 +383,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "1a43293a9ffc91270316199bec5474167594f96a3612f899842532c0f224d694"
|
||||
inputs-digest = "17ca5502a80ae70140ecf819a5b2757898b42deca821221afebce63488b691ea"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
||||
@@ -107,3 +107,7 @@
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/go-homedir"
|
||||
|
||||
@@ -45,6 +45,7 @@ type ConfigtestCmd struct {
|
||||
deep bool
|
||||
|
||||
debug bool
|
||||
vvv bool
|
||||
}
|
||||
|
||||
// Name return subcommand name
|
||||
@@ -68,6 +69,7 @@ func (*ConfigtestCmd) Usage() string {
|
||||
[-containers-only]
|
||||
[-http-proxy=http://192.168.0.1:8080]
|
||||
[-debug]
|
||||
[-vvv]
|
||||
|
||||
[SERVER]...
|
||||
`
|
||||
@@ -125,6 +127,8 @@ func (p *ConfigtestCmd) SetFlags(f *flag.FlagSet) {
|
||||
"containers-only",
|
||||
false,
|
||||
"Test containers only. Default: Test both of hosts and containers")
|
||||
|
||||
f.BoolVar(&p.vvv, "vvv", false, "ssh -vvv")
|
||||
}
|
||||
|
||||
// Execute execute
|
||||
@@ -134,6 +138,11 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
|
||||
c.Conf.LogDir = p.logDir
|
||||
util.Log = util.NewCustomLogger(c.ServerInfo{})
|
||||
|
||||
if err := mkdirDotVuls(); err != nil {
|
||||
util.Log.Errorf("Failed to create .vuls: %s", err)
|
||||
return subcommands.ExitUsageError
|
||||
}
|
||||
|
||||
var keyPass string
|
||||
var err error
|
||||
if p.askKeyPassword {
|
||||
@@ -161,6 +170,7 @@ func (p *ConfigtestCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfa
|
||||
if !(c.Conf.Fast || c.Conf.Offline || c.Conf.Deep) {
|
||||
c.Conf.Fast = true
|
||||
}
|
||||
c.Conf.Vvv = p.vvv
|
||||
|
||||
var servernames []string
|
||||
if 0 < len(f.Args()) {
|
||||
|
||||
@@ -188,6 +188,11 @@ func (p *ScanCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{})
|
||||
c.Conf.LogDir = p.logDir
|
||||
util.Log = util.NewCustomLogger(c.ServerInfo{})
|
||||
|
||||
if err := mkdirDotVuls(); err != nil {
|
||||
util.Log.Errorf("Failed to create .vuls: %s", err)
|
||||
return subcommands.ExitUsageError
|
||||
}
|
||||
|
||||
var keyPass string
|
||||
var err error
|
||||
if p.askKeyPassword {
|
||||
|
||||
@@ -19,8 +19,11 @@ package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/howeyc/gopass"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
)
|
||||
|
||||
func getPasswd(prompt string) (string, error) {
|
||||
@@ -36,3 +39,17 @@ func getPasswd(prompt string) (string, error) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func mkdirDotVuls() error {
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dotVuls := filepath.Join(home, ".vuls")
|
||||
if _, err := os.Stat(dotVuls); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(dotVuls, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
ex "os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -36,6 +37,7 @@ import (
|
||||
"github.com/cenkalti/backoff"
|
||||
conf "github.com/future-architect/vuls/config"
|
||||
"github.com/future-architect/vuls/util"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -269,6 +271,15 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul
|
||||
return sshExecNative(c, cmd, sudo)
|
||||
}
|
||||
|
||||
home, err := homedir.Dir()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Failed to get HOME directory: %s", err)
|
||||
result.Stderr = msg
|
||||
result.ExitStatus = 997
|
||||
return
|
||||
}
|
||||
controlPath := filepath.Join(home, ".vuls", `controlmaster-%r-%h.%p`)
|
||||
|
||||
defaultSSHArgs := []string{
|
||||
"-tt",
|
||||
"-o", "StrictHostKeyChecking=yes",
|
||||
@@ -276,7 +287,7 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul
|
||||
"-o", "ConnectionAttempts=3",
|
||||
"-o", "ConnectTimeout=10",
|
||||
"-o", "ControlMaster=auto",
|
||||
"-o", `ControlPath=~/.ssh/controlmaster-%r-%h.%p`,
|
||||
"-o", fmt.Sprintf("ControlPath=%s", controlPath),
|
||||
"-o", "Controlpersist=10m",
|
||||
}
|
||||
if conf.Conf.Vvv {
|
||||
|
||||
Reference in New Issue
Block a user