-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
[Enhancement]: Check for duplicate keys in IAM policy JSON arguments #33570
Conversation
Community NoteVoting for Prioritization
For Submitters
|
ac40af5
to
ae3b44b
Compare
ae3b44b
to
bcfaf6d
Compare
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.
LGTM 🚀.
% make testacc TESTARGS='-run=TestAccIAMPolicy_\|TestAccIAMRole_\|TestAccIAMRolePolicy_\|TestAccIAMGroupPolicy_\|TESTS=TestAccIAMUserPolicy_' PKG=iam ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/iam/... -v -count 1 -parallel 2 -run=TestAccIAMPolicy_\|TestAccIAMRole_\|TestAccIAMRolePolicy_\|TestAccIAMGroupPolicy_\|TESTS=TestAccIAMUserPolicy_ -timeout 360m
=== RUN TestAccIAMGroupPolicy_basic
=== PAUSE TestAccIAMGroupPolicy_basic
=== RUN TestAccIAMGroupPolicy_disappears
=== PAUSE TestAccIAMGroupPolicy_disappears
=== RUN TestAccIAMGroupPolicy_namePrefix
=== PAUSE TestAccIAMGroupPolicy_namePrefix
=== RUN TestAccIAMGroupPolicy_generatedName
=== PAUSE TestAccIAMGroupPolicy_generatedName
=== RUN TestAccIAMGroupPolicy_unknownsInPolicy
=== PAUSE TestAccIAMGroupPolicy_unknownsInPolicy
=== RUN TestAccIAMPolicy_basic
=== PAUSE TestAccIAMPolicy_basic
=== RUN TestAccIAMPolicy_description
=== PAUSE TestAccIAMPolicy_description
=== RUN TestAccIAMPolicy_tags
=== PAUSE TestAccIAMPolicy_tags
=== RUN TestAccIAMPolicy_disappears
=== PAUSE TestAccIAMPolicy_disappears
=== RUN TestAccIAMPolicy_namePrefix
=== PAUSE TestAccIAMPolicy_namePrefix
=== RUN TestAccIAMPolicy_path
=== PAUSE TestAccIAMPolicy_path
=== RUN TestAccIAMPolicy_policy
=== PAUSE TestAccIAMPolicy_policy
=== RUN TestAccIAMPolicy_diffs
=== PAUSE TestAccIAMPolicy_diffs
=== RUN TestAccIAMPolicy_policyDuplicateKeys
=== PAUSE TestAccIAMPolicy_policyDuplicateKeys
=== RUN TestAccIAMRolePolicy_basic
=== PAUSE TestAccIAMRolePolicy_basic
=== RUN TestAccIAMRolePolicy_disappears
=== PAUSE TestAccIAMRolePolicy_disappears
=== RUN TestAccIAMRolePolicy_policyOrder
=== PAUSE TestAccIAMRolePolicy_policyOrder
=== RUN TestAccIAMRolePolicy_namePrefix
=== PAUSE TestAccIAMRolePolicy_namePrefix
=== RUN TestAccIAMRolePolicy_generatedName
=== PAUSE TestAccIAMRolePolicy_generatedName
=== RUN TestAccIAMRolePolicy_invalidJSON
=== PAUSE TestAccIAMRolePolicy_invalidJSON
=== RUN TestAccIAMRolePolicy_Policy_invalidResource
=== PAUSE TestAccIAMRolePolicy_Policy_invalidResource
=== RUN TestAccIAMRolePolicy_unknownsInPolicy
=== PAUSE TestAccIAMRolePolicy_unknownsInPolicy
=== RUN TestAccIAMRole_basic
=== PAUSE TestAccIAMRole_basic
=== RUN TestAccIAMRole_description
=== PAUSE TestAccIAMRole_description
=== RUN TestAccIAMRole_nameGenerated
=== PAUSE TestAccIAMRole_nameGenerated
=== RUN TestAccIAMRole_namePrefix
=== PAUSE TestAccIAMRole_namePrefix
=== RUN TestAccIAMRole_testNameChange
=== PAUSE TestAccIAMRole_testNameChange
=== RUN TestAccIAMRole_diffs
=== PAUSE TestAccIAMRole_diffs
=== RUN TestAccIAMRole_diffsCondition
=== PAUSE TestAccIAMRole_diffsCondition
=== RUN TestAccIAMRole_badJSON
=== PAUSE TestAccIAMRole_badJSON
=== RUN TestAccIAMRole_disappears
=== PAUSE TestAccIAMRole_disappears
=== RUN TestAccIAMRole_policiesForceDetach
=== PAUSE TestAccIAMRole_policiesForceDetach
=== RUN TestAccIAMRole_maxSessionDuration
=== PAUSE TestAccIAMRole_maxSessionDuration
=== RUN TestAccIAMRole_permissionsBoundary
=== PAUSE TestAccIAMRole_permissionsBoundary
=== RUN TestAccIAMRole_tags
=== PAUSE TestAccIAMRole_tags
=== RUN TestAccIAMRole_InlinePolicy_basic
=== PAUSE TestAccIAMRole_InlinePolicy_basic
=== RUN TestAccIAMRole_InlinePolicy_ignoreOrder
=== PAUSE TestAccIAMRole_InlinePolicy_ignoreOrder
=== RUN TestAccIAMRole_InlinePolicy_empty
=== PAUSE TestAccIAMRole_InlinePolicy_empty
=== RUN TestAccIAMRole_ManagedPolicy_basic
=== PAUSE TestAccIAMRole_ManagedPolicy_basic
=== RUN TestAccIAMRole_ManagedPolicy_outOfBandRemovalAddedBack
=== PAUSE TestAccIAMRole_ManagedPolicy_outOfBandRemovalAddedBack
=== RUN TestAccIAMRole_InlinePolicy_outOfBandRemovalAddedBack
=== PAUSE TestAccIAMRole_InlinePolicy_outOfBandRemovalAddedBack
=== RUN TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemoved
=== PAUSE TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemoved
=== RUN TestAccIAMRole_InlinePolicy_outOfBandAdditionRemoved
=== PAUSE TestAccIAMRole_InlinePolicy_outOfBandAdditionRemoved
=== RUN TestAccIAMRole_InlinePolicy_outOfBandAdditionIgnored
=== PAUSE TestAccIAMRole_InlinePolicy_outOfBandAdditionIgnored
=== RUN TestAccIAMRole_ManagedPolicy_outOfBandAdditionIgnored
=== PAUSE TestAccIAMRole_ManagedPolicy_outOfBandAdditionIgnored
=== RUN TestAccIAMRole_InlinePolicy_outOfBandAdditionRemovedEmpty
=== PAUSE TestAccIAMRole_InlinePolicy_outOfBandAdditionRemovedEmpty
=== RUN TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemovedEmpty
=== PAUSE TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemovedEmpty
=== CONT TestAccIAMGroupPolicy_basic
=== CONT TestAccIAMRole_nameGenerated
--- PASS: TestAccIAMRole_nameGenerated (24.61s)
=== CONT TestAccIAMRole_InlinePolicy_ignoreOrder
--- PASS: TestAccIAMGroupPolicy_basic (52.67s)
=== CONT TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemovedEmpty
--- PASS: TestAccIAMRole_InlinePolicy_ignoreOrder (59.25s)
=== CONT TestAccIAMRole_InlinePolicy_outOfBandAdditionRemovedEmpty
--- PASS: TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemovedEmpty (38.43s)
=== CONT TestAccIAMRole_ManagedPolicy_outOfBandAdditionIgnored
--- PASS: TestAccIAMRole_InlinePolicy_outOfBandAdditionRemovedEmpty (40.53s)
=== CONT TestAccIAMRole_InlinePolicy_outOfBandAdditionIgnored
--- PASS: TestAccIAMRole_ManagedPolicy_outOfBandAdditionIgnored (38.25s)
=== CONT TestAccIAMRole_InlinePolicy_outOfBandAdditionRemoved
--- PASS: TestAccIAMRole_InlinePolicy_outOfBandAdditionRemoved (36.99s)
=== CONT TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemoved
--- PASS: TestAccIAMRole_InlinePolicy_outOfBandAdditionIgnored (54.63s)
=== CONT TestAccIAMRole_InlinePolicy_outOfBandRemovalAddedBack
--- PASS: TestAccIAMRole_ManagedPolicy_outOfBandAdditionRemoved (38.33s)
=== CONT TestAccIAMRole_ManagedPolicy_outOfBandRemovalAddedBack
--- PASS: TestAccIAMRole_InlinePolicy_outOfBandRemovalAddedBack (37.40s)
=== CONT TestAccIAMRole_ManagedPolicy_basic
--- PASS: TestAccIAMRole_ManagedPolicy_outOfBandRemovalAddedBack (38.84s)
=== CONT TestAccIAMRole_InlinePolicy_empty
--- PASS: TestAccIAMRole_InlinePolicy_empty (21.40s)
=== CONT TestAccIAMPolicy_diffs
--- PASS: TestAccIAMRole_ManagedPolicy_basic (60.58s)
=== CONT TestAccIAMRole_description
--- PASS: TestAccIAMRole_description (57.23s)
=== CONT TestAccIAMRole_basic
--- PASS: TestAccIAMRole_basic (23.89s)
=== CONT TestAccIAMRolePolicy_unknownsInPolicy
--- PASS: TestAccIAMRolePolicy_unknownsInPolicy (25.97s)
=== CONT TestAccIAMRolePolicy_Policy_invalidResource
--- PASS: TestAccIAMRolePolicy_Policy_invalidResource (12.02s)
=== CONT TestAccIAMRolePolicy_invalidJSON
--- PASS: TestAccIAMRolePolicy_invalidJSON (2.22s)
=== CONT TestAccIAMRolePolicy_generatedName
--- PASS: TestAccIAMPolicy_diffs (166.40s)
=== CONT TestAccIAMRolePolicy_namePrefix
--- PASS: TestAccIAMRolePolicy_generatedName (42.99s)
=== CONT TestAccIAMRolePolicy_policyOrder
--- PASS: TestAccIAMRolePolicy_policyOrder (32.11s)
=== CONT TestAccIAMRolePolicy_disappears
--- PASS: TestAccIAMRolePolicy_namePrefix (46.62s)
=== CONT TestAccIAMRolePolicy_basic
--- PASS: TestAccIAMRolePolicy_disappears (25.99s)
=== CONT TestAccIAMPolicy_policyDuplicateKeys
--- PASS: TestAccIAMPolicy_policyDuplicateKeys (2.81s)
=== CONT TestAccIAMPolicy_description
--- PASS: TestAccIAMRolePolicy_basic (47.98s)
=== CONT TestAccIAMPolicy_policy
--- PASS: TestAccIAMPolicy_description (25.66s)
=== CONT TestAccIAMPolicy_path
--- PASS: TestAccIAMPolicy_path (23.95s)
=== CONT TestAccIAMPolicy_namePrefix
--- PASS: TestAccIAMPolicy_policy (41.84s)
=== CONT TestAccIAMPolicy_disappears
--- PASS: TestAccIAMPolicy_namePrefix (23.78s)
=== CONT TestAccIAMPolicy_tags
--- PASS: TestAccIAMPolicy_disappears (18.24s)
=== CONT TestAccIAMGroupPolicy_generatedName
--- PASS: TestAccIAMGroupPolicy_generatedName (41.23s)
=== CONT TestAccIAMPolicy_basic
--- PASS: TestAccIAMPolicy_tags (59.58s)
=== CONT TestAccIAMGroupPolicy_unknownsInPolicy
--- PASS: TestAccIAMPolicy_basic (24.13s)
=== CONT TestAccIAMGroupPolicy_namePrefix
--- PASS: TestAccIAMGroupPolicy_unknownsInPolicy (25.71s)
=== CONT TestAccIAMGroupPolicy_disappears
--- PASS: TestAccIAMGroupPolicy_disappears (20.23s)
=== CONT TestAccIAMRole_disappears
--- PASS: TestAccIAMGroupPolicy_namePrefix (39.07s)
=== CONT TestAccIAMRole_InlinePolicy_basic
--- PASS: TestAccIAMRole_disappears (19.21s)
=== CONT TestAccIAMRole_tags
--- PASS: TestAccIAMRole_tags (39.77s)
=== CONT TestAccIAMRole_permissionsBoundary
--- PASS: TestAccIAMRole_InlinePolicy_basic (57.17s)
=== CONT TestAccIAMRole_maxSessionDuration
--- PASS: TestAccIAMRole_maxSessionDuration (46.54s)
=== CONT TestAccIAMRole_policiesForceDetach
--- PASS: TestAccIAMRole_policiesForceDetach (24.62s)
=== CONT TestAccIAMRole_diffs
--- PASS: TestAccIAMRole_permissionsBoundary (88.97s)
=== CONT TestAccIAMRole_badJSON
--- PASS: TestAccIAMRole_badJSON (2.76s)
=== CONT TestAccIAMRole_diffsCondition
--- PASS: TestAccIAMRole_diffsCondition (92.88s)
=== CONT TestAccIAMRole_testNameChange
--- PASS: TestAccIAMRole_testNameChange (39.50s)
=== CONT TestAccIAMRole_namePrefix
--- PASS: TestAccIAMRole_namePrefix (23.01s)
--- PASS: TestAccIAMRole_diffs (311.08s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/iam 1135.256s
This functionality has been released in v5.19.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Description
Adds a step to the existing
verify.ValidIAMPolicyJSON
validator which checks for duplicate keys. This can help prevent situations where key values are overwritten (such as duplicatedCondition
keys in IAM policy documents), leading to unintended permission definitions.This particular check will only help when the value is supplied as a heredoc string. Values created from the
jsonencode
function will already have duplicated keys squashed prior to the provider receiving the argument. #33093 addressed a related issue withCondition
keys in theaws_iam_policy_document
data source, and this should be the preferred option for generating values for IAM policy JSON arguments, avoiding this class of error altogether.Relations
Closes #33026
Depends on hashicorp/aws-sdk-go-base#650 (and subsequent release)
Relates hashicorp/terraform#28727
Output from Acceptance Testing