Least privilege

Replace a rule that is too wide

Lesson 7 of 20 · 12 min · Module 2: Rule sets you can maintain

"Allow everything from the office to the servers" makes every complaint go away. It also gives every infected laptop a path to the database.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • List the flows a wide rule was really serving
  • Write one narrow rule per flow
  • Verify that the unneeded access is gone

The idea

Least privilege means each source gets the services it needs and nothing more. You replace one wide rule with a few narrow ones, built from a list of the traffic that is actually required.

# before
allow any from lan to servers
# after
allow tcp from lan to web port 443
allow udp from lan to dns port 53

01Start from what is needed

Ask the owners, and read the logs of the wide rule: which sources talk to which servers, on which ports? In this office: the website over HTTPS, the file server over SMB (tcp 445), DNS over udp 53, and ping from the administrator for monitoring.

02Write one narrow rule per need

Each need becomes a rule with the smallest source, a single destination server, and the exact protocol and port. Everything the wide rule also allowed, such as the database port, is simply no longer mentioned, and the default deny takes it.

03Test both sides of the change

A good check proves two things: the needed traffic still passes, and the traffic that should stop does stop. On a production firewall you would first add the narrow rules above the wide one, watch the wide rule stop getting hits, and only then remove it.

Your turn

Replace the wide rule with four narrow ones. lan needs: the website on web (tcp 443), the file server files (tcp 445), and DNS on dns (udp 53). The administrator admin needs to ping (icmp) all of servers. Nothing else may pass.

What the checks look for

  • The four needed services still work
  • The database is no longer reachable from the office
  • Ping is for the administrator only
  • Each service is limited to its own server and port
Try it in the editor →

Take this with you

Replace wide rules from evidence: list the real flows, write one narrow rule for each, and test that the rest is closed.

Go a little further

Narrow the administrator ping so it reaches only the database server, and decide whether monitoring would still be useful that way.

Learn Firewall Foundations for free

20 short lessons with real code and instant checks.

See the whole course →