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

How to load SSH key-pair from the filesystem? #170

Open sw-samuraj opened 6 years ago

sw-samuraj commented 6 years ago

Question: I went through the examples and ssh package source code, but I didn't find a function for loading of existing SSH keys/key-pair. All the scenarios are about:

  1. generating of a key-pair,
  2. importing of the key-pair to AWS,
  3. temporary saving of the key-pair for later use,
  4. loading of the saved key-pair,
  5. some tests,
  6. deleting of the key-pair.

I'm missing a function which just performs key-pair loading, but not from the transient test data, but from the "real" keys stored somewhere on the filesystem.

brikis98 commented 6 years ago

Hahah, your timing is impeccable. We had just discussed a little while back how nice it would be if Terratest, when running locally, or perhaps when some env var was set, would import your existing public key (i.e., from ~/.ssh/id_rsa.pub) into AWS, rather than creating a totally new one. That way, if a test failed, you could SSH to the relevant resources with your regular SSH key, which is probably already in ssh-agent. A PR for that is most welcome 😄

sw-samuraj commented 6 years ago

With that goes another question - as I understand from the source code, all the private keys are unencrypted, right? Would be nice to be able to work with encrypted keys as well.

brikis98 commented 6 years ago

Ah, that's a good point. Not sure the best way to handle that. Interactively asking for a password could be a weird user experience. Perhaps providing the password via env var? Or is there some way to get the encrypted key from ssh-agent?

sw-samuraj commented 5 years ago

I'll try to sketch a first draft and then discuss/develop it further.