Description
cidr_ip: 0.0.0.0/0 allows every IPv4 address as an incoming source in rules, or as an outgoing destination in rules_egress. An outbound rule alone does not open a database to incoming connections.
Potential impact
If public addressing, routing and the listening port permit a connection, broad ingress allows unwanted login attempts. Broad egress lets a compromised workload contact more destinations. Database authentication and permissions still apply.
Remediation
- Limit each direction to the required ports, protocols and clients or destinations. For database ingress, use an application security group where supported or a CIDR covering approved clients. Check all-address IPv6 rules (
::/0) too. - Keep an all-address rule only where the service needs it, such as a public web listener. Test approved and blocked connections after the change.
Examples
These are excerpts. Replace vpc_id: 12345 with the VPC ID. eu-west-1a is an Availability Zone, so use a Region such as eu-west-1 for region.
Before
- name: create minimal aurora instance in default VPC and default subnet group
community.aws.rds_instance:
engine: aurora
db_instance_identifier: ansible-test-aurora-db-instance
instance_type: db.t2.small
password: "{{ password }}"
username: "{{ username }}"
cluster_id: ansible-test-cluster
db_security_groups: ["example"]
- name: example ec2 group
ec2_group:
name: example
description: an example EC2 group
vpc_id: 12345
region: eu-west-1a
rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 10.0.0.0/8
rules_egress:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: 0.0.0.0/0
After
- name: example ec2 group
ec2_group:
name: example-db
description: database access group
vpc_id: 12345
region: eu-west-1
rules:
- proto: tcp
from_port: 3306
to_port: 3306
cidr_ip: 10.1.1.1/32
rules_egress:
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: 10.1.1.1/32
The first group allows TCP 80 in both directions for all IPv4 addresses and TCP 22 inbound from 10.0.0.0/8. The second creates example-db, allowing TCP 3306 from 10.1.1.1/32 and TCP 443 to that address. Attach the new group to the Aurora cluster and test it, then detach the old group or remove its unneeded rules.