Egress Firewall
Last updated
Security → Egress. nftables + cgroup v2 vmap rules that restrict each user’s outbound traffic.
Why per-user egress matters
A compromised tenant whose PHP scripts can call any external host becomes an excellent platform for outbound abuse (command-and-control, credential stuffing, spam-relay). Restricting outbound at the per-user cgroup level bounds the damage even when the host application is owned.
Default policy
Per-user, the nftables ruleset:
- Allows
:443/tcpto anywhere (HTTPS, legitimate API use). - Allows
:587/tcpand:465/tcpto the panel’s own mail host (so PHP scripts can submit mail). - Allows
:993/tcpto the panel’s own mail host (IMAP submission of replies, if needed). - Allows
:53/udpand:53/tcpto127.0.0.1(the loopback recursor). - Drops everything else.
The package’s egress_policy field selects this default or unrestricted (no per-user filtering).
Per-user overrides
Users → Edit → Egress allows the admin to:
- Permit specific destination CIDRs on specific ports.
- Permit FQDN-based destinations (resolved at apply time; refreshed on a daily timer).
- Block specific ports / destinations even when otherwise allowed.
Each rule is namespaced per-user; no rule from one user can affect another.
Implementation
- Each user runs in their own systemd slice (
jabali.slice/jabali-user.slice/jabali-user-<username>.slice). - nftables uses a
meta cgroupv2match against the slice id. - A vmap maps
cgroupv2-id → rulesetfor O(1) classification. - The reconciler converges the ruleset on each tick.
The setup was live-verified with the drop counter incrementing on a blocked port and :443 continuing to work.
Per-page surface
- Per-user table: current policy, exception count, drop count (last hour, 24 h).
- Per-user drill-in: the active ruleset rendered as a readable summary plus the raw nftables fragment.
- Test connectivity: pick a user and a destination; the page invokes a one-shot agent call that runs the same nftables decision against the simulated socket and returns “allowed” or “dropped”.
Learning mode, the drops list and alerts
A user in learning is not blocked. Each new connection outside the allowlist is allowed, logged and counted once; packets of a connection already allowed are not counted again. An enforced user’s packets outside the allowlist are dropped, logged and counted.
Click a user’s drop count under Security → Egress to see the recent flows. Each row says Blocked (enforced) or Allowed (learning), with an Allow button that adds the destination to the user’s allowlist. During the learning soak, use it to allow what the user’s apps need before the policy is enforced. The list comes from the kernel log: at most 5 lines per user per minute, and it rotates with journald.
The Outbound traffic outside the allowlist (burst) alert (egress.drop.burst) fires when a user’s count passes the threshold (default 50) between two checks, about a minute apart. Its text names the user and says whether the traffic was blocked or, in learning mode, allowed. It fires at most once per user every 15 minutes.
A dead letter tag on an alert under Notifications → History is about delivery, not egress: the alert could not reach one of its channels after the retries. Notifications → Dead Letter lists those alerts.
Notes
- nftables rules are stateless at the layer the panel manages; established connections are not interrupted when a rule changes.
- A user’s per-user PHP-FPM pool inherits the slice automatically, no extra wiring per pool.
- The egress firewall does not interpose between the user and inbound traffic; inbound firewalling is UFW plus CrowdSec Decisions.
- An app’s loopback port (Python app, Docker app, reverse-proxy domain) can be opened only by the account that owns the app and by system users such as nginx. Other accounts are dropped, whatever their egress state; see Security.
CLI
jabali per-user-egress summary # policy state counts and pending requests
jabali per-user-egress get <email-or-id> # one user's policy
jabali per-user-egress set-policy <email-or-id> --state enforced --allow 140.82.112.0/20,443,tcp
jabali per-user-egress requests # requests tenants sent from the panel
jabali per-user-egress approve <request-id>
jabali per-user-egress deny <request-id>
set-policy replaces the user’s whole allow list. --state is off, learning or enforced, and each --allow is CIDR[,PORT[,PROTO]].