projects
/
arvados.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
15107: Fix redirect target rewriting.
[arvados.git]
/
lib
/
dispatchcloud
/
ssh_executor
/
executor.go
diff --git
a/lib/dispatchcloud/ssh_executor/executor.go
b/lib/dispatchcloud/ssh_executor/executor.go
index d0fb54c54cd932df806e0129a0f92d78cd3a9999..d608763cf5100d46ca0b1cb2b50a6759a157b1e3 100644
(file)
--- 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
type Executor struct {
target cloud.ExecutorTarget
targetPort string
+ targetUser string
signers []ssh.Signer
mtx sync.RWMutex // controls access to instance after creation
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
}
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 == "" {
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".
// Target address does not specify a port. Use
// targetPort, or "ssh".
+ if h == "" {
+ h = addr
+ }
if p = exr.targetPort; p == "" {
p = "ssh"
}
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{
}
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...),
},
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()) {
}
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
}
if err != nil {
return nil, err
}