Vivian Voss

pf Keeps the Only Ruleset

lean software freebsd pf security

In June 2021 the developer behind NewsBlur, a news reader with a loyal following, moved its MongoDB server into a Docker container, about as ordinary a change as modern operations has to offer. The machine had ufw switched on and kept to a strict allowlist of the project's own internal servers, which is precisely what the tutorials recommend. A little over three hours after the switch, the database was empty, and in its place sat a collection called READ__ME_TO_RECOVER_YOUR_DATA asking for 0.03 bitcoin.

The post-mortem found the door quickly. "When I containerized MongoDB, Docker helpfully inserted an allow rule into iptables, opening up MongoDB to the world." The firewall still described itself as active. It simply was not the thing deciding.

Why Docker writes its own rules

The reason deserves to come first, because it is a good one. A container on Linux lives on a private bridge network with an address nobody outside can reach, and docker run -p 8080:80 promises that a request to the host's port 8080 will arrive at the container's port 80. To keep that promise, the kernel has to rewrite the destination of the packet before it decides where the packet goes, which means a destination NAT rule early in the path. Docker cannot know whether the host runs ufw, firewalld, a hand-written nftables file or nothing at all, so it programs the kernel itself and the command works everywhere. For a developer on a laptop that is exactly right, and on a server it means the firewall now has two authors, one of whom comes in round the back without mentioning it to the other.

Four floors between a packet and its fate

Docker's own documentation is admirably plain about what follows. ufw keeps its rules in the INPUT and OUTPUT chains, whilst Docker redirects published traffic in the nat table, which the kernel consults first: "Packets are routed before the firewall rules can be applied, effectively ignoring your firewall configuration." A few lines earlier it concedes that the two "use firewall rules in ways that make them incompatible with each other."

I counted what Docker builds for this in its current source, release 29.10.1. The bridge driver declares seven chains of its own, every name beginning with DOCKER, and the documentation adds an eighth, DOCKER-USER, as the place where the administrator's exceptions are meant to go. Docker keeps the whole arrangement in duplicate for IPv6 and spreads it across more of the kernel's tables than ufw ever touches. Every published port then gets a DNAT rule in nat and an ACCEPT rule at the top of filter, both in front of anything ufw has said. The same file, with an honesty one rarely sees in commercial software, admits in a comment that one of its functions does something with SCTP that is "broken, and disabled-by-default".

So on an Ubuntu server a packet bound for a container meets four floors: ufw, the iptables commands ufw speaks, the nftables engine underneath them, and Docker's chains, which sit in front of all of them. On a Fedora or Red Hat machine with firewalld, Docker adds a zone of its own called docker as well, and each of these keeps its own idea of what is allowed.

Where a packet to a published port is decided Ubuntu with Docker FreeBSD with pf nat PREROUTING → DOCKER DNAT: readdressed to the container FORWARD → DOCKER-USER empty unless written by hand DOCKER-FORWARD → DOCKER ACCEPT for the published port container INPUT → ufw: deny never reached by this packet pf.conf, the main ruleset one file, written by the administrator rdr, without pass readdressed to the jail, still filtered anchor "blocklistd/*" named in pf.conf, may only block pass, written by the same hand the only way in jail Sources: Docker documentation and Docker 29.10.1 source; pf.conf(5); own reading of this blog's server, 2 December 2026

The holes in the floors

The NewsBlur incident was not the first warning. Issue 4737 in Docker's tracker, which reports "serious problems" between Docker and ufw, was opened in March 2014, collected 157 comments and was closed in April 2018, whilst the behaviour it describes is still in the documentation today; one of the latest remarks, from November 2025, puts it neatly, saying that "most of these issues are about the default operation of Docker being a problem."

The layers also undo each other. Until Docker 28.0, a port published only on 127.0.0.1 could still be reached by any machine on the same network segment that sent its packets to the host, which is not quite cricket for an address whose whole meaning is "this machine only". And in July 2025 came CVE-2025-54388: on Docker 28.2.0 to 28.3.2, reloading firewalld wiped Docker's rules, and published ports, including those bound to localhost, became reachable from remote hosts with a route to the bridge. Nobody had attacked anything. One layer had tidied up after itself and taken another layer's work with it.

