Repository navigation
fix(aws): narrow the CloudFormation KMS key/* grant to another account's keys - #90
Closed
tim-thacker-nullify wants to merge 1 commit into
Closed
tim-thacker-nullify wants to merge 1 commit into
tim-thacker-nullify wants to merge 1 commit into
Conversation
…t's keys KMSAccessPolicy granted arn:<partition>:kms:<region>:<account>:key/* next to NullifyKMSKeyArn unconditionally, so a customer who pastes a key ARN from their own account handed the role every KMS key in that account and region. Terraform now derives the wildcard only when the ARN's account differs from the deploying account. - the policy is two statements: the supplied ARN always, and key/* in the ARN's account and region under StringNotEquals on aws:PrincipalAccount, which holds only when that account is not the one the stack is deployed into - the check is a request-time IAM condition, not a template Condition, because CloudFormation allows only Ref, Fn::FindInMap and other conditions inside Fn::Equals, so an account parsed out of the ARN with Fn::Select cannot be compared with AWS::AccountId at deploy time - a Nullify alias ARN keeps its key/* grant, which IAM needs because it never resolves an alias ARN for key operations - NullifyKMSKeyArn's description, the KMSPolicyResource output description and the template README describe the gate and why it is evaluated per request Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This was referenced Sep 15, 2026
fix(terraform): drop the unencrypted-upload opt-out and reject collector + managed scan together
#91
Closed
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KMSAccessPolicygrantedarn:<partition>:kms:<region>:<account>:key/*next toNullifyKMSKeyArnunconditionally, so a customer who pasted a key ARN from their own account handed the role every KMS key in that account and region. #89 narrows Terraform to derive the wildcard only when the ARN's account differs from the deploying account; this brings the CloudFormation template in line.key/*in the ARN's account and region underStringNotEqualsonaws:PrincipalAccountaws:PrincipalAccountis the account owning the role, always the deploying account, so the statement applies exactly when the ARN's account is not itNullifyKMSKeyArn's description, theKMSPolicyResourceoutput description and the template README describe the gateNot deploy-time parity
Terraform drops the wildcard from the policy document. CloudFormation cannot: condition functions accept only
Fn::FindInMap,Refand other condition functions, so theFn::Select/Fn::Splitthat parses the account out of the ARN cannot appear insideFn::Equals, and noConditioncan gate a statement or anFn::Ifresource list on it.AWS::LanguageExtensionsaddsFn::ForEach,Fn::LengthandFn::ToJsonStringonly.The wildcard resource therefore stays in the rendered document and is gated per request instead. Effective permissions match Terraform; the policy JSON does not.
Resulting grant
NullifyKMSKeyArn...:111122223333:alias/x, stack in999988887777)arn:aws:kms:<region>:111122223333:key/*...:111122223333:key/mrk-...)arn:aws:kms:<region>:111122223333:key/*...:999988887777:key/..., stack in999988887777)Unverified
cfn-lintjob is the check🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.