CJCCIE Journals

I Automated Our Firewall Rule Review: Finding Shadowed, Permissive and Unused Rules with Python

AutomationNetwork securityTroubleshooting CCIE journals · November 25, 2026

My team reviewed firewall rules by hand for years. A small Python script now produces the first draft of the review in minutes.

Every quarter, someone on the team would open each firewall's rule base and go line by line looking for risky rules. It took days, it was boring, and results depended on who did it. So I automated the first pass.

I Automated Our Firewall Rule Review: Finding Shadowed, Permissive and Unused Rules with Python

What the script looks for

  • Overly permissive rules: any source, any destination, or any service, or very large subnets (say /8 to /16) as source or destination.
  • Shadowed rules: a rule that can never match because an earlier rule with the same or broader match already catches all its traffic.
  • Unused rules: zero hit count over the review period.
  • Hygiene: rules without comments, disabled rules nobody cleaned up, duplicate objects.

How it works

  1. Export the running config and hit counts from each firewall.
  2. Parse objects and object-groups into Python sets using the ipaddress module.
  3. Normalize every rule into (source set, destination set, service set, action).
  4. Compare each rule against every earlier rule: if A ⊇ B on all three dimensions, B is shadowed.
  5. Write the results to Excel with one sheet per firewall and a summary sheet.
rule-review.py — output output (lab recreation)

A tiny piece of the logic

import ipaddress

def covers(a_nets, b_nets):
    # True if every network in b is inside some network in a
    return all(any(b.subnet_of(a) for a in a_nets) for b in b_nets)

def is_shadowed(earlier, rule):
    return (covers(earlier.src, rule.src) and
            covers(earlier.dst, rule.dst) and
            rule.svc <= earlier.svc)

Results

The first run flagged dozens of shadowed rules and many unused ones on just two firewalls. Humans still decide what gets removed; the script just gives everyone the same starting point in minutes instead of days.

Tips if you build your own

  • Start with one vendor and one firewall. Parsing is 80% of the work.
  • Keep hit-count windows long enough to cover quarter-end and year-end jobs.
  • Never auto-delete. Report, review, then change through normal change control.

Note: device names, IP addresses, AS numbers and user names in this post are pseudonyms or lab values. The problem and the fix are real.

CJ

Written by CCIE journals

Network security engineer sharing hands-on notes from the journey to CCIE.

0 Comments

Post a Comment

Ready to level up your networking career?

Meet the Author →

Welcome to my blog, dedicated to network and security engineering enthusiasts. Here, you can learn about various vendors and gain valuable insights and resources to excel in the field of network engineering!