RDS Inherits the Default Security Group You Forgot
Overview
A CreateDBInstance call without an explicit VpcSecurityGroupIds parameter silently attaches the VPC's default security group, and that group often still carries a 0.0.0.0/0 rule on 3306 or 5432 left over from an old migration script, exposing MySQL or PostgreSQL to the internet the moment PubliclyAccessible is set to true.
At a glance
- Symptom
- PubliclyAccessible is set to true while the inherited default security group still carries a 0.0.0.0/0 ingress rule on 3306 or 5432 from an earlier…
- Likely cause
- RDS instance created without an explicit VpcSecurityGroupIds parameter, causing inheritance of the VPC's default security group.
- Impact
- The database becomes directly reachable from the internet on its engine port with no bastion, VPN, or PrivateLink boundary in the path.
- Verification signal
- Re-run the detection test and a controlled negative-path test.
- Safe correction
- Strip ingress from the default security group, mandate explicit scoped VpcSecurityGroupIds on every RDS instance, and enforce AWS Config rules rds-instance-public-access-check and vpc-default-security-group-closed.
- Rollback or recovery
- Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.
The Trap
Default Security Group Inheritance on RDS. When a CreateDBInstance API call or a Terraform resource omits an explicit security group, RDS does not refuse the request or fall back to a locked-down group. It associates the default security group of the DB subnet group’s VPC, whatever state that group happens to be in, and the console’s create wizard preselects that same default group unless someone changes it.
The Default State
Every VPC has an AWS-created default security group, which cannot be deleted, and most still carry its original self-referencing ingress rule. That would be harmless on its own.
The problem is that this group is shared infrastructure: someone, at some point, opened it to 0.0.0.0/0 on port 3306 or 5432 to unblock a one-off data load, a Lambda function that couldn’t resolve a VPC endpoint, or a contractor’s laptop. Nobody revoked the rule afterwards because the default group looks like background noise, not a production control.
Separately, a Terraform module or a hurried console choice sets publicly_accessible to true for a “quick dev instance” and that instance later gets promoted, cloned, or copied into a production account with the flag untouched.
The Blast Radius
The two defaults compound. PubliclyAccessible=true gives the endpoint a public IP address, and with the DB subnets routed to an internet gateway, the inherited default security group, still carrying the stale 0.0.0.0/0 ingress rule on 3306 or 5432, permits any source address to reach the listener. There is no bastion, no VPN, no PrivateLink boundary in the path.
The database becomes reachable directly from the internet using nothing but its engine port. Exposed database ports are routinely scanned by credential-stuffing bots, and a weak or default master password turns into full data exfiltration or ransomware encryption of the instance.
The AWS Config rules below can flag the exposure, but only after it exists, so the fix has to stop the accidental attach in the first place.
The Lead Mechanic Fix
Close the default security group in each VPC so it can never again serve as an accidental attach point. First list what uses it (aws ec2 describe-network-interfaces --filters Name=group-id,Values=sg-default): removing its rules cuts off every resource still attached, so move each to a purpose-built group and continue only when that query returns nothing.
Save its rules for rollback (aws ec2 describe-security-group-rules --filters Name=group-id,Values=sg-default > sg-default-rules.json), then, in a change window, revoke every ingress and egress rule by ID, self-referencing one included: aws ec2 revoke-security-group-ingress --group-id sg-default --security-group-rule-ids sgr-xxxxxxxx, and revoke-security-group-egress likewise. To roll back, re-add the saved rules with authorize-security-group-ingress and authorize-security-group-egress.
Require every aws_db_instance resource to set vpc_security_group_ids explicitly to a purpose-built group scoped to the application subnet CIDR only. Enable the AWS Config managed rules rds-instance-public-access-check and vpc-default-security-group-closed. Config remediation needs an SSM Automation document and role you configure; limit it to named instances, approved per run.
Before changing an instance, confirm its clients from the engine’s session view and VPC Flow Logs, and that sg-scoped admits them all.
Then, one instance at a time in a change window, run aws rds modify-db-instance --db-instance-identifier <db-instance-id> --no-publicly-accessible --vpc-security-group-ids sg-scoped --apply-immediately; clients outside sg-scoped lose access as soon as it applies, so keep the original group IDs to reapply.
Related reading
Apply the safer control
Before you change production
Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.
Fix commands and configuration
aws ec2 describe-network-interfaces --filters Name=group-id,Values=sg-defaultaws ec2 describe-security-group-rules --filters Name=group-id,Values=sg-default > sg-default-rules.jsonaws ec2 revoke-security-group-ingress --group-id sg-default --security-group-rule-ids sgr-xxxxxxxxVerify, roll back or escalate
Verify
Re-run the detection test and a controlled negative-path test. Confirm the unsafe behaviour is blocked while approved traffic still succeeds.
Rollback
Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.
Escalate
Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.
Fixed? Get the next one before it hits you: The KBY Brief
Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.
About this page
Credited to
Dates
Published
Last updated
Corrections
- : Corrected during a review of published articles. Details
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Found this useful? Follow KBY for more like it.
