diff --git a/config.go b/config.go index 7d32a9a..04a67ae 100644 --- a/config.go +++ b/config.go @@ -53,11 +53,16 @@ func (c *Config) SetWorkerPool(numWorkers int) { } // SetSSHAuthSockAuth uses SSH_AUTH_SOCK environment variable to populate auth method in the SSH config. -func (c *Config) SetSSHAuthSockAuth() { +func (c *Config) SetSSHAuthSockAuth() error { // SSH_AUTH_SOCK contains the path of the unix socket that the agent uses for communication with other processes. - if SSHAuthSock, err := sshAuthSock(); err == nil { - c.SSHConfig.Auth = append(c.SSHConfig.Auth, SSHAuthSock) + SSHAuthSock, err := sshAuthSock() + if err != nil { + return err } + + c.SSHConfig.Auth = append(c.SSHConfig.Auth, SSHAuthSock) + + return nil } // Run executes the config, return a slice of Results once the command has exited @@ -129,11 +134,8 @@ func (c *Config) SetPublicKeyAuth(PublicKeyFile string, PublicKeyPassphrase stri return fmt.Errorf("unable to parse public key with passphrase: %s", err) } } - - - c.SSHConfig.Auth = []ssh.AuthMethod{ - ssh.PublicKeys(signer), - } + + c.SSHConfig.Auth = append(c.SSHConfig.Auth, ssh.PublicKeys(signer)) return nil } @@ -143,12 +145,8 @@ func (j *Job) SetCommand(command string) { } // SetPasswordAuth sets ssh password from provided byte slice (read from terminal) -func (c *Config) SetPasswordAuth(password []byte) error { - c.SSHConfig.Auth = []ssh.AuthMethod{ - ssh.Password(string(password)), - } - - return nil +func (c *Config) SetPasswordAuth(password []byte) { + c.SSHConfig.Auth = append(c.SSHConfig.Auth, ssh.Password(string(password))) } // SetLocalScript reads a script file contents into the Job config. diff --git a/session_test.go b/session_test.go index bebdcfe..f2a8dc2 100644 --- a/session_test.go +++ b/session_test.go @@ -148,7 +148,6 @@ func TestSshBastion(t *testing.T) { sshc := &ssh.ClientConfig{ User: testParams.User, - Auth: []ssh.AuthMethod{ssh.Password(testParams.Password)}, HostKeyCallback: ssh.InsecureIgnoreHostKey(), Timeout: time.Duration(2) * time.Second, } @@ -158,8 +157,9 @@ func TestSshBastion(t *testing.T) { SSHConfig: sshc, Job: j, WorkerPool: 10, - BastionHost: "192.168.1.120", + BastionHost: "192.168.1.121", } + cfg.SetPasswordAuth([]byte(testParams.Password)) // This should be the last responsibility from the massh package. Handling the Result channel is up to the user. res, err := cfg.Run()