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 theresolverfield.- catalogs#
Catalog per scope:
Nonefor global, else the firewall name.
- rules#
Rules by
(firewall, policy), sorted byorder_id, sorules[key][i]is the rule behindpolicies[key].states[i].
- request(firewall, sources, destinations, services)#
Turn a request’s values into one traffic set, ready for
place.Address values are
ANY, a name visible fromfirewall(its own objects first, then global ones) or an address or network literal, validated likeAddressObject.values; a name wins over a literal that looks the same. Service values areANY, a visible service name or a service entry. Each list is unioned, then the three are intersected.- Parameters:
- Returns:
The requested traffic.
- Raises:
KeyError – If
firewallis unknown.ValueError – If any value is unknown or has the wrong kind. One line per problem, led by its field (
sources: ...).
- Return type:
- 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:
- Returns:
Catalogs, compiled policies and the rules sorted by
order_id.- Return type:
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.
- traffic#
Traffic the rule matches.
- Type:
- class fireman.core.compiled.State(accept, deny, effective, residual, rule, id)#
Traffic totals after one rule.
- accept#
Traffic accepted so far.
- Type:
- deny#
Traffic denied so far.
- Type:
- effective#
Traffic this rule decided.
- Type:
- residual#
Traffic no rule has matched yet.
- Type:
- rule#
The rule itself.
- Type:
- class fireman.core.compiled.CompiledPolicy(bdd, rules, universe=None, implicit_deny=True)#
Walks a policy’s rules in order, built in one BDD manager.
- universe#
Traffic to consider;
Nonemeans all traffic.- Type:
TrafficSet | None
- implicit_deny#
Add a final deny-all rule, as most firewalls do. It gets its own
Stateat the end ofstates.- Type:
- is_covered(rule)#
Whether the policy already gives all of
rule’s traffic the same action.Checked against the last state, so
ruleneed not be in the policy: it answers “is this already allowed (or blocked)?”. Traffic no rule decides, possible withimplicit_deny=False, is not covered. Traffic outsideuniverseis ignored.- Parameters:
rule (TrafficRule) – Rule to check, built in
bdd.- Returns:
True if every packet of
trafficalready getsaction.- Return type:
- 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:
- 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: