fireman.model#

Models for fireman tool.

class fireman.model.AddressGroup(*, name, include, exclude=(), kind='address')#

A named group of address objects or address groups.

name#

Name of the group.

Type:

NameT

include#

1 to 100 unique address names it matches.

Type:

tuple[NameT, …]

exclude#

0 to 100 unique address names taken back out. Defaults to none.

Type:

tuple[NameT, …]

kind#

Always "address".

Type:

Literal[‘address’]

class fireman.model.AddressObject(*, name, values)#

A named group of IPv4 addresses and networks.

Instances are immutable and hashable, and unknown fields are rejected.

name#

Name of the object, 1 to 1024 characters with no leading or trailing whitespace.

Type:

NameT

values#

1 to 100 IPv4 addresses or networks, as ipaddress objects or strings. Networks must not have host bits set: 10.0.0.0/24 is valid, 10.0.0.1/24 is rejected. IPv6 is rejected.

Type:

tuple[IPValueT, …]

class fireman.model.Anomaly#

What can be wrong with one rule.

SHADOWED#

Never fires, and earlier rules give some of its traffic the other action.

REDUNDANT#

Removing it changes nothing. Earlier rules already give its traffic the same action, or later explicit rules would without it. related says which. The implicit deny never makes a rule redundant, so explicit deny rules before it are not flagged. A rule that matches nothing is EMPTY instead.

CORRELATED#

Overlaps an earlier rule with the other action.

GENERALIZATION#

Wholly contains an earlier rule with the other action; always correlated too.

EMPTY#

Matches no traffic, e.g. a group whose exclude covers its include. Its only finding.

class fireman.model.Classification(*, policies, cached)#

What Pipeline.classify found, and which firewalls it took from the cache.

policies#

Findings per policy, in inventory order.

Type:

tuple[PolicyFindings, …]

cached#

Names of the firewalls read from the store, in inventory order; a firewall without policies counts too.

Type:

tuple[str, …]

class fireman.model.Coverage(*, action, covered, granted, missing)#

Whether a policy already gives a request its action, and who decides what.

action#

Action the request wants.

Type:

ActionT

covered#

Every part of the request already gets it.

Type:

bool

granted#

Parts that get it, by deciding rule.

Type:

tuple[Decision, …]

missing#

Parts that don’t, by deciding rule (None when undecided).

Type:

tuple[Decision, …]

class fireman.model.CoveredRequest(*, name, coverage)#

One request and whether the policy already gives it its action.

name#

The request’s name; None if it has none.

Type:

str | None

coverage#

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

Type:

Coverage

class fireman.model.Decision(*, rule, traffic)#

Part of the request and the rule that decides it.

rule#

Deciding rule, the implicit deny (RuleId()) included; None when no rule matches (possible without an implicit deny).

Type:

RuleId | None

traffic#

That part of the request.

Type:

tuple[FormattedTraffic, …]

class fireman.model.Finding(*, rule, anomaly, related)#

One anomaly of one rule.

rule#

The rule.

Type:

RuleId

anomaly#

What is wrong.

Type:

Anomaly

related#

The rules involved; never the implicit deny.

Type:

tuple[RuleId, …]

class fireman.model.Firewall(*, name, objects=Objects(addresses=(), fqdns=(), services=(), groups=()), policies=())#

A firewall: its own objects, which override global ones by name, and its policies.

Policy names must be unique, and global is reserved for the global scope. Instances are immutable and hashable, and unknown fields are rejected.

name#

Name of the firewall.

Type:

NameT

objects#

Objects that override global ones of the same name.

Type:

Objects

policies#

Policies of this firewall.

Type:

tuple[Policy, …]

rule_problems(kinds)#

Check rules use address names or literals in sources and destinations, service names or entries in services.

Parameters:

kinds (Mapping[str, str]) – Kind of every name visible to this firewall.

Returns:

A (policy name, message) pair per problem.

Return type:

list[tuple[str, str]]

class fireman.model.FqdnObject(*, name, fqdn, addresses, resolved_at=None)#

A named domain name with the addresses it resolved to.

The addresses are a snapshot the firewall or user resolved: fireman never looks names up. Instances are immutable and hashable, and unknown fields are rejected.

name#

Name of the object, used in rules and groups like an address object.

Type:

NameT

fqdn#

The domain name, kept as written.

Type:

FqdnT

addresses#

1-100 IPv4 addresses or networks from the snapshot. Without one the name can’t be analysed, so it is rejected.

Type:

tuple[IPValueT, …]

