fireman.core#

The compiler and the compiled policy. The analyses classify, place, coverage and is_covered are methods of CompiledPolicy.

fireman.core.compiler#

Compile an inventory into catalogs and one compiled policy per firewall policy.

class fireman.core.compiler.CompiledInventory(bdd, catalogs, policies, rules, resolver)#

An inventory turned into catalogs and compiled policies.

Mappings are stored as read-only views of copies. request() resolves names through a private resolver, kept in the resolver field.

bdd#

Manager every traffic set was built in.

Type:

BDD

catalogs#

Catalog per scope: None for global, else the firewall name.

Type:

Mapping[ScopeT, Catalog]

policies#

Compiled policy by (firewall, policy).

Type:

Mapping[tuple[str, str], CompiledPolicy]

rules#

Rules by (firewall, policy), sorted by order_id, so rules[key][i] is the rule behind policies[key].states[i].

Type:

Mapping[tuple[str, str], tuple[Rule, …]]

request(firewall, sources, destinations, services)#

Turn a request’s values into one traffic set, ready for place.

Address values are ANY, a name visible from firewall (its own objects first, then global ones) or an address or network literal, validated like AddressObject.values; a name wins over a literal that looks the same. Service values are ANY, a visible service name or a service entry. Each list is unioned, then the three are intersected.

Parameters:
  • firewall (str) – Firewall whose names apply.

  • sources (Iterable[str]) – Source names or address literals.

  • destinations (Iterable[str]) – Destination names or address literals.

  • services (Iterable[TypeAliasForwardRef('fireman.model.service_object.ServiceRefT')]) – Service names or entries.

Returns:

The requested traffic.

Raises:
  • KeyError – If firewall is unknown.

  • ValueError – If any value is unknown or has the wrong kind. One line per problem, led by its field (sources: ...).

Return type:

TrafficSet

fireman.core.compiler.compile_inventory(inventory, bdd, *, implicit_deny=True)#

Resolve an inventory into catalogs and one compiled policy per firewall policy.

The inventory is trusted: names, kinds and cycles were checked by Inventory. A firewall sees its own objects first, then global ones; a global group only sees global objects.

Parameters:
  • inventory (Inventory) – Validated inventory.

  • bdd (BDD) – Manager to build every traffic set in.

  • implicit_deny (bool) – Add a final deny-all rule to each compiled policy.

Returns:

Catalogs, compiled policies and the rules sorted by order_id.

Return type:

CompiledInventory

fireman.core.compiled#

A policy compiled into BDD sets, plus its rule walk.

class fireman.core.compiled.TrafficRule(action, traffic, id=None, negated=False)#

One policy rule as the compiled policy sees it.

action#

What the rule does with matching traffic.

Type:

ActionT

traffic#

Traffic the rule matches.

Type:

TrafficSet

id#

How reports name it; without one the rule’s 1-based position stands in as order_id.

Type:

RuleId | None

negated#

A source, destination or service list is negated, so the rule can’t be widened.

Type:

bool

class fireman.core.compiled.State(accept, deny, effective, residual, rule, id)#

Traffic totals after one rule.

accept#

Traffic accepted so far.

Type:

TrafficSet

deny#

Traffic denied so far.

Type:

TrafficSet

effective#

Traffic this rule decided.

Type:

TrafficSet

residual#

Traffic no rule has matched yet.

Type:

TrafficSet

rule#

The rule itself.

Type:

TrafficRule

id#

How reports name the rule: its own id, else its 1-based position.

Type:

RuleId

class fireman.core.compiled.CompiledPolicy(bdd, rules, universe=None, implicit_deny=True)#

Walks a policy’s rules in order, built in one BDD manager.

bdd#

Manager every rule’s traffic set comes from.

Type:

BDD

rules#

Rules in policy order. Init only: states keeps each one.

Type:

InitVar[tuple[’fireman.core.compiled.TrafficRule’, …]]

universe#

Traffic to consider; None means all traffic.

Type:

TrafficSet | None

implicit_deny#

Add a final deny-all rule, as most firewalls do. It gets its own State at the end of states.

Type:

bool

states#

The running totals after each rule, walked once at init.

Type:

tuple[State, …]

is_covered(rule)#

Whether the policy already gives all of rule’s traffic the same action.

Checked against the last state, so rule need not be in the policy: it answers “is this already allowed (or blocked)?”. Traffic no rule decides, possible with implicit_deny=False, is not covered. Traffic outside universe is ignored.

Parameters:

rule (TrafficRule) – Rule to check, built in bdd.

Returns:

True if every packet of traffic already gets action.

Return type:

bool

classify()#

Find every anomaly in the policy, in rule order.

The implicit deny is never classified and never shows up in related.

Returns:

The findings, several per rule at most; a clean policy gives none.

Return type:

tuple[TypeAliasForwardRef(’fireman.model.Finding’), …]

coverage(rule)#

Check whether the policy already gives rule’s traffic its action.

Like place() without the options, so it is cheap.

Parameters:

rule (TrafficRule) – The request, built in bdd; need not be in the policy.

Returns:

Whether it is covered, and which rules decide each part.

Return type:

Coverage

place(rule)#

Find how to give rule’s traffic its action.

Parameters:

rule (TrafficRule) – The request, built in bdd; need not be in the policy.

Returns:

What is already granted, what is missing, and the options.

Return type:

Placement