Twelve years of Docker and the host firewall Mar 2014 issue 4737 opened: "docker and ufw serious problems" Apr 2018 closed after 157 comments the behaviour stays in the documentation Jun 2021 NewsBlur: ufw active, MongoDB open to the world database deleted a little over three hours later May 2023 issue 45610: localhost ports reachable from the LAN dropped from Docker 28.0 onwards Jul 2025 CVE-2025-54388: a firewalld reload wipes the rules published ports exposed, localhost ones included (28.2.0 to 28.3.2) Nov 2025 on the old issue: "about the default operation of Docker" Dec 2026 documentation: "effectively ignoring your firewall configuration" Sources: moby issues 4737 and 45610, GHSA-x4rx-4gw3-53p4, NewsBlur post-mortem, Docker documentation

A security group at a cloud provider would have stopped NewsBlur's port before it reached the host, but a rented virtual server at most hosting firms, or a machine in a company's own rack, usually has nothing in front of it except the firewall it runs itself. None of this needs a clever attacker. It needs an administrator who trusts the firewall's own report, and that is the administrator the firewall was built for.

Who collects and who pays

Docker collects the command that always works, and with it the smooth first hour on which its popularity was built. Ubuntu ships ufw under the name Uncomplicated Firewall, a name that holds until the first container publishes a port.

The administrator pays in rules that live outside the firewall they set up. The fix Docker recommends goes into DOCKER-USER, written in raw iptables with connection tracking, because by the time a packet reaches that chain its destination has already been rewritten. It has to be written again for IPv6, and kept somewhere that survives a reboot without ufw overwriting it. The other route is a third-party helper that teaches ufw about Docker, or a 127.0.0.1 in front of every published port in every compose file, and the first colleague who forgets it has opened the database again. Either way, the answer to the question of which ports are open now lives in several places, and ufw status is only one of them.

One file on FreeBSD

pf reads its rules from /etc/pf.conf, and FreeBSD ships without one: until the administrator writes that file and sets pf_enable, there is no ruleset to speak of. Whatever reaches the kernel later comes from that text.

A program can still add rules, and the mechanism shows how. pf calls it an anchor, a named container for rules, and the manual page is precise about when its contents count: "When evaluation of the main ruleset reaches an anchor rule, pf(4) will proceed to evaluate all rules specified in that anchor." An anchor that pf.conf does not name is never reached. The file decides where in the order an outside program may write and which interface its rules apply to, and pfctl -sA lists every such place.

The server behind this blog, which runs FreeBSD 15.1, gave me its numbers this morning (2 December, 09:18, read-only). Its pf.conf runs to 95 lines, of which 37 do any work. Once loaded, they become 22 filter rules, plus 10 that translate addresses for the jails. The web jail receives its traffic through rdr rules written without the pass keyword, so every redirected packet still has to meet an explicit pass rule further down, written by the same hand. One line in the file names an anchor, anchor "blocklistd/*" in on $ext_if, and the only program that uses it is blocklistd from the base system, which blocks addresses that keep failing at the SSH login. Inside that anchor sits exactly one rule, block drop in quick proto tcp from <port22> to any port = ssh, and a table of fifteen addresses (fifteen this morning; the number changes, the rule does not). The helper script that writes it can only ever produce a block line.

That is the whole firewall, written by one hand, with a single invited guest who is only allowed to lock doors.

The firewall of this blog's server, read on 2 December 2026 95 lines in pf.conf 37 of them do any work 22 + 10 filter and translation rules 1 anchor named in the file blocklistd, base system 1 rule inside it block, the only kind it writes 15 addresses locked out failed SSH logins, this morning FreeBSD 15.1-RELEASE-p3, pfctl -sr, -sn, -sA, read-only, 09:18

The limit

Podman on FreeBSD can bypass the filter too. The container networking plugins write their port forwards as rdr pass, and pf.conf(5) says such packets are "automatically passed" without meeting the filter rules. They do so only after the administrator has added rdr-anchor "cni-rdr/*" to pf.conf, as the Handbook instructs; without that line nothing is forwarded at all. A permitted bypass is still a bypass, so the line deserves the same scrutiny as any rule. The FreeBSD port of Podman also describes itself as experimental.

Docker's way is faster to start. Where Docker needs -p, a jail on FreeBSD that serves the web needs an rdr line and a pass line for each port, written by hand. Those two lines are then also the documentation, readable by the next administrator in the one file they would open anyway, and no program adds a third without a line in that same file allowing it to.

Linux has repairs. DOCKER-USER, ports bound to localhost, rootless mode and Docker's nftables backend all exist; the documentation still calls that backend experimental and notes that it creates no default drop policy. Each repair is a setting the administrator has to know about, on top of the default.

The firewall was not NewsBlur's only lock, or should not have been. Its MongoDB accepted connections without a password, and its developer added authentication afterwards. A database that trusts the network is a risk on any system, pf included.

A firewall is a list of promises, and on FreeBSD only the person who signs them is allowed to make them.