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 Name
from the dashboard, UnderConnectivity and Security
. -
On the
Security
, check if thePublicly Accessible
flag status is set toYes
. -
Follow the below-mentioned steps to check database subnet access:
- In the
networking
section, 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 Table
tab from the dashboard bottom panel. - If the route table contains any entries with the destination CIDR block set to
0.0.0.0/0
and with anInternet Gateway
attached, 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-instances
command 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-instances
command using thePubliclyAccessible
parameter 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-instances
command 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-tables
command 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
GatewayId
andDestinationCidrBlock
attributes values returned in the output. If the route table contains any entries with theGatewayId
value set toigw-xxxxxxxx
and theDestinationCidrBlock
value 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-instances
command 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-tables
command 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
GatewayId
andDestinationCidrBlock
attributes values returned in the output. If the route table contains any entries with theGatewayId
value set toigw-xxxxxxxx
and theDestinationCidrBlock
value 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.