Skip to main content

SKY-D400 · Deployment and infrastructure

Terraform security group opens SSH or RDP to the whole internet

High

An AWS security group is a firewall for servers. SKY-D400 reports a Terraform security group rule that lets any address on the internet (0.0.0.0/0 or ::/0) reach the administrative ports 22 (SSH) or 3389 (Remote Desktop).

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 administrative ingress
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Internet-wide scanners try passwords and known exploits on these ports within minutes of a server coming up. One weak password or unpatched SSH or RDP service then gives an attacker a shell inside your network.

What Skylos flags

main.tf · TerraformReported on line 5
variable "vpc_id" {  type = string} resource "aws_security_group" "bastion" {  name   = "bastion"  vpc_id = var.vpc_id   ingress {    description = "SSH"    from_port   = 22    to_port     = 22    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" "bastion" {  name   = "bastion"  vpc_id = var.vpc_id   ingress {    description = "SSH from the office VPN"    from_port   = 22    to_port     = 22    protocol    = "tcp"    cidr_blocks = ["10.20.0.0/16"]  }}

Why Skylos leaves it alone

The same SSH rule, but the source is the private VPN range 10.20.0.0/16, not the whole internet. Skylos merges all source ranges of a rule and reports only when together they cover every IPv4 or every IPv6 address.

More languages

Terraform

Flagged

main.tf · TerraformReported on line 1
resource "aws_vpc_security_group_ingress_rule" "rdp" {  security_group_id = aws_security_group.windows.id  ip_protocol       = "tcp"  from_port         = 3389  to_port           = 3389  cidr_ipv6         = "::/0"}

Not flagged

main.tf · Terraform
resource "aws_vpc_security_group_ingress_rule" "https" {  security_group_id = aws_security_group.windows.id  ip_protocol       = "tcp"  from_port         = 443  to_port           = 443  cidr_ipv6         = "::/0"}

Why Skylos leaves it alone

Opening HTTPS (443) to everyone is normal for a public web server. Only ranges that include port 22 or 3389 (or every protocol, -1) count.

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 ingress blocks of aws_security_group, aws_security_group_rule with type = "ingress", and aws_vpc_security_group_ingress_rule.
  5. A rule counts as administrative when its protocol is TCP (tcp or 6) and its port range includes 22 or 3389, or when the protocol is all (-1). UDP and ICMP rules are left alone.
  6. Merges the rule's IPv4 and IPv6 source ranges and reports when they cover a whole address family, so 0.0.0.0/1 plus 128.0.0.0/1 counts as the whole internet. Rules whose source is another security group or a prefix list are not reported.
  7. Reports HIGH on the resource line, once per resource.

How to fix it

Allow SSH and RDP only from known ranges such as a VPN, or close the ports and use AWS Systems Manager Session Manager or EC2 Instance Connect instead.

main.tf · Terraform · the fix, against the flagged file
variable "vpc_id" {  type = string} resource "aws_security_group" "bastion" {  name   = "bastion"  vpc_id = var.vpc_id   ingress {Removed:     description = "SSH"Added:     description = "SSH from the office VPN"    from_port   = 22    to_port     = 22    protocol    = "tcp"Removed:     cidr_blocks = ["0.0.0.0/0"]Added:     cidr_blocks = ["10.20.0.0/16"]  }}

When it can be wrong

  • 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-D400] on the resource line does not hide the finding.

  • [tool.skylos] ignore = ["SKY-D400"] 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.