resolved_at#

When the snapshot was taken, timezone-aware.

Type:

AwareDatetime | None

class fireman.model.GroupUse(*, scope, name, via=None)#

A group that uses a name.

scope#

Firewall defining the group, None for global.

Type:

ScopeT

name#

Group name.

Type:

str

via#

Group it reached the name through, None if it uses it directly.

Type:

str | None

class fireman.model.IcmpEntry(*, protocol, icmp_type=None, icmp_code=None)#

ICMP traffic, optionally of one type and code.

A code needs a type: a code on its own is rejected.

protocol#

Always 1 (ICMP).

Type:

int

icmp_type#

ICMP type, 0 to 255 (e.g. 8 is echo request). None matches every type.

Type:

IcmpValueT | None

icmp_code#

ICMP code, 0 to 255. None matches every code of icmp_type.

Type:

IcmpValueT | None

class fireman.model.Insert(*, kind='insert', after, before, overrides, left)#

Add a new rule for the request.

Any spot from right after rule after to right before rule before has the same effect.

kind#

Always "insert".

Type:

Literal[‘insert’]

after#

Earliest spot, right after this rule; None is the top.

Type:

RuleId | None

before#

Latest spot, right before this rule; None is the end.

Type:

RuleId | None

overrides#

Rules that lose traffic to the new rule.

Type:

tuple[RuleId, …]

left#

Part of the request that still won’t get the action.

Type:

tuple[FormattedTraffic, …]

class fireman.model.Inventory(*, objects=Objects(addresses=(), fqdns=(), services=(), groups=()), firewalls=())#

Everything in one place: global objects and the firewalls that use them.

A name used in a firewall resolves to that firewall’s own object first, else the global one. A global group only sees global objects, so a firewall override never changes it. Checks what a single model cannot and reports every problem together, one per line: unique firewall names, unknown names and wrong kinds in rules and groups, overrides that change a name’s kind, and group cycles and nesting depth per scope.

objects#

Global objects.

Type:

Objects

firewalls#

Firewalls, each with its own overrides and policies.

Type:

tuple[Firewall, …]

exception fireman.model.InventoryError(issues)#

The cross-object checks of an Inventory failed.

The message is the full text, one problem per line. problems holds the same problems with their scope set and that part left out of the message.

problems#

One problem per line of the message.

class fireman.model.NameUsage(*, scope, name, kind, groups, rules)#

Everything that uses one name, directly or through groups.

scope#

Scope that defines the name, None for global.

Type:

ScopeT

name#

The name.

Type:

str

kind#

address or service.

Type:

Literal[‘address’, ‘service’]

groups#

Groups using it, sorted by scope and name.

Type:

tuple[GroupUse, …]

rules#

Rules using it, sorted by firewall, policy and order_id.

Type:

tuple[RuleUse, …]

class fireman.model.Objects(*, addresses=(), fqdns=(), services=(), groups=())#

A set of address objects, FQDN objects, service objects and groups.

Names are unique across all four lists, and none is ANY. Instances are immutable and hashable, and unknown fields are rejected.

addresses#

Address objects.

Type:

tuple[AddressObject, …]

fqdns#

FQDN objects; they act as address objects.

Type:

tuple[FqdnObject, …]

services#

Service objects.

Type:

tuple[ServiceObject, …]

groups#

Address and service groups.

Type:

tuple[GroupT, …]

property kinds: Mapping[str, str]#

Read-only map of each object and group name to "address" or "service".

group_problems(kinds)#

Check groups reference only existing names of their own kind, resolved in kinds.

Parameters:

kinds (Mapping[str, str]) – Kind of every name visible in this scope.

Returns:

One message per problem.

Return type:

list[str]

cycle_problems()#

Check the groups form no cycles and nest at most MAX_GROUP_DEPTH deep.

Both include and exclude count. Only names defined here are edges: a name that points at the global scope can never point back.

Returns:

One message if a cycle or a too deep chain exists, else none.

Return type:

list[str]

class fireman.model.PlaceRequest(*, name=None, action=None, sources, destinations, services)#

A request to give some traffic an action in a policy.

Sources and destinations are names, ANY or address literals such as 10.0.0.0/24. Services are names, ANY or entries such as {"protocol": 6, "ports": [443, 443]}. Nothing is resolved here: that needs the inventory. Instances are immutable and hashable, and unknown fields are rejected.

name#

Optional label for the request.

Type:

NameT | None

action#

"accept" or "deny"; None leaves it to the caller’s default.

