Skip to content

Commit

Permalink
Append auth method (#11)
Browse files Browse the repository at this point in the history
* Updated Config.SetPublicKeyAuth to accept a passphrase.

* Updated CHANGELOG

* Updated config auth funcs to append rather than replace.
  • Loading branch information
DiscoRiver authored Sep 19, 2021
1 parent c81115a commit 7ebe5ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
26 changes: 12 additions & 14 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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()
Expand Down

0 comments on commit 7ebe5ba

Please sign in to comment.