Metadata-Version: 2.4
Name: fireman
Version: 0.1.1
Summary: Find shadowed, redundant, correlated and generalizing rules in firewall policies, and where new rules belong. Based on the FIREMAN paper.
Keywords: firewall,firewall-policy,network-security,anomaly-detection,bdd,fireman
Author: Jay
Author-email: Jay <opossum-assists2j@icloud.com>
License-Expression: AGPL-3.0-only
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Security
Classifier: Topic :: System :: Networking :: Firewalls
Requires-Dist: alembic>=1.20.1
Requires-Dist: click>=8.5.1
Requires-Dist: fqdn>=1.6.0
Requires-Dist: oxidd>=0.13.0
Requires-Dist: pydantic>=2.14.3
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: rich>=15.0.0
Requires-Dist: sqlalchemy>=2.1.9
Requires-Python: >=3.12
Project-URL: Documentation, https://horusthesonofosiris.github.io/fireman/
Project-URL: Source, https://github.com/HorusTheSonOfOsiris/fireman
Project-URL: Issues, https://github.com/HorusTheSonOfOsiris/fireman/issues
Description-Content-Type: text/markdown

# Fireman

Firewall modelling and analysis, built on the FIREMAN paper.

Fireman reads your firewall policies and points at the rules that don't do what
they seem to. Each policy is walked in order with every rule turned into an
exact set of packets, so overlaps between address ranges, groups, port ranges
and negated fields are worked out, never guessed.

## What it finds

- **Shadowed**: the rule never fires, and earlier rules give some of its traffic
  the other action. Usually a mistake.
- **Redundant**: removing the rule changes nothing, because earlier rules already
  give its traffic the same action, or later rules would once it is gone.
- **Correlated**: the rule overlaps an earlier rule with the other action, so
  their order decides what the overlap gets.
- **Generalization**: the rule also contains the whole of that earlier rule, a
  narrow exception before a broad rule. Often intended, worth a look.
- **Empty**: the rule matches no traffic, for example through a group that
  excludes everything it includes.

It also answers the everyday questions: is this traffic already allowed
(`fireman covered`), where would a new rule go (`fireman place`), and what uses
this object (`fireman usage`).

## Install

Fireman needs Python 3.13 or newer. For the `fireman` command, install it as a
tool:

```sh
uv tool install fireman     # or: pipx install fireman
fireman --help
```

To use it from your own Python code, add it to your project instead:

```sh
uv add fireman              # or: pip install fireman
```

## Quickstart

Download the sample estate (one firewall, two policies), load it, then
classify it:

```sh
curl -O https://raw.githubusercontent.com/HorusTheSonOfOsiris/fireman/main/docs/examples/estate.yaml
fireman load estate.yaml
fireman classify
```

```text
Loaded workspace 'default': 1 firewalls, 2 policies, 10 rules, 10 objects.
                                                Findings
┏━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Firewall ┃ Policy  ┃ Rule                              ┃ Anomaly        ┃ Related                     ┃
┡━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ edge     │ inbound │ allow-web (order_id 20)           │ generalization │ block-abusers (order_id 10) │
│ edge     │ inbound │ allow-web (order_id 20)           │ correlated     │ block-abusers (order_id 10) │
│ edge     │ inbound │ allow-partner-https (order_id 30) │ redundant      │ allow-web (order_id 20)     │
│ edge     │ inbound │ block-scanners (order_id 40)      │ shadowed       │ allow-web (order_id 20)     │
│ edge     │ inbound │ allow-partner-api (order_id 50)   │ redundant      │ allow-web (order_id 20)     │
└──────────┴─────────┴───────────────────────────────────┴────────────────┴─────────────────────────────┘
```

`load` validates the file and keeps it as a workspace in `.fireman/` in the
current directory. Every other command reads from there, so you load once and
ask many questions. The `outbound` policy is clean, so it has no rows.

## From Python

The same models back the files, so you can build a policy in code, compile it
and classify it:

```python
import click

from fireman import BDDManager, compile_inventory
from fireman.model import Firewall, Inventory, Policy, Rule

https = {"protocol": 6, "ports": [443, 443]}
rules = [
    Rule(
        order_id=10,
        name="allow-lan",
        action="accept",
        sources=["10.0.0.0/8"],
        destinations=["any"],
        services=[https],
    ),
    Rule(
        order_id=20,
        name="block-guests",
        action="deny",
        sources=["10.9.0.0/16"],
        destinations=["any"],
        services=[https],
    ),
]
policy = Policy(name="outbound", rules=rules)
inventory = Inventory(firewalls=[Firewall(name="edge", policies=[policy])])

compiled = compile_inventory(inventory, BDDManager(nodes=1 << 20, cache=1 << 18, threads=1))
for finding in compiled.policies["edge", "outbound"].classify():
    click.echo(f"{finding.rule.name} {finding.anomaly} {[r.name for r in finding.related]}")
```

```text
block-guests shadowed ['allow-lan']
```

To read files instead, `fireman.Pipeline().load(fireman.yaml_file(path))` gives
the same `Inventory`.

## Links

- Source and issues: <https://github.com/HorusTheSonOfOsiris/fireman>
- Docs: <https://horusthesonofosiris.github.io/fireman/>
- The FIREMAN paper: Yuan et al., "FIREMAN: A Toolkit for FIREwall Modeling and
  ANalysis", IEEE Symposium on Security and Privacy, 2006.

## License

Fireman is licensed under the GNU Affero General Public License v3.0. See
[LICENSE](https://github.com/HorusTheSonOfOsiris/fireman/blob/main/LICENSE).
