rules:
- id: no-iam-admin-privileges
  pattern-either:
  - patterns:
    - pattern-inside: |
        resource $TYPE "..." {
          ...
          policy = jsonencode({
            ...
            Statement = [
              ...
            ]
            ...
          })
          ...
        }
    - pattern-not-inside: |
        resource $TYPE "..." {
          ...
          policy = jsonencode({
            ...
            Statement = [
              ...,
              {... Effect = "Deny" ...},
              ...
            ]
            ...
          })
          ...
        }
    - patterns:
      - pattern: |
          {..., Action = "*", ...}
      - pattern: |
          {..., Resource = "*", ...}
    - metavariable-pattern:
        metavariable: $TYPE
        pattern-either:
        - pattern: |
            "aws_iam_role_policy"
        - pattern: |
            "aws_iam_policy"
        - pattern: |
            "aws_iam_user_policy"
        - pattern: |
            "aws_iam_group_policy"
  - patterns:
    - pattern-inside: |
        data aws_iam_policy_document "..." {
          ...
          statement {
            ...
          }
          ...
        }
    - pattern-not-inside: |
        data aws_iam_policy_document "..." {
          ...
          statement {
            ...
            effect = "Deny"
            ...
          }
          ...
        }
    - patterns:
      - pattern: |
          {..., resources = ["*"], ...}
      - pattern: |
          {..., actions = ["*"], ...}
  message: >-
    IAM policies that allow full "*-*" admin privileges violates the principle of least privilege.
    This allows an attacker to take full control over all AWS account resources. Instead, give each user
    more fine-grained control with only the privileges they need. $TYPE
  metadata:
    references:
    - https://github.com/bridgecrewio/checkov/blob/master/checkov/terraform/checks/data/aws/AdminPolicyDocument.py
    category: security
    cwe:
    - 'CWE-269: Improper Privilege Management'
    technology:
    - terraform
    - aws
    owasp:
    - A04:2021 - Insecure Design
    subcategory:
    - audit
    likelihood: LOW
    impact: LOW
    confidence: LOW
  languages: [hcl]
  severity: WARNING
