X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1d80809a16fc97d7351824d2c921578133a93f65..10d70a1c08984a699ac3f6b893fe6d2141c5ad9e:/lib/dispatchcloud/ssh_executor/executor.go diff --git a/lib/dispatchcloud/ssh_executor/executor.go b/lib/dispatchcloud/ssh_executor/executor.go index d0fb54c54c..d608763cf5 100644 --- a/lib/dispatchcloud/ssh_executor/executor.go +++ b/lib/dispatchcloud/ssh_executor/executor.go @@ -38,6 +38,7 @@ func New(t cloud.ExecutorTarget) *Executor { type Executor struct { target cloud.ExecutorTarget targetPort string + targetUser string signers []ssh.Signer mtx sync.RWMutex // controls access to instance after creation @@ -172,24 +173,34 @@ func (exr *Executor) sshClient(create bool) (*ssh.Client, error) { return exr.client, exr.clientErr } -// Create a new SSH client. -func (exr *Executor) setupSSHClient() (*ssh.Client, error) { - target := exr.Target() - addr := target.Address() +func (exr *Executor) TargetHostPort() (string, string) { + addr := exr.Target().Address() if addr == "" { - return nil, errors.New("instance has no address") + return "", "" } - if h, p, err := net.SplitHostPort(addr); err != nil || p == "" { + h, p, err := net.SplitHostPort(addr) + if err != nil || p == "" { // Target address does not specify a port. Use // targetPort, or "ssh". + if h == "" { + h = addr + } if p = exr.targetPort; p == "" { p = "ssh" } - addr = net.JoinHostPort(h, p) + } + return h, p +} + +// Create a new SSH client. +func (exr *Executor) setupSSHClient() (*ssh.Client, error) { + addr := net.JoinHostPort(exr.TargetHostPort()) + if addr == ":" { + return nil, errors.New("instance has no address") } var receivedKey ssh.PublicKey client, err := ssh.Dial("tcp", addr, &ssh.ClientConfig{ - User: "root", + User: exr.Target().RemoteUser(), Auth: []ssh.AuthMethod{ ssh.PublicKeys(exr.signers...), }, @@ -206,7 +217,7 @@ func (exr *Executor) setupSSHClient() (*ssh.Client, error) { } if exr.hostKey == nil || !bytes.Equal(exr.hostKey.Marshal(), receivedKey.Marshal()) { - err = target.VerifyHostKey(receivedKey, client) + err = exr.Target().VerifyHostKey(receivedKey, client) if err != nil { return nil, err }