INF-30Required
Deny all traffic unless a rule allows it
Start every security group and firewall from deny. Allow only named ports from named sources, and open a port to the whole internet only on the load balancer.
How to do it
Write each allowed path as its own rule in code. Point rules at other security groups instead of address ranges where you can. Only the public load balancer takes 0.0.0.0/0 and ::/0, and only on ports 80 and 443. Remove the default rules a new network comes with. The app applies the same idea to access in Deny by default.
Examples
Shell example
# Lists rules open to the internet on ports other than 80 and 443. Expect nothing.
aws ec2 describe-security-group-rules --query \
'SecurityGroupRules[?IsEgress==`false` && (CidrIpv4==`0.0.0.0/0` || CidrIpv6==`::/0`) && !(FromPort==`443` && ToPort==`443`) && !(FromPort==`80` && ToPort==`80`)].[GroupId,FromPort,ToPort]' \
--output text
How to check
The query below finds no rule open to the internet on any port but 80 or 443. Rules open on 80 or 443 belong only to the load balancer's security group. A policy scan fails a pull request that adds one.
Sources
Related rules
- WEB-166 Be reachable over IPv6 in Website
- APS-20 Deny by default and when a check fails in Application security
- INF-71 Let only your edge network reach the origin in Infrastructure and environments
- INF-76 Publish only the ports visitors use in Infrastructure and environments
- INF-81 Deny pod traffic by default with network policies 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/deny-by-default-firewall">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.