-
Notifications
You must be signed in to change notification settings - Fork 119
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
Enable temporary_key_pair_type option for ed25519 #179
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far, as you pointed out there isn't a great place to test this currently,
@nywilken and I are going to make some changes to the key_pair step code to make it easier to test, the refactor to allow us to mock the ec2Connection seems a bit complicated for a first time contributor, we will update you here once we have merged those changes so you can write a test.
I tested your changes locally and they worked on my end for setting the key
We will also need to update the docs here https://github.com/hashicorp/packer/blob/master/website/content/partials/packer-plugin-sdk/communicator/SSHTemporaryKeyPair-not-required.mdx but we can handle that ourselves once we have your PR merged.
Thank you so much for this contribution, we'll get back to you soon!
builder/common/run_config.go
Outdated
@@ -601,6 +601,9 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error { | |||
c.Comm.SSHPrivateKeyFile == "" && c.Comm.SSHPassword == "" { | |||
|
|||
c.Comm.SSHTemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) | |||
if c.Comm.SSHTemporaryKeyPairType != "ed25519" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this defaulting makes sense sense the AWS docs here https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateKeyPair.html specify that that ed25519 is not supported on several instances
@@ -64,6 +64,7 @@ func (s *StepKeyPair) Run(ctx context.Context, state multistep.StateBag) multist | |||
ui.Say(fmt.Sprintf("Creating temporary keypair: %s", s.Comm.SSHTemporaryKeyPairName)) | |||
keypair := &ec2.CreateKeyPairInput{ | |||
KeyName: &s.Comm.SSHTemporaryKeyPairName, | |||
KeyType: &s.Comm.SSHTemporaryKeyPairType, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that was the issue!
Wasn't really sure what to do with the docs. The option is already documented even though it hadn't been implemented and has fewer actual options than shown. The docs are generic so there is stuff there that doesn't apply to AWS. Thanks for working on the unit tests. Will keep an eye out for that when it's ready :) |
Introduce a unit test and acceptance test for the key pair step, validating that an ssh key name is respected, and that its type is RSA, adding these tests to help with #179 Co-authored-by: Jenna Goldstrich <[email protected]> Co-authored-by: Wilken Rivera <[email protected]>
Hey @wedge-jarrad, I just merged #181 which @nywilken and I worked on to add a unit test and an acceptance test for the keypair step. So you'll need to rebase your PR on top of that. For unit tests you should be able to un-comment the extra lines in this test
For acceptance tests if you'd like you can add a duplicate of this test
make testacc , or to run a single test, like the RSA one, you could run PACKER_ACC=1 go test -count=1 -v ./... -run='TestAccBuilder_EbsKeyPair' --timeout=120m
One other small change I'd recommend is to edit the run_config to include a check that the SSH Key type is rsa, or ed25519, and throw an error if its not one of those types, and then add a corresponding unit test. Here is an example of a validator in the run config that checks the value of a field
We can handle the docs change if you'd like. I know this is a bit long so, feel free to let us know if there's any of that you'd like help on/are confused on! |
Default to "rsa" if not given. Error if a value other than "rsa" or "ed25519" is given.
26a2f3b
to
52a16e8
Compare
Ok, I think that's everything. Let me know if I've missed anything. And thank you for taking the time to guide me through this :) Acceptance tests:
Unit tests:
|
Looks fantastic to me, excellent contribution @wedge-jarrad, merging! |
Super nice ! |
Thanks for taking care of this @wedge-jarrad! |
Not sure if I'm doing something wrong, but I now see that my local private key is ssh-keygen -l
...
256 SHA256:.... (ED25519) Default ssh user's authorized_keys ssh-rsa AAAAB3NzaC1yc2... packer_62.... Feels like there is a mismatch here? |
Okay, to the point of this PR - it works great, thank you! I was finally able to verify. Building on my comment above, I'm not sure where to go but I'm building an AMI on top of another packer-built AMI. It turns out that the public ssh key from the first Packer run is still in the |
Hi, would it please be possible to fix this for the OpenStack builder as well? See hashicorp/packer-plugin-openstack#54. |
Allow Packer to create ed25519 keys as the temporary SSH keypair by setting the
temporary_key_pair_type
option. Defaults to rsa.This is my first foray into the Packer code so I have no idea what I'm doing :D. Feel free to boss me around a bit if there are better ways to go about this, particularly the way the input is validated/defaulted.
I only spent a little bit of time looking at the tests but it wasn't immediately obvious to me how to incorporate this in the tests. Might have some more time to look a bit harder tomorrow (pointers appreciated!). I did, however, test manually and it seems to work. If you specify
temporary_key_pair_type = "ed25519"
you get an ed25519 keypair. Any other value or omission oftemporary_key_pair_type
results in an rsa keypair.Closes #144
Relates hashicorp/packer#10074