Skip to main content

SKY-D408 · Deployment and infrastructure

Terraform security group opens a database port to the whole internet

High

Database and cache servers listen on well-known ports. SKY-D408 reports a Terraform security group rule that lets any address on the internet reach a database or cache port: SQL Server 1433, Oracle 1521, MySQL 3306, PostgreSQL 5432, Redis 6379, Cassandra 9042, Elasticsearch 9200, Memcached 11211 or MongoDB 27017 and 27018.

Languages
Terraform
Quality gate
counted toward the gate limits (full and diff scans). Reported under security (danger). It counts toward max_high and max_security; the rule never reports CRITICAL.
Finding type
review
Catalog name
Terraform AWS worldwide database ingress
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Exposed databases and caches are found by automated scans and emptied or held for ransom, often within hours. Redis, Memcached and Elasticsearch frequently run without a password at all.

What Skylos flags

main.tf · TerraformReported on line 5
variable "vpc_id" {  type = string} resource "aws_security_group" "db" {  name   = "orders-db"  vpc_id = var.vpc_id   ingress {    description = "PostgreSQL"    from_port   = 5432    to_port     = 5432    protocol    = "tcp"    cidr_blocks = ["0.0.0.0/0"]  }}

What Skylos leaves alone

main.tf · Terraform
variable "vpc_id" {  type = string} resource "aws_security_group" "db" {  name   = "orders-db"  vpc_id = var.vpc_id   ingress {    description = "PostgreSQL from the VPC"    from_port   = 5432    to_port     = 5432    protocol    = "tcp"    cidr_blocks = ["10.0.0.0/16"]  }}

Why Skylos leaves it alone

The same PostgreSQL rule, but only the VPC's private range can connect.

How Skylos decides

  1. Runs with --danger (or -a). Reads .tf and .tf.json files, skipping .terraform, .git, node_modules, vendor, build, dist and virtual-environment folders, and parses them as HCL without running Terraform or contacting AWS.
  2. Resolves only literal values and local values of the same module. Input variables, data sources, attributes of other resources and module outputs stay unknown, and an unknown value never produces a finding.
  3. Skips a resource with count = 0 or an empty for_each, and needs the official AWS provider (hashicorp/aws, which an aws_ resource uses unless another provider is configured).
  4. Checks the same resources as SKY-D400: ingress blocks of aws_security_group, aws_security_group_rule with type = "ingress", and aws_vpc_security_group_ingress_rule.
  5. A rule counts when its protocol is TCP or all (-1) and its port range includes one of 1433, 1521, 3306, 5432, 6379, 9042, 9200, 11211, 27017 or 27018.
  6. Reports when the merged source ranges cover every IPv4 or every IPv6 address. A rule open on all protocols is reported by both this rule and SKY-D400.
  7. Reports HIGH on the resource line.

How to fix it

Allow the port only from the application's security group or the VPC range, and keep the database in private subnets.

main.tf · Terraform · the fix, against the flagged file
variable "vpc_id" {  type = string} resource "aws_security_group" "db" {  name   = "orders-db"  vpc_id = var.vpc_id   ingress {Removed:     description = "PostgreSQL"Added:     description = "PostgreSQL from the VPC"    from_port   = 5432    to_port     = 5432    protocol    = "tcp"Removed:     cidr_blocks = ["0.0.0.0/0"]Added:     cidr_blocks = ["10.0.0.0/16"]  }}

When it can be wrong

  • Databases on other ports, such as a PostgreSQL moved to 6432, are not recognised.
  • Values that come from variables, modules or other resources are not checked, because Skylos does not run Terraform: cidr_blocks = var.admin_cidrs is not reported even when its default is 0.0.0.0/0.
  • It judges the declaration only. It does not know what is deployed, and other settings (account defaults, security groups, routing) can make the real exposure smaller or larger.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Terraform rules read no inline marker: # skylos: ignore[SKY-D408] on the resource line does not hide the finding.

  • [tool.skylos] ignore = ["SKY-D408"] turns the rule off for the project.

  • A baseline (skylos baseline ., then --baseline) accepts the declarations that exist today and reports new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.