TF001–TF004 · CIS AWS v5.0 5.2 / 5.3 · SOC 2 CC6.6 · PCI 1.2

Fix Terraform Security Group 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.

Scan Terraform SG (0 Upload) Pro CLI Pack $49 →

0 bytes uploaded · 0 AWS keys · One-time local CLI, SARIF 2.1.0 & SOC 2 CC6.1/CC6.6 pack via Polar.sh.

TF002 (SSH 22 / RDP 3389) TF003 (Postgres 5432 / MySQL 3306) TF004 (All Ports -1 from 0.0.0.0/0) 0 Network Requests During Scan
1. Load a Security Group Sample or Drop Local .tf Files
Drag & drop local Terraform .tf network files — scanned strictly in browser memory.

Exposed vs. Hardened Terraform Security Groups (Before & After)

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.

Vulnerable · TF002 · TF003 · TF004 · CIS 5.2 Fail
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"]
  }
}
Hardened · 100/100 (Grade A · 0 Findings)
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"]
  }
}

Terraform Perimeter & Credential Rules Checked (TF001–TF004)

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.

Gate Every Terraform VPC & RDS Pull Request Locally

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.

Frequently Asked Questions

How do I allow an app tier to reach RDS Postgres/MySQL without 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.

What is the safest replacement for open SSH (22) or RDP (3389)?

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.

Which compliance frameworks fail open 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.

Related AWS IAM & Terraform Remediation Guides

Fix EC2 IMDSv1 & Unencrypted RDS

Enforce IMDSv2 http_tokens = "required", RDS/EBS KMS encryption, and CloudTrail (TF007–TF012).

Read IMDSv2 & KMS Guide

Fix AWS S3 Public Buckets

Check S3 Public Access Block (TF006), SSE-KMS (TF008), and versioning (TF017).

Open S3 Terraform Checker

Oriancy Local Security Quartet

4 Zero-Upload Scanners · 1 One-Time Bundle
DevSecOps Quartet Bundle — All 4 local CLIs & auditor packs on one-time Polar licenses · oriancy.com