-
Notifications
You must be signed in to change notification settings - Fork 42
Add support for specifying account aliases in the allowed_accounts stack definition property #325
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
Changes from all commits
0763ce8
bf4d5fc
9bccba9
417e7ff
55a4b3d
d41a82d
205a2b1
ca3e60c
bb773ab
6061e54
1fc44b7
b476736
8a528b7
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 |
|---|---|---|
| @@ -1,16 +1,25 @@ | ||
| module StackMaster | ||
| class Identity | ||
| def running_in_allowed_account?(allowed_accounts) | ||
| allowed_accounts.nil? || allowed_accounts.empty? || allowed_accounts.include?(account) | ||
| MissingIamPermissionsError = Class.new(StandardError) | ||
|
|
||
| def running_in_account?(accounts) | ||
| accounts.nil? || | ||
| accounts.empty? || | ||
| contains_account_id?(accounts) || | ||
| contains_account_alias?(accounts) | ||
| end | ||
|
|
||
| def account | ||
| @account ||= sts.get_caller_identity.account | ||
| end | ||
|
|
||
| private | ||
| def account_aliases | ||
| @aliases ||= iam.list_account_aliases.account_aliases | ||
|
Member
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. With the addition of this new API call, I'm assuming StackMaster requires additional permissions. Perhaps we should document this in the changelog.
Contributor
Author
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. Added in 1fc44b7. |
||
| rescue Aws::IAM::Errors::AccessDenied | ||
| raise MissingIamPermissionsError, 'Failed to retrieve account aliases. Missing required IAM permission: iam:ListAccountAliases' | ||
| end | ||
|
|
||
| attr_reader :sts | ||
| private | ||
|
|
||
| def region | ||
| @region ||= ENV['AWS_REGION'] || Aws.config[:region] || Aws.shared_config.region || 'us-east-1' | ||
|
|
@@ -19,5 +28,17 @@ def region | |
| def sts | ||
| @sts ||= Aws::STS::Client.new(region: region) | ||
| end | ||
|
|
||
| def iam | ||
| @iam ||= Aws::IAM::Client.new(region: region) | ||
| end | ||
|
|
||
| def contains_account_id?(ids) | ||
| ids.include?(account) | ||
| end | ||
|
|
||
| def contains_account_alias?(aliases) | ||
| account_aliases.any? { |account_alias| aliases.include?(account_alias) } | ||
|
Member
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. Perhaps this should only be checked (and the API call made) if the provided values look like aliases, ie. they're not numbers.
Contributor
Author
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 thought about this too, but the problem with this approach is that it only covers the case where the check is performed, not when the error message is being generated in the cli.rb file. I think the way to cover all cases is to rescue the permissions error in the
Member
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. 👍 Let's do that. |
||
| end | ||
| end | ||
| end | ||
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.
❤️