-
Notifications
You must be signed in to change notification settings - Fork 47
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 ability to restrict which accounts can work with stacks #283
Conversation
This adds the ability to specify stack defaults and override it for a specific stack.
@@ -0,0 +1,23 @@ | |||
module StackMaster | |||
class Identity | |||
def running_in_allowed_account?(allowed_accounts) |
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.
Seems odd to pass a nil
or empty
variable to a function.
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.
Maybe if nil
was the default value for allowed_accounts (in StackDefinition, indicating unspecified) the expected values would either be nil
or an array of account IDs
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.
Good idea. Done in b30dede.
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 good 👍
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.
This looks good.
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.
Code looks good, I'm curious about the tests though...
README.md
Outdated
|
||
This is an opt-in feature which is enabled by specifying at least one account to allow. | ||
|
||
Unlike other stack defaults, `allowed_accounts` values specified in the stack definition override values in the stack defaults instead of merging them together. This allows specifying allowed accounts in the stack defaults for all stacks and still have different values for specific stacks. See below example config for an example. |
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.
From just reading this I'm still not entirely sure what the behaviour will be. Does it allow applying myapp-db
to account 555555555
or not?
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.
No it doesn't as the account IDs specified in the stack definition overrides the stack defaults.
I've reworded this section and example stack below. Let me know if it clarifies things.
See 4233345.
|
||
def region | ||
@region ||= ENV['AWS_REGION'] || Aws.config[:region] || Aws.shared_config.region || 'us-east-1' | ||
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.
This method isn't necessary. If we don't specify a region the SDK does a lookup for us automatically.
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.
You're right it does, however I added this method to ensure that a default region is used if it couldn't find a region from the environment. It's also the same as the CloudFormation driver class except for the default value.
This was me being more defensive, but happy to remove it if you think it'll be fine without it?
end | ||
|
||
after do | ||
StackMaster.reset_flags |
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 spec_helper already handles this
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.
It doesn't handle this. The cucumber features do though.
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.
Right you are
us-east-1 | stack2 | UPDATE_COMPLETE | Yes | ||
* No echo parameters can't be diffed | ||
OUTPUT | ||
expect { status.perform }.to output(out).to_stdout |
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.
Shouldn't this test expect an error to be returned? If the account IDs don't match it shouldn't print the status?
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.
It's a got a special case now: Disallowed account | N/A
.
It would not be great if it threw an error just because one stack is unavailable.
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.
What @viraptor said.
Alternatively, I could leave them blank instead? I didn't go with that option because I thought it would be better to let the user know why no status is included for that stack.
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.
Another option is to include SKIPPED
for the status field and Disallowed account
for different field.
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.
Right I see. Are we able to have an integration test for when someone runs stack_master apply
on a stack in the wrong account then? I thought that's what this was doing, but I didn't read the spec name 😆
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.
Good idea. Added integration tests in f02603c.
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.
Thanks
In order to provide extra safety and reduce the risk of applying non-production changes to production, this PR adds the ability to specify which accounts are allowed to work with specific stacks.
The behaviour can be summarised using the following example stack_master.yml file:
Changes
allowed_accounts
stack definition property that lists the aws account IDs allowed to work with the stack--skip-account-check
flag to bypass the account checks