PHP-FPM metadata egress: testing cgroup BPF with real controls
Use an owned dummy endpoint, positive controls and actual BPF attachment to verify an IPv4 link-local block inside FPM without provider queries.
Filesystem permissions do not constrain every network request PHP can make. We separately tested an IPv4 link-local block inside our owned FPM service in a disposable Debian 13 VM.
We did not investigate whether Mirohost exposes a metadata API, and we did not request real provider metadata.
Own the control endpoint first
We checked that 169.254.169.254 was unused, assigned it to the VM's loopback interface and confirmed a local route. Only then did we start our own HTTP server on that address and 127.0.0.1, using port 18085.
ip address add 169.254.169.254/32 dev lo
ip route get 169.254.169.254
The actual route had type local and dev lo, keeping requests inside the VM. GET /proof returned only the exact dummy bytes owned local metadata fixture\n.
A service cgroup policy
This is an excerpt from the owned FPM unit:
[Service]
IPAccounting=yes
IPAddressDeny=169.254.0.0/16
ExecStartPre=+/usr/bin/python3 -I /etc/deploy-cli/php85/bpf-guard.py
The complete unit also selects our PHP configuration and limits capabilities and writable paths. The cgroup BPF mechanism is described in systemd.resource-control. A configuration value alone does not prove that filtering works.
Before ExecStart, a root-owned helper checks its expected cgroup and runs BPF_PROG_QUERY for ingress and egress. Missing attached programs make it fail before FPM starts. The helper only queries the kernel: it does not load BPF, change firewall rules or send network requests.
The + prefix gives this short helper the privilege needed to query BPF outside the main command's capability restrictions. As systemd.service explains, it does not bypass policies covering the whole cgroup.
The helper uses a specifically checked x86_64 syscall profile with no claim of portability to every architecture. Attachment alone also does not prove policy contents; actual requests must follow.
The same UIDs inside and outside the service
Both pools executed a PHP fixture through FastCGI. It connects directly to two fixed addresses using stream_socket_client:
$file = @stream_socket_client(
'tcp://' . $host . ':18085',
$errno,
$message,
1
);
One second is a timeout for one control connection, not evidence of policy and not a server-configuration deadline. After connecting, the fixture sends GET /proof and checks the dummy response. It accepts no arbitrary user-supplied target addresses.
| Context | 127.0.0.1:18085 | 169.254.169.254:18085 |
|---|---|---|
| Root outside FPM | HTTP 200, exact bytes | HTTP 200, exact bytes |
| Each runtime UID outside the FPM cgroup | HTTP 200, exact bytes | HTTP 200, exact bytes |
| Actual frontend worker | Successful response | No connection, errno 110 |
| Actual admin worker | Successful response | No connection, errno 110 |
A root observer matched the PHP response PIDs to the master's children and checked their UIDs and cgroup. A separate kernel query confirmed attached ingress/egress BPF programs. The nftables ruleset was identical before and after the probes.
Limits of the network policy
A timeout alone would show only that no response arrived. Here it is supported by the local route, positive responses from the same endpoint, an allowed-address response from FPM itself, actual cgroup/BPF state and unchanged nftables. Together these establish the denial within this controlled experiment.
The block covers 169.254.0.0/16 for sockets created in our FPM service. Other processes using the same Unix UIDs outside that cgroup could connect. This is neither a global UID rule nor complete PHP isolation.
IPv6, other metadata addresses, proxies and application-level SSRF defenses require separate decisions. We do not assert that the provider exposes an endpoint at this address.
A separate reboot boundary
The network probes belong to the explicit manual launch before reboot. After a normal reboot, FPM remained disabled/inactive, the test IP was absent and the control HTTP service had not started. Earlier results were not presented as a post-reboot metadata test.
The same criteria for the CLI-created configuration
After the manual exercise, the CLI created and started two pools on another clean Debian VM. Before starting, its source-owned BPF helper checked actual mechanism support and attached ingress/egress programs in the service cgroup. The following ordinary helper checked the future master capability context. Excerpt from the actual CLI unit:
ExecStartPre=+/usr/bin/python3 -I /etc/deploy-cli/php85/bpf-guard.py
ExecStartPre=/usr/bin/python3 -I /etc/deploy-cli/php85/process-guard.py
The first file and metadata probes then ran on this configuration with the same locally owned positive and negative controls. Each pool could access its own private files and cache; cross-pool private/cache access, code writes and connecting to its own socket were denied. Inside FPM the controlled link-local address was blocked, while the same UIDs outside the cgroup received HTTP 200. nftables remained unchanged.
Numeric UIDs differ between the manual and CLI VMs because identities use an allocator; each worker was checked against its own assigned user. After a separate normal reboot, the CLI-created service remained disabled/inactive and the dummy address and runtime disappeared. The CLI refused the old running proof without writes; no new start or metadata requests ran after reboot.