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

Add support for specifying SSH key type to be generated #583

Merged
merged 2 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/kitchen/driver/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Ec2 < Kitchen::Driver::Base
default_config :aws_secret_access_key, nil
default_config :aws_session_token, nil
default_config :aws_ssh_key_id, ENV["AWS_SSH_KEY_ID"]
default_config :aws_ssh_key_type, "rsa"
default_config :image_id, &:default_ami
default_config :image_search, nil
default_config :username, nil
Expand Down Expand Up @@ -830,7 +831,7 @@ def create_key(state)
# to rapidly exhaust local entropy by creating a lot of keys. So this is
# probably fine. If you want very high security, probably don't use this
# feature anyway.
resp = ec2.client.create_key_pair(key_name: "kitchen-#{name_parts.join("-")}")
resp = ec2.client.create_key_pair(key_name: "kitchen-#{name_parts.join("-")}", key_type: config[:aws_ssh_key_type])
state[:auto_key_id] = resp.key_name
info("Created automatic key pair #{state[:auto_key_id]}")
# Write the key out with safe permissions
Expand Down
2 changes: 1 addition & 1 deletion spec/kitchen/driver/ec2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
config.delete(:aws_ssh_key_id)
allow(instance).to receive(:name).and_return("instance_name")

expect(actual_client).to receive(:create_key_pair).with(key_name: /kitchen-/).and_return(double(key_name: "expected-key-name", key_material: "RSA PRIVATE KEY"))
expect(actual_client).to receive(:create_key_pair).with(key_name: /kitchen-/, key_type: "rsa").and_return(double(key_name: "expected-key-name", key_material: "RSA PRIVATE KEY"))
fake_file = double
allow(File).to receive(:open).and_call_original
expect(File).to receive(:open).with("/kitchen/.kitchen/instance_name.pem", kind_of(Numeric), kind_of(Numeric)).and_yield(fake_file)
Expand Down