AWS security group allows ingress from all source addresses

Separate ingress scope for public services from internal-only services.

Description

Allow the database’s application clients by CIDR or source security group. Even on one database port, 0.0.0.0/0 covers every IPv4 source and ::/0 covers every IPv6 source.

Potential impact

Where routes and a listener permit it, unintended clients can attempt database connections. Database authentication applies separately.

Remediation

Keep public web access in separate rules or groups. Check all attached groups and network paths, then test that an approved application can connect and that other sources are blocked.

Examples

Both excerpts use TCP 3306. Verify the listening port and identify the target VPC and the resources that will use this group.

Before

hcl
resource "aws_security_group" "database_access" {
  ingress {
    from_port   = 3306
    to_port     = 3306
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

The first rule allows every IPv4 source on this port.

After

hcl
resource "aws_security_group" "database_access" {
  ingress {
    from_port   = 3306
    to_port     = 3306
    protocol    = "tcp"
    cidr_blocks = ["10.0.0.0/16"]
  }
}

The second permits the whole of 10.0.0.0/16. Narrow that range to the application clients that need the database.

References