fireman.model#
Models for fireman tool.
- class fireman.model.AddressGroup(*, name, include, exclude=(), kind='address')#
A named group of address objects or address groups.
- 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.
- 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.
relatedsays which. The implicit deny never makes a rule redundant, so explicit deny rules before it are not flagged. A rule that matches nothing isEMPTYinstead.
- 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.classifyfound, and which firewalls it took from the cache.- policies#
Findings per policy, in inventory order.
- Type:
tuple[PolicyFindings, …]
- class fireman.model.Coverage(*, action, covered, granted, missing)#
Whether a policy already gives a request its action, and who decides what.
- class fireman.model.CoveredRequest(*, name, coverage)#
One request and whether the policy already gives it its action.
- class fireman.model.Decision(*, rule, traffic)#
Part of the request and the rule that decides it.
- rule#
Deciding rule, the implicit deny (
RuleId()) included;Nonewhen no rule matches (possible without an implicit deny).- Type:
RuleId | None
- traffic#
That part of the request.
- Type:
- class fireman.model.Finding(*, rule, anomaly, related)#
One anomaly of one rule.
- 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
globalis reserved for the global scope. Instances are immutable and hashable, and unknown fields are rejected.- rule_problems(kinds)#
Check rules use address names or literals in sources and destinations, service names or entries in services.
- 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.
- addresses#
1-100 IPv4 addresses or networks from the snapshot. Without one the name can’t be analysed, so it is rejected.
- 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.
- 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.
- icmp_type#
ICMP type, 0 to 255 (e.g. 8 is echo request).
Nonematches every type.- Type:
IcmpValueT | None
- icmp_code#
ICMP code, 0 to 255.
Nonematches every code oficmp_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
afterto right before rulebeforehas the same effect.- kind#
Always
"insert".- Type:
Literal[‘insert’]
- left#
Part of the request that still won’t get the action.
- Type:
- 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.
- exception fireman.model.InventoryError(issues)#
The cross-object checks of an
Inventoryfailed.The message is the full text, one problem per line.
problemsholds 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.
- kind#
addressorservice.- Type:
Literal[‘address’, ‘service’]
- 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, …]
- 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.
- cycle_problems()#
Check the groups form no cycles and nest at most
MAX_GROUP_DEPTHdeep.Both
includeandexcludecount. Only names defined here are edges: a name that points at the global scope can never point back.
- 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,
ANYor address literals such as10.0.0.0/24. Services are names,ANYor 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.- 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.
- class fireman.model.Placement(*, action, granted, missing, options)#
Where a request stands and how to make the policy give it the action.
- class fireman.model.Policy(*, name, rules=())#
A named, ordered collection of rules.
Rule
order_idmust 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.
- class fireman.model.PolicyFindings(*, firewall, policy, findings, cached=False)#
The findings of one policy.
- class fireman.model.PortEntry(*, protocol, ports)#
A port-based protocol (TCP, UDP, DCCP or SCTP) with a port range.
- ports#
Inclusive
(low, high)port range, each 0 to 65535. A single port is(80, 80).- Type:
- class fireman.model.Problem(*, resource, index, loc=(), message, scope=None)#
One thing wrong with the input.
- class fireman.model.ProtocolEntry(*, protocol)#
Any other IP protocol, matched by number alone (e.g. 47 for GRE).
- 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_idorder.sourcesanddestinationshold names of address objects or groups, or address literals such as10.0.0.0/24.servicesholds 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 nameANYmatches 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.- services#
Service names or entries, may include
ANY.- Type:
tuple[ServiceRefT, …]
Negating a list that contains
ANYwould match nothing, so it is rejected.
- class fireman.model.RuleId(*, order_id=None, name=None)#
A rule as the firewall knows it, never as a position.
Both
Noneis the implicit deny.
- class fireman.model.RuleUse(*, firewall, policy, order_id, name=None, via=None)#
A rule that uses a name.
- class fireman.model.ServiceGroup(*, name, include, exclude=(), kind='service')#
A named group of service objects or service groups.
- 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.
- entries#
1 to 100 entries. Each is a
PortEntry,IcmpEntryorProtocolEntry, chosen by itsprotocol.- Type:
tuple[ServiceEntryT, …]
- class fireman.model.TrafficSet(bdd, node)#
A set of traffic, stored as one BDD over the
src,dst,portandprotocolaxes.Build a set with
from_blocks(). An axis the set does not constrain matches every value. Sets combine withunion(),intersection()anddifference(), or the operators|,&and-; both sides must come from the sameBDD. Instances are immutable and hashable, andreprshows the traffic as text.- node#
BDD that is true for every packet in the set.
- Type:
oxidd.bdd.BDDFunction
- 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.
ANYanywhere 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 validatedAddressObject.valuesandServiceObject.entries; nothing is parsed.- Parameters:
bdd (BDD) – Manager to build the set in.
sources (Sequence[IPv4Address | IPv4Network | AnyT]) – Source addresses and networks, or
ANY.destinations (Sequence[IPv4Address | IPv4Network | AnyT]) – Destination addresses and networks, or
ANY.services (Sequence[ServiceEntryT | AnyT]) – Service entries, or
ANY.
- Returns:
The traffic set.
- Raises:
ValueError – If an axis holds a string other than
ANY.- Return type:
- 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:
- 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:
- 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:
- project(axis)#
Keep only
axisand 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:
- 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 thanself | other.- Parameters:
other (TrafficSet) – Set whose values to add, from the same BDD.
- Returns:
The product of the per-axis unions.
- Return type:
- 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.
ANYis 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
nameas seen fromscope: 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
nameas seen fromscope, directly or through groups.Each hit keeps the nearest group it reached the name through.
- 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’]
- left#
Part of the request that still won’t get the action.
- Type:
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.valuesitems.
- 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 likeServiceObject.entriesitems.
- 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 = intIn 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.
- class fireman.model.catalog.RuleRef(firewall, policy, order_id)#
A rule that references an object.
- 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:
- by_set#
Names in this scope that share each traffic set, in definition order.
- used_by_group#
Groups that reference each name; only used names appear.