pf is the best firewall I have worked with: one readable file, atomic reloads, NAT and queueing in the same language as the filter rules. What it lacks is an API. Every tool that wants to change a pf firewall ends up templating pf.conf , copying it over SSH and hoping pfctl -f likes it.
I wrote pfapid to fix that: a small REST API for pf that runs on the firewall itself, with a Terraform provider on top. This post builds a complete NAT firewall with it: a default-deny base, outbound NAT, a port forward to a DMZ web server, a blocklist and QoS on the uplink.
What pfapid manages, and what it doesn't
pfapid splits the firewall into two owners:
Part Owned by Lives in
Defaults, block all , antispoof, management access You, by hand or config management /etc/pf.conf
Filter and NAT rules, per unit of work Terraform via pfapid Anchors api/<name>
Contents of tables such as <blocklist> Terraform via pfapid Tables declared in pf.conf
HFSC queues and the rules that classify into them Terraform via pfapid The…