fix: log what keys are loaded with the ssh-agent
continuous-integration/drone/push Build is passing Details

Closes coop-cloud/organising#249.
This commit is contained in:
decentral1se 2021-11-18 20:04:57 +01:00
parent cc37615d83
commit 56c3e070f5
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 20 additions and 1 deletions

View File

@ -409,12 +409,31 @@ func connect(username, host, port string, authMethod ssh.AuthMethod, timeout tim
}
func connectWithAgentTimeout(host, username, port string, timeout time.Duration) (*Client, error) {
logrus.Debugf("using ssh-agent to make an SSH connection for %s", host)
sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
if err != nil {
return nil, err
}
authMethod := ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers)
agentCl := agent.NewClient(sshAgent)
authMethod := ssh.PublicKeysCallback(agentCl.Signers)
loadedKeys, err := agentCl.List()
if err != nil {
return nil, err
}
var convertedKeys []string
for _, key := range loadedKeys {
convertedKeys = append(convertedKeys, key.String())
}
if len(convertedKeys) > 0 {
logrus.Debugf("ssh-agent has these keys loaded: %s", strings.Join(convertedKeys, ","))
} else {
logrus.Debug("ssh-agent has no keys loaded")
}
return connect(username, host, port, authMethod, timeout)
}