Type:

ActionT | None

sources#

1 to 100 unique source values.

Type:

RuleRefsT

destinations#

1 to 100 unique destination values.

Type:

RuleRefsT

services#

1 to 100 unique service names or entries.

Type:

tuple[ServiceRefT, …]

class fireman.model.PlacedRequest(*, name, placement)#

One request and where it stands in the policy.

name#

The request’s name; None if it has none.

Type:

str | None

placement#

What is granted, what is missing and the options.

Type:

Placement

class fireman.model.Placement(*, action, granted, missing, options)#

Where a request stands and how to make the policy give it the action.

action#

Action the request wants.

Type:

ActionT

granted#

Parts of the request that already get it, by deciding rule.

Type:

tuple[Decision, …]

missing#

Parts that don’t yet, by deciding rule, in policy order.

Type:

tuple[Decision, …]

options#

Ways to change that, best first: whole request granted, then fewest overrides, then widening before inserting, then policy order. Empty when nothing is missing.

Type:

tuple[OptionT, …]

class fireman.model.Policy(*, name, rules=())#

A named, ordered collection of rules.

Rule order_id must be unique within the policy, and so must rule names (a rule may have none); every problem is collected and reported together, one per line. Names used by rules are checked in the inventory, where all objects are known. Instances are immutable and hashable, and unknown fields are rejected.

name#

Name of the policy.

Type:

NameT

rules#

Rules, matched in order_id order. Defaults to none.

Type:

tuple[Rule, …]

class fireman.model.PolicyFindings(*, firewall, policy, findings, cached=False)#

The findings of one policy.

firewall#

Firewall the policy belongs to.

Type:

str

policy#

Policy name.

Type:

str

findings#

Its findings, in rule order.

Type:

tuple[Finding, …]

cached#

Whether they were read from the findings store instead of computed.

Type:

bool

class fireman.model.PortEntry(*, protocol, ports)#

A port-based protocol (TCP, UDP, DCCP or SCTP) with a port range.

protocol#

6 (TCP), 17 (UDP), 33 (DCCP) or 132 (SCTP).

Type:

int

ports#

Inclusive (low, high) port range, each 0 to 65535. A single port is (80, 80).

Type:

PortRangeT

class fireman.model.Problem(*, resource, index, loc=(), message, scope=None)#

One thing wrong with the input.

resource#

A resource name, a file path, or "inventory".

Type:

str

index#

Item position within its resource, or None if not tied to one item.

Type:

int | None

loc#

Field path, as in pydantic’s errors().

Type:

tuple[str | int, …]

message#

What went wrong.

Type:

str

scope#

Where the resource lives (edge/inbound), or None for file-level problems.

Type:

str | None

class fireman.model.ProtocolEntry(*, protocol)#

Any other IP protocol, matched by number alone (e.g. 47 for GRE).

protocol#

IANA protocol number, 0 to 255, excluding the port protocols and ICMP, which have their own entry types, and IPv6-only protocols (43, 44, 58, 59, 60, 135, 140).

Type:

int

class fireman.model.Rule(*, order_id, name=None, action, description='', sources, destinations, services, source_negate=False, destination_negate=False, service_negate=False)#

A firewall rule, matched in order_id order.

sources and destinations hold names of address objects or groups, or address literals such as 10.0.0.0/24. services holds service names or entries such as {"protocol": 6, "ports": [443, 443]}. Each list matches the union of its items; a name wins over a literal that looks the same. The reserved name ANY matches everything, so a list containing it matches everything even if it also names other objects. Such lists are stored as written; the redundant names are reported by analysis, not rejected here. Whether names exist and have the right kind (and whether other strings are valid literals) is checked where all objects are known. Instances are immutable and hashable, and unknown fields are rejected.

order_id#

Position of the rule in its policy, 0 or more; lower is matched first.

Type:

int

name#

Name of the rule, if the firewall has one. Defaults to none.

Type:

NameT | None

action#

"accept" or "deny".

Type:

ActionT

description#

Free text, up to 1024 characters. Defaults to empty.

Type:

str

sources#

Address names or literals, may include ANY.

Type:

RuleRefsT

destinations#

Address names or literals, may include ANY.

Type:

RuleRefsT

services#

Service names or entries, may include ANY.

Type:

tuple[ServiceRefT, …]

source_negate#

Match every source except sources.

Type:

bool

destination_negate#

Match every destination except destinations.

Type:

bool

service_negate#

Match every service except services.

Type:

bool

