Other Articles
- IAM - Enable User MFA
- IAM - Enforce Key Rotation
- IAM - Enforce Active Key Limit
- IAM - Disable Unused User Credentials
- IAM - Enforce Group Permission
- IAM - Enforce Password Length
- IAM - Prohibit Password Reuse
- IAM - Check Root Access Keys Existence
- IAM - Enable Root MFA
- IAM - Establish Support Role
- IAM - Enable Key Rotation
- Purge Expired Certificates
- EC2 Volume – Enable EBS Volume Backup
- EC2 Volume – Enable EBS Encryption
- EFS – Enable EFS Storage Backup
- S3 Bucket – Enable S3 Bucket Versioning
- S3 Bucket – Enable S3 Bucket Encryption
- S3 Bucket – Block S3 Bucket Public Access
- RDS DB Instance – Encryption of Storage
- RDS DB Instance – Enable Deletion Protection
- RDS DB Instance – Enable Auto Minor Version Upgrade
- DynamoDB Table – Enable Table Encryption
- DynamoDB Table – Enable Table Point In Time Recovery
- DynamoDB Table – Enable Table Deletion Protection
- EKS Cluster – Enable Secrets Encryption
- OpenSearch Domain – Enable Encryption at Rest
- RDS DB Cluster – Retain Backups for 7 Days
- RDS DB Cluster – Encryption of Storage
- RDS DB Cluster – Enable Deletion Protection
- EC2 Instance – Monitor CPU Utilization
- ECS Service – Monitor CPU Utilization
- ECS Service – Monitor Memory Utilization
- RDS DB Instance – Monitor Free Storage Space
- RDS DB Instance – Monitor CPU Utilization
- SQS Queue – Monitor Message Age
- SQS Queue – Monitor Message Visibility
- DynamoDB Table – Monitor Table Read Capacity
- DynamoDB Table – Monitor Table Write Capacity
- DynamoDB Table – Monitor Table Latency
- Enable CloudTrail
- Encrypt CloudTrail Logs
- EC2 VPC – Ensure Flow Logs are Enabled
- EKS Cluster – Enable Control Plane Logging
- CloudWatch Log Group – Enable KMS Encryption
- CloudWatch Log Group – Configure Retention
- Load Balancer – Enable Access Logs
- RDS DB Instance – Block Public Access
- EC2 Security Group – Restrict Public SSH and RDP Access
- EKS Cluster – Restrict Public Endpoint
- EC2 VPC – Restrict Default Security Group Traffic
- Load Balancer – Redirect HTTP Traffic to HTTPS
- Load Balancer – Use Strong TLS Policies
- OpenSearch Domain – Enable Node-to-Node Encryption
- OpenSearch Domain – Enforce HTTPS
- OpenSearch Domain – Restrict Public Access
- RDS DB Cluster – Block Public Access
- EC2 Instance – Enable Deletion Protection
- ECS Service – Enable Auto Scaling
- Load Balancer – Enable Deletion Protection
- Enable AWS Security Hub
- Enable GuardDuty
- CloudFront Distribution – Enforce HTTPS for Viewers
- CloudFront Distribution – Require TLS 1.2 for Viewers
- CloudFront Distribution – Associate a WAF Web ACL
- CloudFront Distribution – Protect S3 Origin Access
- KMS Key – Avoid Pending Deletion
- SNS Topic – Enable Encryption
- SNS Topic – Restrict Topic Policy Access
EC2 Security Group – Restrict Public Database Access
Secure Configuration Checks > AWS
This check ensures that no EC2 security group allows common database ports to be reached from the entire internet. Exposed databases are a leading cause of data theft and ransom attacks.
Check Details
- Resource: EC2 Security Group
- Check: Restrict public database access (
NoUnrestrictedDatabasePorts) - Risk: Attackers can read, change or delete data, or lock it for ransom
Ports covered
- MySQL / MariaDB:
3306 - PostgreSQL:
5432 - SQL Server:
1433 - MongoDB:
27017 - Redis:
6379 - Elasticsearch:
9200and9300 - Redshift:
5439
Remediation via AWS Console
-
Log in to the AWS Management Console and open the Amazon EC2 console.
-
In the left navigation pane, select Security Groups and choose the affected security group.
-
Open the Inbound rules tab and click Edit inbound rules.
-
Identify database port rules that allow unrestricted access from
0.0.0.0/0(IPv4) or::/0(IPv6).Common database ports include:
- 3306: MySQL / Aurora
- 5432: PostgreSQL
- 1433: Microsoft SQL Server
- 1521: Oracle
- 5439: Amazon Redshift
-
For each affected rule, change the Source to the application's security group or a trusted IP address range. If external access is not required, click Delete to remove the rule.
-
Click Save rules to apply the changes.
-
Repeat these steps for every affected security group. Verify that no database port allows unrestricted access from
0.0.0.0/0or::/0.
Note: Prefer referencing the application's security group as the source when database access is required between resources in the same VPC. Ensure that other associated security groups do not independently allow unrestricted access to the database ports.
Remediation via AWS CLI
-
Log in to the AWS Management Console and click the CloudShell icon (
>_) in the top-right corner.
-
List the open rules that include a database port. The output shows the group ID, name and port range:
PORTS="3306 5432 1433 27017 6379 9200 9300 5439" aws ec2 describe-security-groups --output json | \ jq -r --arg ports "$PORTS" ' ($ports | split(" ") | map(tonumber)) as $p | .SecurityGroups[] as $sg | $sg.IpPermissions[] as $r | select( ([$r.IpRanges[].CidrIp] | index("0.0.0.0/0")) != null or ([$r.Ipv6Ranges[].CidrIpv6] | index("::/0")) != null) | select( $r.IpProtocol == "-1" or ($r.IpProtocol == "tcp" and any($p[]; . >= $r.FromPort and . <= $r.ToPort))) | [$sg.GroupId, $sg.GroupName, ($r.FromPort // "all"), ($r.ToPort // "all")] | @tsv'The command covers one region. Add
--region <region>to check another. -
Allow the port only from the application security group:
aws ec2 authorize-security-group-ingress \ --group-id <security-group-id> \ --protocol tcp \ --port <port> \ --source-group <app-security-group-id>
To allow an IP range instead, replace
--source-groupwith--cidr <trusted-cidr>. -
Remove the open rules for the same port, for both IPv4 and IPv6:
aws ec2 revoke-security-group-ingress \ --group-id <security-group-id> \ --protocol tcp \ --port <port> \ --cidr 0.0.0.0/0 aws ec2 revoke-security-group-ingress \ --group-id <security-group-id> \ --ip-permissions 'IpProtocol=tcp,FromPort=<port>,ToPort=<port>,Ipv6Ranges=[{CidrIpv6=::/0}]'If a rule allows all traffic or a wide port range, remove it and add only the ports you need.
-
Verify the remaining inbound rules:
aws ec2 describe-security-groups \ --group-ids <security-group-id> \ --query 'SecurityGroups[0].IpPermissions'
Replace <security-group-id> with the group ID, for example sg-0123456789abcdef0.
Replace <port> with the database port, for example 3306.
Repeat steps 3 and 4 for each port.
Updated on 03 November, 2026