Skip to content

Firewall inventory

Inventory

At every check in the agent reads the host firewall, without changing anything, and sends it when it changed (a hash, like the package list). Backend is the first found of a running firewalld, an active ufw, nftables and iptables:

  • firewalld: firewall-cmd --permanent --list-all-zones and --list-all-policies, one rule per interface or source binding, service, port, protocol, forward port and rich rule. The raw text is the firewall-cmd option that adds it.
  • ufw: ufw status verbose (default policies) and ufw show added.
  • nftables: nft -j list ruleset for the fields, nft -a list ruleset for the text and handle.
  • iptables: iptables-save and ip6tables-save, only when nothing else is there.

Beside ufw and firewalld the agent also lists the nftables tables (or iptables rules) they do not own, which is where Docker, libvirt and fail2ban put theirs. Each tool runs at most 20 seconds; the inventory holds up to 2000 rules.

Every rule has an origin: managed (added by LiMDM from this declaration, or in a table or firewalld zone of LiMDM itself: inet limdm on Alpine, inet limdm_fw of early agents, the policy limdm-egress), system or foreign. System rules belong to container, virtualization, VPN and intrusion prevention tools: names starting with docker, br-, veth, podman, cni, netavark, nv_, libvirt, virbr, kube, cali, flannel, cilium, weave, netbird, nb- (NetBird sets), tailscale, ts-, wg-quick, f2b-, fail2ban or crowdsec, or the VPN interfaces wt0 (NetBird) and zt... (ZeroTier), in table, chain, set, zone, interface, jump target, comment or text. Rules whose addresses lie in a subnet of a local container or VM bridge (docker0, br-, podman, cni, virbr; the agent reads them from the interface list, bridge_nets) are system rules too, which covers Docker's hairpin NAT and masquerade rules outside its chains. Rules an admin wrote for a wg* interface stay foreign: they cannot be told from wg-quick PostUp rules. System rules are shown and never adopted, kept or removed; the server classifies every rule again, also stored inventories when it reads them, and does not trust the agent's word. On a Docker host every Docker chain, the jumps into it and the rules for docker0 and br-* are system rules.

On the Firewall tab of a device an admin decides per foreign rule:

  • Adopt: the rule is added to a firewall library item (an existing one, or a new one with enforce off that is assigned in a blueprint the admin picks; the device's own blueprint is preselected unless it is the global default, the dialog shows how many devices the blueprint reaches and asks a second time for the global default or a blueprint that reaches more than this device; tenant admins see only the blueprints of their tenant) in this format: a port of the default zone goes to allow, a port with a source to rules, a port on an interface or in another firewalld zone (with that zone's interfaces and sources) to zones, an outbound allow rule to outbound.allow (only into an item that already has an outbound policy, so adopting never changes the device's outbound default). Deny rules, rules without TCP or UDP port and firewalld services without a known port cannot be adopted; the tab says why.
  • Exception: the rule's match (tool, place and text without counters or handles) is added to keep of a firewall item. The rule stays and is listed as accepted.
  • Discard: the rule's match is added to remove of a firewall item (the same dialog as adopt: existing item or a new one in a picked blueprint, a second confirmation for a rule that may cut SSH or the server). Every agent that gets the item deletes a matching foreign rule in every cycle, so a rule that comes back at boot or with a reload of the tool that added it goes again; the declaration status lists what was removed or left. Rules of LiMDM, of container, VPN and protection tools (also by bridge address) and rules listed in keep are never removed, even when listed: the server refuses such entries when the item is saved, and the agent checks the live rule again. With four eyes approval on, saving an item with a remove list waits for another administrator (a new item is refused then; pick an existing one). The removal uses ufw --force delete, firewall-cmd --permanent --remove-… plus --reload, nft delete rule … handle N or iptables -D.
  • The signed command firewall_remove_rule (API only, admins, four eyes) still removes one rule at once; with nftables and iptables that changes the running ruleset only, so a rule loaded at boot comes back unless it is also in a remove list.

Adopt, exception and discard are normal library saves (signature, version, audit) plus an audit entry firewall.adopt, firewall.keep or firewall.remove on the device.

After a reboot

What LiMDM applies stays in force after a reboot on every backend, and the agent applies everything again at its start anyway:

  • ufw: rules and defaults live in ufw's own files (/etc/ufw/user.rules, ufw.conf); ufw --force enable also enables it at boot.
  • firewalld: every change is made with --permanent and then --reload; the firewalld service is enabled.
  • nftables (Alpine): /etc/nftables.d/limdm.nft is loaded at boot by the distribution's nftables service when its main configuration includes /etc/nftables.d/*.nft and the service is enabled (checked from the files, no command). Otherwise the agent installs its own boot service limdm-firewall (systemd unit after nftables.service, or an OpenRC script after nftables) that loads only LiMDM's file, and enables it without starting anything. The main configuration is never edited.
  • Remove lists are enforced in every cycle, so rules restored at boot are removed again at the agent's first cycle.

On Debian 13 with Docker, NetBird and CrowdSec (nftables service with flush ruleset and include "/etc/nftables.d/*.nft") the agent loads no ruleset at all: LiMDM's firewall there is ufw, and a host with an active nftables service and no ufw is reported, not overwritten. A remove list there deletes single foreign rules by handle at runtime, in every cycle.