Negating a list that contains ANY would match nothing, so it is rejected.

property label: str#

How messages name the rule, 'name' in quotes or else its order_id.

class fireman.model.RuleId(*, order_id=None, name=None)#

A rule as the firewall knows it, never as a position.

Both None is the implicit deny.

order_id#

The rule’s order_id; None for the implicit deny.

Type:

int | None

name#

The rule’s name; None if it has none.

Type:

str | None

class fireman.model.RuleUse(*, firewall, policy, order_id, name=None, via=None)#

A rule that uses a name.

firewall#

Firewall the rule belongs to.

Type:

str

policy#

Policy the rule belongs to.

Type:

str

order_id#

order_id of the rule.

Type:

int

name#

Rule name, None if it has none.

Type:

str | None

via#

Group it reached the name through, None if it uses it directly.

Type:

str | None

class fireman.model.ServiceGroup(*, name, include, exclude=(), kind='service')#

A named group of service objects or service groups.

name#

Name of the group.

Type:

NameT

include#

1 to 100 unique service names it matches.

Type:

tuple[NameT, …]

exclude#

0 to 100 unique service names taken back out. Defaults to none.

Type:

tuple[NameT, …]

kind#

Always "service".

Type:

Literal[‘service’]

class fireman.model.ServiceObject(*, name, entries)#

A named group of service entries.

Instances are immutable and hashable, and unknown fields are rejected.

name#

Name of the object, 1 to 1024 characters with no leading or trailing whitespace.

Type:

NameT

entries#

1 to 100 entries. Each is a PortEntry, IcmpEntry or ProtocolEntry, chosen by its protocol.

Type:

tuple[ServiceEntryT, …]

class fireman.model.TrafficSet(bdd, node)#

A set of traffic, stored as one BDD over the src, dst, port and protocol axes.

Build a set with from_blocks(). An axis the set does not constrain matches every value. Sets combine with union(), intersection() and difference(), or the operators |, & and -; both sides must come from the same BDD. Instances are immutable and hashable, and repr shows the traffic as text.

bdd#

Manager the set was built in. Not part of equality.

Type:

BDD

node#

BDD that is true for every packet in the set.

Type:

oxidd.bdd.BDDFunction

property is_empty: bool#

Whether the set holds no traffic.

classmethod everything(bdd)#

Return the set of all traffic.

classmethod nothing(bdd)#

Return the empty set.

classmethod from_blocks(bdd, sources, destinations, services)#

Build the set of traffic from any source, to any destination, matching any service.

Each axis is the union of its values, and the axes are intersected. ANY anywhere in an axis leaves that axis free. An empty sequence is still an empty union, so the result is the empty set. Values are the already validated AddressObject.values and ServiceObject.entries; nothing is parsed.

Parameters:
Returns:

The traffic set.

Raises:

ValueError – If an axis holds a string other than ANY.

Return type:

TrafficSet

union(other)#

Return the traffic in either set.

Parameters:

other (TrafficSet) – Set to combine with, from the same BDD.

Returns:

The union of both sets.

Return type:

TrafficSet

intersection(other)#

Return the traffic in both sets.

Parameters:

other (TrafficSet) – Set to combine with, from the same BDD.

Returns:

The intersection of both sets.

Return type:

TrafficSet

difference(other)#

Return the traffic in this set but not in other.

Parameters:

other (TrafficSet) – Set to remove, from the same BDD.

Returns:

This set minus other.

Return type:

TrafficSet

project(axis)#

Keep only axis and leave the others free.

Exact for a product of axes, which every from_blocks() set is. "service" keeps port and protocol together, since ICMP stores type and code in the port bits.

Parameters:

axis (Literal['src', 'dst', 'service']) – Axis to keep.

Returns:

The set’s values on axis, with every other axis unconstrained.

Return type:

TrafficSet

widen(other)#

Return this set with other’s values added to each axis.

Like adding other’s sources, destinations and services to a rule’s fields, so the result can hold more than self | other.

Parameters:

other (TrafficSet) – Set whose values to add, from the same BDD.

Returns:

The product of the per-axis unions.

Return type:

TrafficSet

property rows: tuple[FormattedTraffic, ...]#

The set as formatted rows, computed once per instance.

class fireman.model.Usage(inventory)#

Name resolution and usage of a validated inventory. Trusts the inventory, runs no BDD.

A firewall sees its own objects first, then global ones; a global group only sees global objects. ANY is never a name.

property defined: dict[ScopeT, dict[str, ObjectT]]#

