forked from toolshed/abra
fix: attempt to include IdentityFile if available
This is part of trying to debug: coop-cloud/organising#250 And also part of: coop-cloud/docs.coopcloud.tech#27 Where I now try to specify the same logic as `ssh -i <my-key-path>` in the underlying connection logic. This should help with being more explicit about what key is being used via the SSH config file.
This commit is contained in:
@ -2,6 +2,7 @@ package commandconn
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
|
||||
@ -34,9 +35,25 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*connhelper.Conne
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "ssh host connection is not valid")
|
||||
}
|
||||
|
||||
if err := sshPkg.EnsureHostKey(ctxConnDetails.Host); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hostConfig, err := sshPkg.GetHostConfig(
|
||||
ctxConnDetails.Host,
|
||||
ctxConnDetails.User,
|
||||
ctxConnDetails.Port,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if hostConfig.IdentityFile != "" {
|
||||
msg := "discovered %s as identity file for %s, using for ssh connection"
|
||||
logrus.Debugf(msg, hostConfig.IdentityFile, ctxConnDetails.Host)
|
||||
sshFlags = append(sshFlags, fmt.Sprintf("-o IdentityFile=%s", hostConfig.IdentityFile))
|
||||
}
|
||||
|
||||
return &connhelper.ConnectionHelper{
|
||||
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return New(ctx, "ssh", append(sshFlags, ctxConnDetails.Args("docker", "system", "dial-stdio")...)...)
|
||||
|
Reference in New Issue
Block a user