Description
Ensure and verify that RDS database instances provisioned in your AWS account do restrict unauthorized access in order to minimize security risks. To restrict access to any publicly accessible RDS database instance, you must disable the database Publicly Accessible flag 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), everyone and everything on the Internet can establish a connection to your database and this can increase the opportunity for malicious activities such as brute force attacks, PostgreSQL injections, or DoS/DDoS attacks.
Auditโ
From 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 RDS Dashboard, click
Databases. -
Select the RDS instance that you want to examine.
-
Click
Instance Namefrom the dashboard, UnderConnectivity and Security. -
On the
Security, check if thePublicly Accessibleflag status is set toYes. -
Follow the below-mentioned steps to check database subnet access:
- In the
networkingsection, click the subnet link available 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 with anInternet Gatewayattached, the selected RDS database instance was provisioned inside a public subnet, therefore is not running within a logically isolated environment and can be accessible from the Internet.
- In the
-
Repeat steps no. 4 and 5 to determine the type (public or private) and subnet for 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.
From Command Lineโ
- Run
describe-db-instancescommand to list all RDS database names, available 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 again
describe-db-instancescommand using thePubliclyAccessibleparameter as query filter to reveal the database instance Publicly Accessible flag status:
aws rds describe-db-instances --region <region-name> --db-instance-identifier <db-instance-name> --query 'DBInstances[*].PubliclyAccessible'
- Check for the Publicly Accessible parameter status, If the Publicly Accessible flag is set to
Yes. Then selected RDS database instance is publicly accessible and insecure, follow the below-mentioned steps to check database subnet access - Run again
describe-db-instancescommand using the RDS database instance identifier that you want to check and appropriate filtering to describe the VPC subnet(s) associated with the selected instance:
aws rds describe-db-instances --region <region-name> --db-instance-identifier <db-name> --query 'DBInstances[*].DBSubnetGroup.Subnets[]'
- The command output should list the subnets available in the selected database subnet group.
- Run
describe-route-tablescommand using the ID of the subnet returned at 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=<SubnetID>" --query 'RouteTables[*].Routes[]'
-
If the command returns the route table associated with database instance subnet ID. Check the
GatewayIdandDestinationCidrBlockattributes values 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.OR
-
If the command returns empty results, the route table is implicitly associated with subnet, therefore the audit process continues with the next step
- Run again
describe-db-instancescommand using the RDS database instance identifier that you want to check and appropriate filtering to describe the VPC ID associated with the selected instance:
aws rds describe-db-instances --region <region-name> --db-instance-identifier <db-name> --query 'DBInstances[*].DBSubnetGroup.VpcId'
- The command output should show the VPC ID in the selected database subnet group.
- Now run
describe-route-tablescommand using the ID of the VPC returned at the previous step to describe the routes of the VPC main route table 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 database instance subnet ID. Check the
GatewayIdandDestinationCidrBlockattributes values 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 is not running within a logically isolated environment and does not adhere to AWS security best practices.