Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Load ssh keys from home dir as a final ssh fallback #877

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imilchev
Copy link
Member

@imilchev imilchev commented Feb 2, 2023

The last resort for loading ssh keys at the moment was ssh-agent. However, if that loads no keys then we stop. This PR also attempts to load the keys located in ~/.ssh (if they exist).

Signed-off-by: Ivan Milchev <ivan@mondoo.com>
@@ -201,14 +204,48 @@ func prepareConnection(pCfg *providers.Config) ([]ssh.AuthMethod, []io.Closer, e
}
}

if len(sshSigners) > 0 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this below loading the ssh-agent certs since anything that is appended to sshSigners after that is simply ignored. I feel like this was a bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be correct here. The ssh agents authentication is activated in the cli if the user has not provided anything. Therefore we can remove the fallback to ssh-agent here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this code is not needed at all then?

// if no credential was provided, fallback to ssh-agent and ssh-config
if len(pCfg.Credentials) == 0 {
sshSigners = append(sshSigners, signers.GetSignersFromSSHAgent()...)
}

// If no keys were loaded so far, then attempt loading the default keys in the home directory
if len(sshSigners) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is adding more implicit behavior. We should add a new credential type for ssh config and only load it when the credential type is set. The cli behaviour should stay implicit and therefore we need to add ssh_config and ssh_agent as default there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure whether ssh_config makes sense as a name. This is just using your default ssh settings for your user.

@@ -201,14 +204,48 @@ func prepareConnection(pCfg *providers.Config) ([]ssh.AuthMethod, []io.Closer, e
}
}

if len(sshSigners) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be correct here. The ssh agents authentication is activated in the cli if the user has not provided anything. Therefore we can remove the fallback to ssh-agent here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants