int128 / terraform-aws-nat-instance

Terraform module to provision a NAT Instance using an Auto Scaling Group and Spot Instance from $1/month
https://registry.terraform.io/modules/int128/nat-instance/aws/
Apache License 2.0
175 stars 90 forks source link

iam policy with wildcards #49

Open syscod3 opened 2 years ago

syscod3 commented 2 years ago

Hi! another tfsec warning

Result #2 HIGH IAM policy document uses sensitive action 'ec2:AttachNetworkInterface' on wildcarded resource '*'
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 .terraform/modules/nat_instance/main.tf Line 199
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  194  │         {
  195  │             "Effect": "Allow",
  196  │             "Action": [
  197  │                 "ec2:AttachNetworkInterface"
  198  │             ],
  199  │             "Resource": "*"
  200  │         }
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
          ID aws-iam-no-policy-wildcards
      Impact Overly permissive policies may grant access to sensitive resources
  Resolution Specify the exact permissions required, and to which resources they should apply instead of using wildcards.

  More Information
  - https://aquasecurity.github.io/tfsec/v1.8.0/checks/aws/iam/no-policy-wildcards/
  - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

it can probably be solved by adding a condition to the policy (as per the ASG tag here) like

         "Condition": {
             "StringEquals": {
                "aws:resourceTag/Name": "nat-instance-${var.name}"
              }
          }