SKY-D408 · Deployment and infrastructure
Terraform security group opens a database port to the whole internet
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 towardmax_highandmax_security; the rule never reports CRITICAL. - Finding type
- review
- Catalog name
- Terraform AWS worldwide database ingress
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
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
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
- Runs with
--danger(or-a). Reads.tfand.tf.jsonfiles, skipping.terraform,.git,node_modules,vendor,build,distand virtual-environment folders, and parses them as HCL without running Terraform or contacting AWS. - Resolves only literal values and
localvalues 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. - Skips a resource with
count = 0or an emptyfor_each, and needs the official AWS provider (hashicorp/aws, which anaws_resource uses unless another provider is configured). - Checks the same resources as SKY-D400:
ingressblocks ofaws_security_group,aws_security_group_rulewithtype = "ingress", andaws_vpc_security_group_ingress_rule. - 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. - 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.
- Reports HIGH on the
resourceline.
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.
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_cidrsis not reported even when its default is0.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.