Fix EC2 IMDSv1 & Unencrypted RDS
Enforce IMDSv2 http_tokens = "required", RDS/EBS KMS encryption, and CloudTrail (TF007–TF012).
0.0.0.0/0 SSH, RDP & RDS Exposure
Close internet-facing SSH (22), RDP (3389), PostgreSQL (5432), MySQL (3306), Redis (6379), and
all-protocol (-1) ingress rules (TF002–TF004) plus hardcoded Terraform credentials
(TF001) in seconds—0 bytes uploaded.
0 bytes uploaded · 0 AWS keys · One-time local CLI, SARIF 2.1.0 & SOC 2 CC6.1/CC6.6 pack via Polar.sh.
.tf Files
.tf network files — scanned strictly in browser memory.
Never expose database ports (5432, 3306, 6379, 27017) or
management ports (22, 3389) to 0.0.0.0/0 or ::/0. Reference
upstream security group IDs for app-to-DB traffic and restrict SSH to private VPN CIDRs or AWS SSM Session Manager.
resource "aws_security_group" "web_and_db" {
name = "prod-exposed-sg"
description = "Overly open ingress"
vpc_id = aws_vpc.main.id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "rds_private" {
name = "prod-rds-private-sg"
description = "Allow Postgres strictly from app tier security group"
vpc_id = aws_vpc.main.id
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
security_groups = [aws_security_group.app_tier.id]
}
}
resource "aws_security_group" "bastion_vpn" {
name = "prod-ssh-vpn-only"
description = "Allow SSH strictly from corporate VPN CIDR"
vpc_id = aws_vpc.main.id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.20.0.0/24"]
}
}
| Rule | Severity | Terraform Misconfiguration | Verified Fix |
|---|---|---|---|
TF001 |
CRITICAL | Hardcoded AWS access key (AKIA...) or plaintext DB password in *.tf |
Use OIDC roles + AWS Secrets Manager / SSM Parameter Store data sources. |
TF002 |
CRITICAL | Security Group exposes SSH (22) or RDP (3389) to 0.0.0.0/0 or ::/0 |
Switch to AWS SSM Session Manager or narrow corporate VPN CIDR. |
TF003 |
CRITICAL | Security Group exposes PostgreSQL (5432), MySQL (3306), Redis (6379), Mongo (27017), or ES (9200) to internet |
Restrict ingress to security_groups = [aws_security_group.app_tier.id] in private subnets. |
TF004 |
CRITICAL | Security Group allows all ports/protocols (-1 or 0..0) from 0.0.0.0/0 or ::/0 |
Allow only explicit application ports (e.g., 443 on ALB) with least-privilege sources. |
Run leastproof-cli in CI/CD with zero Python dependencies and get SARIF 2.1.0 annotations plus
hardened S3/RDS/VPC CIS v5.0 Terraform templates in the Team Pack.
0.0.0.0/0?
Reference the application tier's security group ID via security_groups = [aws_security_group.app_tier.id]
on port 5432/3306 and deploy RDS in private subnets with publicly_accessible = false.
Remove inbound port 22/3389 rules entirely and connect via AWS Systems Manager Session Manager or EC2 Instance
Connect Endpoint; if SSH is mandatory, lock cidr_blocks to a private VPN CIDR.
0.0.0.0/0 Security Groups?CIS AWS v5.0 5.2 and 5.3, SOC 2 CC6.1 and CC6.6, ISO/IEC 27001:2022 A.8.20–A.8.22, and PCI-DSS Requirements 1.2 and 1.3.
Enforce IMDSv2 http_tokens = "required", RDS/EBS KMS encryption, and CloudTrail (TF007–TF012).
Check S3 Public Access Block (TF006), SSE-KMS (TF008), and versioning (TF017).
iam:PassRole EscalationScope iam:PassRole and remove CreatePolicyVersion wildcards (IAM002–009).