gruntwork-io / terratest

Terratest is a Go library that makes it easier to write automated tests for your infrastructure code.
https://terratest.gruntwork.io/
Apache License 2.0
7.49k stars 1.32k forks source link

RSA Key Problem with OpenSSH v8.x #1170

Open juan-castrillon opened 2 years ago

juan-castrillon commented 2 years ago

Hello terratest team. First of all thank you for a great tool!

Similar to the issue here I've running into some issues when trying to SSH into a machine in AWS with Ubuntu 22.04

I create a key pair with keyPair := aws.CreateAndImportEC2KeyPair(t, AwsRegion, keyPairName) and pass it to the ssh command like this :

host := ssh.Host{
  Hostname:    publicIP,
  SshKeyPair:  keyPair,
  SshUserName: "ubuntu",
  CustomPort:  portNumber,
}
// Try until SSH connection can be established
maxRetries := 20
timeBetweenRetries := 5 * time.Second
time.Sleep(1 * time.Minute)
err = ssh.CheckSshConnectionWithRetryE(t, host, maxRetries, timeBetweenRetries)
if err != nil {
  return "", err
}

However, I keep running into the following error:

returned an error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain.

After some digging, it seems to be a problem identified within the x/crypto/ssh package from the stdlib (See https://github.com/golang/go/issues/49952). Apparently RSA keys are no longer supported by default. which seems to already have an available fix

This would require however the update of the dependency in terratest's go.mod file.

Let me know if you need any more information of my use case, or anything I can help with.

Thanks in advance :)

bob-rohan commented 1 year ago

I ran into this today as well, can confirm the above analysis matches my findings. I tested with replace golang.org/x/crypto => golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd and can confirm this version fixes issue.