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

Each user’s chain allows, to any destination:

  • Loopback: 127.0.0.0/8 and ::1, on every port (an app’s loopback port is still reserved for its own account; see Notes).
  • TCP 53, 80, 443: DNS, HTTP and HTTPS (wp-cron, Composer, API calls).
  • TCP 25, 465, 587 for sending mail, and 110, 143, 993, 995 for apps that fetch mail from external mailboxes.
  • UDP 53: DNS.

Everything else is dropped for an enforced user, and allowed but logged for a learning user. A user set to off is not filtered.

Two package settings add to this, both off by default: SSH out (egress_ssh_out: TCP 22, optionally only to the CIDRs in egress_ssh_out_cidrs) and ICMP (egress_icmp: ping only).

Whatever the state, tenant processes cannot reach link-local addresses (169.254.0.0/16, fe80::/10), which covers cloud metadata endpoints.

Per-user allowlist

Under Security → Egress, Edit policy on a user’s row sets the user’s state (off, learning or enforced) and the extra destinations. Each destination is a CIDR, an optional port, a protocol (TCP or UDP) and a comment; + Add destination adds one. Extra destinations only allow traffic; there are no block rules.

Each rule is namespaced per-user; no rule from one user can affect another.

Pending requests lists destinations tenants asked for; approve or deny each one.

Implementation

  • Each user runs in their own systemd slice (jabali.slice/jabali-user.slice/jabali-user-<username>.slice).
  • nftables matches the slice with socket cgroupv2 level 3 vmap @cgroup_to_chain, a verdict map from each user’s slice to that user’s chain.
  • It also matches by socket owner (meta skuid), so a process outside the slice, such as an SSH shell, goes through the same chain.
  • 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

  • Summary: the number of enforced, learning and off users, and the total drops in the last tick.
  • Per-user policy: each user’s egress state, drops in the last tick and in the last 24 hours, and Edit policy. Click the 24-hour count to see the recent flows (below).
  • Pending requests: destinations tenants asked for, with approve and deny.

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 or Node.js 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]].