Legacy DB security group allows all source addresses

Limit database access to required application and administrator sources.

Description

A DB security group can allow connections from an entire network. To determine whether a database is internet-accessible, also check its public-access setting, attached groups and routes.

Potential impact

A reachable database can receive unwanted login attempts. Compromised accounts or services can expose data or interrupt service. Authentication and database permissions still govern data access.

Remediation

For current RDS instances, use a VPC security group. Restrict the database port to approved applications and administrators, and remove broader permissions from any attached group. Test connections from permitted and blocked sources.

Examples

These are alternative settings for the same historical resource. Terraform AWS provider 5.0 removed the EC2-Classic aws_db_security_group resource.

Before

hcl
resource "aws_db_security_group" "db_sg" {
  name = "rds_sg"

  ingress {
    cidr = "0.0.0.0/0"
  }
}

0.0.0.0/0 permits all IPv4 sources.

After

hcl
resource "aws_db_security_group" "db_sg" {
  name = "rds_sg"

  ingress {
    cidr = "10.0.0.0/8"
  }
}

10.0.0.0/8 still admits the entire private range. Use the addresses your clients actually need.

References