-
Notifications
You must be signed in to change notification settings - Fork 211
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
#335 Adding warning if a KMS key allows wildcarded principals in its policy #338
#335 Adding warning if a KMS key allows wildcarded principals in its policy #338
Conversation
# Select all key policy 'Statement' objects to audit | ||
violating_statements = key.keyPolicy['Statement'].select do |statement| | ||
# Add statement as violating if allowing wildcard principal | ||
statement['Principal'] == '*' && statement['Effect'] == 'Allow' |
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 believe {"AWS":"*"} is also legal and equivalent to "*"
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 call! Latest commit adds logic for that contingency and changes this to a failure instead of warning.
…s set to wildcard.
# Select all key policy 'Statement' objects to audit | ||
violating_statements = key.keyPolicy['Statement'].select do |statement| | ||
# Add statement as violating if allowing wildcard principal | ||
(statement['Principal'] == '*' || statement['Principal']['AWS'] == '*') && statement['Effect'] == 'Allow' |
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 was just thinking about this.... we may need to enhanced the logic around SQS and SNS. i believe the following is legal syntax:
"AWS": [
"aws:arn:us-east-1:111111111:user/foo",
"*"
]
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.
Yeah, we may need to make use of the parsing in cfn-model for principals. I believe that parsing (and the wildcard_principal
method) take the depth into account. Let's hold off merging this, and I'll start reworking this to use that model.
https://github.com/stelligent/cfn-model/blob/master/lib/cfn-model/model/principal.rb
…el from cfn-model and included tests for nested hash wildcard principal.
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.
need to bump the version of cfn-model for the policy object on kms key?
@erickascic Updated cfn-model version and validated with rubobop.
|
#335
Depends On
stelligent/cfn-model PR #58
Once the above PR is merged in cfn-model and a new gem artifact created, this PR will be able to execute.
Description
Adding a failure to catch KMS key policy principals with wildcard values.
Testing
Rspec test suite includes both positive and negative test cases from JSON templates, which pass while covering all relevant logic in the rule. Added YAML templates for integration testing as well.
Example rspec Output
Example Integration Test Output