RDS-linked subnet uses a /0 CIDR

RDS subnets need valid VPC address ranges and appropriate routing. Replace invalid /0 ranges and restrict the actual connection paths for private databases.

Description

A subnet’s CidrBlock or Ipv6CidrBlock must be a supported range within its VPC. 0.0.0.0/0 and ::/0 are invalid subnet ranges. A direct route to an internet gateway makes a subnet public, including one with private addresses.

Potential impact

An invalid range can prevent stack creation or updates. If the database has a public address and both routing and security groups allow the connection, unintended external clients can reach it.

Remediation

  • Allocate nonoverlapping ranges with spare addresses for maintenance and failover. A typical regional DB subnet group spans two Availability Zones. Check the different requirements for Local Zones.
  • For a private database, check each subnet’s routes, exclude direct internet-gateway routes, set PubliclyAccessible: false, and allow only the necessary clients. Prepare and test the application’s private route before changing the stack.

Examples

The first excerpt omits mySubnet1. Both omit VpcId, DBSubnetGroupDescription and required database properties. The second lacks the usual two-zone layout. The logical IDs change, so review which resources a stack update affects.

Before

yaml
Resources:
  Positive1:
    Type: AWS::RDS::DBInstance
    Properties:
      DBSubnetGroupName:
        Ref: myDBSubnetGroup
  myDBSubnetGroup:
    Type: "AWS::RDS::DBSubnetGroup"
    Properties:
      SubnetIds:
        - Ref: mySubnet1
        - Ref: mySubnet2
  mySubnet2:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 0.0.0.0/0

After

yaml
Resources:
  Negative1:
    Type: AWS::RDS::DBInstance
    Properties:
      DBSubnetGroupName:
        Ref: myDBSubnetGroup0
  myDBSubnetGroup0:
    Type: "AWS::RDS::DBSubnetGroup"
    Properties:
      SubnetIds:
        - Ref: mySubnet10
  mySubnet10:
    Type: AWS::EC2::Subnet
    Properties:
      CidrBlock: 10.0.0.0/24

Explanation:

  • Before: AWS cannot assign 0.0.0.0/0 to a subnet.
  • After: 10.0.0.0/24 has a supported size. Check that it fits the VPC without overlap and that the omitted routes and security groups allow only the intended paths.

References