Security · 4 min read

Writing least-privilege firewall rules without breaking the app

Least privilege in firewall design means permitting only the exact traffic an application needs to function, then denying everything else. The challenge: discovering what 'exact' means without breaking the app. Most engineers either over-permit for safety or under-permit and spend weeks troubleshooting. This guide shows how to get it right the first time.

Start with application discovery, not guesswork

Before writing a single rule, you must know what the application actually needs. Guessing leads to either overly permissive rules or frustrated users. Use netstat, ss, or packet capture on a test instance to map all inbound and outbound connections. Document the source IP, destination IP, port, and protocol. If the app uses dynamic ports or DNS names, note that too.

# On Linux, capture established connections
ss -tpn | grep ESTAB

# On Windows, list listening ports and their processes
netstat -ano | findstr LISTENING

# Packet capture for bidirectional traffic
tcpdump -i eth0 -nn 'tcp or udp' -w app-traffic.pcap

Talk to the application owner or vendor. Ask for a network requirements document. Many vendors publish this; if not, it signals a maturity gap. Document dependencies: databases, APIs, authentication services, logging collectors, NTP, DNS. Each is a separate rule candidate.

Build rules in layers: deny-by-default foundation

Start with a deny-all default policy, then add explicit allow rules. This inverts the usual risk: you only permit what you know is needed. On most firewalls, this means setting the default action to 'deny' and building a whitelist.

Common mistakes that break applications

Testing and validation before production

Test in a staging environment that mirrors production topology. Run the full application workflow: login, data queries, file uploads, exports, integrations. Monitor for timeouts or connection resets. Use tcpdump or firewall logs to identify any blocked traffic. Adjust rules and repeat until all workflows succeed and no legitimate traffic is denied.

# Test connectivity from app server to database
nc -zv database-server.local 5432

# Verify DNS resolution works
nslookup api.example.com

# Check for dropped packets (if firewall supports ICMP unreachable)
ping -c 4 blocked-destination.local

After deployment, monitor firewall logs for the first week. Legitimate denied traffic often surfaces after go-live when real users exercise edge cases. Adjust rules quickly, but always log and review before permitting new traffic.

Documentation and maintenance

Document every rule with its purpose, owner, and approval date. Include the application name, business justification, and any vendor references. This prevents rule decay: when someone asks 'why does this rule exist?', you have an answer. Schedule quarterly reviews to remove obsolete rules and update documentation.

Port Reference
Free tool to look up common application ports and protocols
Open →
Practise this on today’s Daily Ops Drill — a free network task every day.
Open the app →
Free tools for this
More from the blog
Subnetting on the Fortinet NSE4 exam: what to expectRead →Auditing an ACL for the permit any that should not be thereRead →