-
Notifications
You must be signed in to change notification settings - Fork 202
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 explicit option for using iam profile for authentication #107
Changes from 5 commits
69d4f41
4b12e1b
adc082d
389522c
aaaa892
1945879
9853526
770557e
f13c073
d352cb4
40ce055
e1d5ae4
16302ab
ac3d1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,7 @@ module Driver | |
# | ||
# @author Fletcher Nichol <[email protected]> | ||
class Ec2 < Kitchen::Driver::SSHBase | ||
|
||
extend Fog::AWS::CredentialFetcher::ServiceMethods | ||
include Fog::AWS::CredentialFetcher::ServiceMethods | ||
default_config :region, 'us-east-1' | ||
default_config :availability_zone, 'us-east-1b' | ||
default_config :flavor_id, 'm1.small' | ||
|
@@ -42,13 +41,14 @@ class Ec2 < Kitchen::Driver::SSHBase | |
default_config :iam_profile_name, nil | ||
default_config :price, nil | ||
default_config :aws_access_key_id do |driver| | ||
ENV['AWS_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY_ID'] || iam_creds[:aws_access_key_id] | ||
ENV['AWS_ACCESS_KEY'] || ENV['AWS_ACCESS_KEY_ID'] || driver.iam_creds[:aws_access_key_id] | ||
end | ||
default_config :aws_secret_access_key do |driver| | ||
ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY'] || iam_creds[:aws_secret_access_key] | ||
ENV['AWS_SECRET_KEY'] || ENV['AWS_SECRET_ACCESS_KEY'] || | ||
driver.iam_creds[:aws_secret_access_key] | ||
end | ||
default_config :aws_session_token do |driver| | ||
ENV['AWS_SESSION_TOKEN'] || ENV['AWS_TOKEN'] || iam_creds[:aws_session_token] | ||
driver.default_aws_session_token | ||
end | ||
default_config :aws_ssh_key_id do |driver| | ||
ENV['AWS_SSH_KEY_ID'] | ||
|
@@ -98,10 +98,10 @@ class Ec2 < Kitchen::Driver::SSHBase | |
end | ||
end | ||
|
||
def self.iam_creds | ||
def iam_creds | ||
@iam_creds ||= begin | ||
fetch_credentials(use_iam_profile:true) | ||
rescue RuntimeError => e | ||
fetch_credentials(use_iam_profile: true) | ||
rescue RuntimeError, NoMethodError => e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still have the same question about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://github.com/fog/fog-aws/blob/master/lib/fog/aws/credential_fetcher.rb#L27 fetch_credentials will always call super if it fails There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NM, I was able to reproduce the error from https://github.com/test-kitchen/kitchen-ec2/pull/104/files locally and I see why you have the |
||
debug("fetch_credentials failed with exception #{e.message}:#{e.backtrace.join("\n")}") | ||
{} | ||
end | ||
|
@@ -167,6 +167,15 @@ def default_public_ip_association | |
!!config[:subnet_id] | ||
end | ||
|
||
def default_aws_session_token | ||
if config[:aws_secret_access_key] == iam_creds[:aws_secret_access_key] \ | ||
&& config[:aws_access_key_id] == iam_creds[:aws_access_key_id] | ||
iam_creds[:aws_session_token] | ||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the user required to specify the same access key / secret as returned by the iam_creds query? If they have to do that, why not just use the provided access key / secret for authentication? I thought the primary point of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I'm just checking that config[:aws_secret_access_key] et all had fallen back to the iam_creds statement so that we know it would be logical to return the iam_creds[:aws_session_token] since our other config values are from iam. |
||
ENV['AWS_SESSION_TOKEN'] || ENV['AWS_TOKEN'] | ||
end | ||
end | ||
|
||
private | ||
|
||
def connection | ||
|
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.
Where do you expect the
NoMethodError
to come from?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.
fetch_credentials calls super when it fails, so since we don't have a super for it to fail over to we need to catch NoMethodError, I think I made a note in the commit message.