Ensure that RDS instances are not publicly accessible
Description
Ensure and verify that the RDS database instances provisioned in your AWS account restrict unauthorized access in order to minimize security risks. To restrict access to any RDS database instance, you must disable the Publicly Accessible flag for the database and update the VPC security group associated with the instance.
Rationale
Ensure that no public-facing RDS database instances are provisioned in your AWS account, and restrict unauthorized access in order to minimize security risks. When the RDS instance allows unrestricted access (0.0.0.0/0), anyone and anything on the Internet can establish a connection to your database, which can increase the opportunity for malicious activities such as brute force attacks, PostgreSQL injections, or DoS/DDoS attacks.
Impact
Disabling public accessibility may require application reconfiguration to use private endpoints or VPN connections. Ensure all applications connecting to the RDS instance can reach it through private networking before making changes.
Audit Procedure
Using AWS Console
- Log in to the AWS management console and navigate to the RDS dashboard at https://console.aws.amazon.com/rds/.
- Under the navigation panel, on the RDS dashboard, click
Databases. - Select the RDS instance that you want to examine.
- Click
Instance Namefrom the dashboard, underConnectivity and Security. - In the
Securitysection, check if the Publicly Accessible flag status is set toNo. - Follow the steps below to check database subnet access:
- In the
networkingsection, click the subnet link underSubnets. - The link will redirect you to the VPC Subnets page.
- Select the subnet listed on the page and click the
Route Tabletab from the dashboard bottom panel. - If the route table contains any entries with the destination CIDR block set to
0.0.0.0/0and anInternet Gatewayattached, the selected RDS database instance was provisioned inside a public subnet; therefore, it is not running within a logically isolated environment and can be accessed from the Internet.
- In the
- Repeat steps 3-6 to determine the configuration of other RDS database instances provisioned in the current region.
- Change the AWS region from the navigation bar and repeat the audit process for other regions.
Using AWS CLI
- Run the
describe-db-instancescommand to list all available RDS database names in the selected AWS region:
aws rds describe-db-instances --region <region-name> --query 'DBInstances[*].DBInstanceIdentifier'
The command output should return each database instance
identifier.Run the
describe-db-instancescommand again, using thePubliclyAccessibleparameter as a query filter to reveal the status of the database instance's Publicly Accessible flag:
aws rds describe-db-instances --region us-east-1 --query 'DBInstances[*].[DBInstanceIdentifier,PubliclyAccessible]' --output table
Check the Publicly Accessible parameter status. If the Publicly Accessible flag is set to
Yes, then the selected RDS database instance is publicly accessible and insecure. Follow the steps mentioned below to check database subnet access.Run the
describe-db-instancescommand again using the RDS database instance identifier that you want to check, along with the appropriate filtering to describe the VPC subnet(s) associated with the selected instance:
aws ec2 describe-route-tables --filters "Name=association.subnet-id,Values=" --query "RouteTables[].Routes[?GatewayId!='null']"
- If the command returns the route table associated with the database instance subnet ID, check the values of the
GatewayIdandDestinationCidrBlockattributes returned in the output. If the route table contains any entries with theGatewayIdvalue set toigw-xxxxxxxxand theDestinationCidrBlockvalue set to0.0.0.0/0, the selected RDS database instance was provisioned within a public subnet. - Or, if the command returns empty results, the route table is implicitly associated with the subnet; therefore, the audit process continues with the next step.
- Run the
describe-route-tablescommand using the ID of the subnet returned in the previous step to describe the routes of the VPC route table associated with the selected subnet:
aws ec2 describe-route-tables --region <region-name> --filters "Name=association.subnet-id,Values=<subnet-id>" --query 'RouteTables[*].Routes[]'
- Run the
describe-db-instancescommand again using the RDS database instance identifier that you want to check, along with the appropriate filtering to describe the VPC ID associated with the selected instance:
aws rds describe-db-instances --region <region-name> --db-instance-identifier <db-instance-name> --query 'DBInstances[*].DBSubnetGroup.VpcId'
- Now run the
describe-route-tablescommand using the ID of the VPC returned in the previous step to describe the routes of the VPC's main route table that is implicitly associated with the selected subnet:
aws ec2 describe-route-tables --region <region-name> --filters "Name=vpc-id,Values=<vpc-id>" "Name=association.main,Values=true" --query 'RouteTables[*].Routes[]'
- The command output returns the VPC main route table implicitly associated with the database instance subnet ID. Check the values of the
GatewayIdandDestinationCidrBlockattributes returned in the output. If the route table contains any entries with theGatewayIdvalue set toigw-xxxxxxxxand theDestinationCidrBlockvalue set to0.0.0.0/0, the selected RDS database instance was provisioned inside a public subnet; therefore, it is not running within a logically isolated environment and does not adhere to AWS security best practices.
Expected Result
The PubliclyAccessible flag should be set to No (or False) for all RDS instances. Additionally, the RDS instances should be deployed in private subnets without routes to Internet Gateways.
Remediation
Using AWS Console
- Log in to the AWS management console and navigate to the RDS dashboard at https://console.aws.amazon.com/rds/.
- Under the navigation panel, on the RDS dashboard, click
Databases. - Select the RDS instance that you want to update.
- Click
Modifyfrom the dashboard top menu. - On the Modify DB Instance panel, under the
Connectivitysection, click onAdditional connectivity configurationand update the value forPublicly AccessibletoNot publicly accessibleto restrict public access. - Follow the below steps to update subnet configurations:
- Select the
Connectivity and securitytab, and click the VPC attribute value inside theNetworkingsection. - Select the
Detailstab from the VPC dashboard's bottom panel and click the Route table configuration attribute value. - On the Route table details page, select the Routes tab from the dashboard's bottom panel and click
Edit routes. - On the Edit routes page, update the Destination of Target which is set to
igw-xxxxxand clickSaveroutes.
- Select the
- On the Modify DB Instance panel, click
Continue, and in the Scheduling of modifications section, perform one of the following actions based on your requirements:- Select
Apply during the next scheduled maintenance windowto apply the changes automatically during the next scheduled maintenance window. - Select
Apply immediatelyto apply the changes right away. With this option, any pending modifications will be asynchronously applied as soon as possible, regardless of the maintenance window setting for this RDS database instance.
- Select
- Repeat steps 3-7 for each RDS instance in the current region.
- Change the AWS region from the navigation bar to repeat the process for other regions.
Using AWS CLI
- Run the
describe-db-instancescommand to list all available RDS database identifiers in the selected AWS region:
aws rds describe-db-instances --region <region-name> --query 'DBInstances[*].DBInstanceIdentifier'
The command output should return each database instance identifier.
Run the
modify-db-instancecommand to modify the configuration of a selected RDS instance, disabling thePublicly Accessibleflag for that instance. This command uses theapply-immediatelyflag. If you want to avoid any downtime, the--no-apply-immediatelyflag can be used:
aws rds modify-db-instance --region <region-name> --db-instance-identifier <db-instance-identifier> --no-publicly-accessible --apply-immediately
The command output should reveal the
PubliclyAccessibleconfiguration under pending values, to be applied at the specified time.Updating the Internet Gateway destination via the AWS CLI is not currently supported. To update information about the Internet Gateway, please use the AWS Console procedure.
Repeat steps 1-5 for each RDS instance provisioned in the current region.
Change the AWS region by using the --region filter to repeat the process for other regions.
Default Value
By default, new Amazon RDS instances are created with the Publicly Accessible setting disabled. However, this option can be explicitly enabled during instance creation or modification.
References
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.html
- https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html
- https://aws.amazon.com/rds/faqs/
CIS Controls
| Controls Version | Control | IG 1 | IG 2 | IG 3 |
|---|---|---|---|---|
| v8 | 3.3 Configure Data Access Control Lists | x | x | x |
| v7 | 14.6 Protect Information through Access Control Lists | x | x | x |
MITRE ATT&CK Mappings
| Techniques / Sub-techniques | Tactics | Mitigations |
|---|---|---|
| T1530 | TA0010 | M1037, M1054 |
Profile
Level 1 | Automated