-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the issue
Many checks use the Cloudsplaining library to parse IAM policies, and there is a caching mechanism to avoid parsing again the same policy multiple times, as that can be time consuming. The cache uses entity_path as the key, which is derived from the un-indexed name of each terraform resource.
This means that if two or more IAM resources are defined in with count or for_each, which will make them have the same name, only the first one will be loaded, and the rest will be skipped, with the scanner rerunning again on the same cached policy code.
Examples
Example configuration that would trigger the bug:
resource "aws_iam_policy" "policy" {
for_each = toset(["policy1.json", "policy2.json"])
name = replace(each.value, ".json", "")
path = "/"
policy = file(each.value)
}as this would create two policies with addresses aws_iam_policy.policy["policy1.json"] and aws_iam_policy.policy["policy2.json"], but only the first one would be loaded and scanned since the entity path would only include aws_iam_policy.policy.
Version:
- Checkov Version 3.2.483
Additional context
N/A