fix(query): fn for IAM_Policies_With_Full_Privileges -- terraform/aws #7601
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.








Reason for Proposed Changes
This query flags for samples when IAM policies are allowed full administrative privileges; however , it will only flag this result if the
Action/Resourcefields of a valid IAM policy resource or theactions/resourcesfields of aaws_iam_policy_documentdata both have the*permission; with this implementation it dismisses instances ofResource/resourceswith the expected * permission andAction/actionsfields that include"iam:*"permissions, and those results should also be flagged.The granted permission (
iam:*) allows for the creation/edition/deletion of policies, so it ends up being equivalent to*. (aws_guide page 1665/4071 - "to allow users to perform any IAM action, you can use iam:*")Proposed Changes
To flag for both relevant instances (
*/iam:*), i added ais_full_priviledge_permissionfunction to replace the simple check for*, allowing either permission type to result in a true evaluation for the policy.When analyzing the query i found the
searchLinevalues to be problematic , sometimes resulting in -1 ; to fix this the policy that handlesaws_iam_policy_documentdata had to be adjusted to better handle arrays vs single instances of statement(s) inside the data. Currently this handling is poor and thesearchLine/keyExpectedValue/keyActualValue/searchKeyvalues are all incorrectly referencing "policy" instead of theaws_iam_policy_documentequivalent (statements) resulting in the wrongsearchLine/Keyvalues.With the better case handling the correct relevant statement will now be indicated if there are multiple statements , the
searchLine/searchKeyvalues are now valid and more precise when there is an array of statement; previously the result would point to theaws_iam_policy_documentthe statements belonged to instead of the relevant statement.I submit this contribution under the Apache-2.0 license.