Objects and groups by name, global under None, then each firewall.

owner(scope, name)#

Scope that defines name as seen from scope: itself if it has it, else global.

property by_group: Mapping[NodeT, frozenset[GroupRef]]#

Groups that name each (defining scope, name) in an include or exclude.

property by_rule: Mapping[NodeT, frozenset[RuleRef]]#

Rules that name each (defining scope, name) in sources, destinations or services.

of(scope, name)#

Groups and rules that use name as seen from scope, directly or through groups.

Each hit keeps the nearest group it reached the name through.

Parameters:
  • scope (ScopeT) – Firewall to look from, None for global.

  • name (str) – Object or group name.

Raises:

KeyError – If scope is not a known firewall or no object has that name.

class fireman.model.Widen(*, kind='widen', rule, overrides, left)#

Add the request’s values to an existing rule’s fields.

Only offered when that adds no traffic beyond the request.

kind#

Always "widen".

Type:

Literal[‘widen’]

rule#

Rule to widen.

Type:

RuleId

overrides#

Rules that lose traffic to the widened rule.

Type:

tuple[RuleId, …]

left#

Part of the request that still won’t get the action.

Type:

tuple[FormattedTraffic, …]

fireman.model.types#

Field types shared by the models above, and the aliases built from them.

Field types shared across models.

type fireman.model.types.NameT#

Object name: 1 to 1024 characters, no leading/trailing whitespace or line breaks.

type fireman.model.types.ActionT#

Rule action.

type fireman.model.types.RuleRefsT#

1 to 100 unique names or address literals, which may include ANY.

type fireman.model.types.PortRangeT#

Inclusive (low, high) port range, each 0 to 65535.

type fireman.model.types.IcmpValueT#

ICMP type or code, 0 to 255.

type fireman.model.types.IPValueT#

An IPv4 address or network. IPv6 is not supported.

type fireman.model.types.FqdnT#

A fully qualified domain name, kept as written.

fireman.model.types.ADDRESS_LITERAL#

Validates address literals exactly like AddressObject.values items.

fireman.model.group.GroupT#

An address or service group; the type is chosen from kind.

fireman.model.service_object.ServiceEntryT#

A service entry; the entry type is chosen from its protocol.

fireman.model.service_object.ServiceRefT#

A service name (or ANY), or a service entry written like ServiceObject.entries items.

fireman.model.placement.OptionT#

One way to give a request its action.

fireman.model.usage.ScopeT#

Type alias.

Type aliases are created through the type statement:

type Alias = int

In this example, Alias and int will be treated equivalently by static type checkers.

At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed.

Type aliases can also be generic:

type ListOrSet[T] = list[T] | set[T]

In this case, the type parameters of the alias are stored in the __type_params__ attribute.

See PEP 695 for more information.

fireman.model.catalog#

What one scope of a compiled inventory holds. Catalog is built by compile_inventory(), so it is documented here and not exported from fireman.model.

Catalog model.

class fireman.model.catalog.GroupRef(scope, name)#

A group that references an object.

scope#

Firewall name that defines the group, None for a global group.

Type:

str | None

name#

Name of the group.

Type:

str

class fireman.model.catalog.RuleRef(firewall, policy, order_id)#

A rule that references an object.

firewall#

Firewall the rule belongs to.

Type:

str

policy#

Policy the rule belongs to.

Type:

str

order_id#

order_id of the rule in that policy.

Type:

int

class fireman.model.catalog.Catalog(objects, sets, by_set, used_by_group, used_by_rule)#

The objects of one scope (global or one firewall), with their traffic sets and uses.

A use counts for the definition the name resolves to, so a global object lists every firewall that uses it, and an override takes over its firewall’s uses.

The catalog is read-only: fields cannot be reassigned, and each mapping is stored as a read-only view of a copy of the input. Mappings are not hashable, so catalogs compare and hash by identity.

objects#

Address, FQDN and service objects and groups defined in this scope, by name.

Type:

Mapping[str, AddressObject | FqdnObject | ServiceObject | GroupT]

sets#

Traffic set of each object or group, by name.

Type:

Mapping[str, TrafficSet]

by_set#

Names in this scope that share each traffic set, in definition order.

Type:

Mapping[oxidd.bdd.BDDFunction, tuple[str, …]]

used_by_group#

Groups that reference each name; only used names appear.

Type:

Mapping[str, frozenset[GroupRef]]

used_by_rule#

Rules that reference each name; only used names appear.

Type:

Mapping[str, frozenset[RuleRef]]