INF-29Required
Keep databases in private subnets
Put every database, cache and queue in a private subnet with no public address. Only the app's own security group may reach it.
How to do it
A private subnet has no route from the internet. Set the service's public access off, such as publicly_accessible = false. Allow the database port only from the app's security group, never from an address range. Reach it for admin work through the admin access rule. File storage stays closed the same way, as Keep storage buckets private says.
Examples
Terraform example
resource "aws_db_instance" "orders" {
identifier = "shop-orders"
publicly_accessible = false
db_subnet_group_name = aws_db_subnet_group.private.name
vpc_security_group_ids = [aws_security_group.orders_db.id]
}
resource "aws_vpc_security_group_ingress_rule" "orders_db_from_app" {
security_group_id = aws_security_group.orders_db.id
referenced_security_group_id = aws_security_group.app.id
ip_protocol = "tcp"
from_port = 5432
to_port = 5432
}
Shell example
aws rds describe-db-instances --query 'DBInstances[?PubliclyAccessible==`true`].DBInstanceIdentifier' # []
How to check
The query below lists no database with a public address. A connection to the database port from outside the network times out.
Sources
- Amazon RDS DB instance in a VPC accessed by an EC2 instance
- NIST SP 800-41 Rev. 1 Guidelines on Firewalls
Related rules
- INF-31 Close admin ports to the internet in Infrastructure and environments
- APS-63 Keep storage buckets private in Application security
- INF-87 Reach managed services over private endpoints in Infrastructure and environments
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/networking-and-dns/private-data-stores">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.