Description
Limit incoming connections to the clients that need the database port. An internal network can contain unrelated applications, even if every address in it is private.
Potential impact
A compromised host inside an allowed range can attempt to reach the database if the network path is open. Authentication and database permissions still control data access.
Remediation
- In VPC security groups, restrict
CidrIporCidrIpv6to approved sources and the required protocol and port. Where supported, use the application’s security group as the source. Review every attached group. - For a historical RDS DB security group, review
CIDRIPagainst the same client list. Use VPC security groups for current RDS instances. Verify that approved clients can connect and other sources are blocked.
Examples
For these MySQL examples, provide a DB subnet group in the security group’s VPC, a supported instance class and an administrator name. RDS manages the password in Secrets Manager.
Before
yaml
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
DBSubnetGroupName:
Type: String
DBInstanceClass:
Type: String
MasterUsername:
Type: String
Resources:
DBinstance1:
Type: AWS::RDS::DBInstance
Properties:
VPCSecurityGroups:
- Ref: DbSecurity
AllocatedStorage: "20"
DBInstanceClass: !Ref DBInstanceClass
DBSubnetGroupName: !Ref DBSubnetGroupName
Engine: mysql
MasterUsername: !Ref MasterUsername
ManageMasterUserPassword: true
DeletionPolicy: Snapshot
UpdateReplacePolicy: Snapshot
DbSecurity:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: MySQL access
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: 10.0.0.0/23
The group allows TCP 3306 from the whole 10.0.0.0/23 network.
After
yaml
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
DBSubnetGroupName:
Type: String
DBInstanceClass:
Type: String
MasterUsername:
Type: String
Resources:
DBinstance1:
Type: AWS::RDS::DBInstance
Properties:
VPCSecurityGroups:
- Ref: DbSecurity
AllocatedStorage: "20"
DBInstanceClass: !Ref DBInstanceClass
DBSubnetGroupName: !Ref DBSubnetGroupName
Engine: mysql
MasterUsername: !Ref MasterUsername
ManageMasterUserPassword: true
DeletionPolicy: Snapshot
UpdateReplacePolicy: Snapshot
DbSecurity:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: MySQL access
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 3306
ToPort: 3306
CidrIp: 10.0.1.10/32
10.0.1.10/32 permits one client on the same port. Use the actual approved client address.