key file is not used if other keys exist in ssh agent
- Dominant language
- Go
- Stars
- 53
- Forks
- 33
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 29
Description
While debugging a `k0sctl` issue, I found my specified `keyPath` for ssh is not used and ssh connection failed.
```yaml
spec:
hosts:
- ssh:
address: rocky9-0
keyPath: /home/docker/.ssh/id_ed25519
port: 22
user: root
...
```
To work around the issue, I had to manually add the key to ssh agent or unset `SSH_AUTH_SOCK` or clearing keys in ssh agent.
I reviewed `k0sproject/rig` codes and found the reason is that I have already had other ssh keys in SSH agent, and the specified ssh key file is configured as another `ssh.AuthMethod` in https://github.com/k0sproject/rig/blob/v0.19.0/ssh.go#L434 , so `ssh.ClientConfig.Auth` has two `AuthMethod`, both `method(`) is `publickey` , `golang.org/x/crypto/ssh client_auth.go` only tries the first one for the same auth method (https://cs.opensource.google/go/x/crypto/+/refs/tags/v0.29.0:ssh/client_auth.go;l=101), so the specified ssh key file is never used.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in ssh.go around line 434, where the SSH authentication methods are assembled, and compare that behavior with golang.org/x/crypto/ssh client_auth.go. Reproduce the case with keys already present in SSH_AUTH_SOCK and a separate keyPath. Done means the configured key file is tried successfully even when other public-key methods are available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100