Hi Tuntematon,

In today’s post we’ll get going at getting SafeLine excellent WAF (Web Application Firewall) to agree at running on Rootless Docker setup.

11.2026 update — Docker Engine 29.5+ changed the ground under this article#

TL;DR if you’re on Docker Engine 29.5 or later: the slirp4netns port-driver override (old Step 1) is obsolete, network_mode: host surgery is optional, and getting real client IPs into SafeLine now takes a different (and shorter) path: userland-proxy: false + hard prerequisite kernel module. The privileged-port sysctl is the only step that survives unchanged. Everything below is the recipe for the new era, verified in production on this very host.

Everything below the fold was written against Docker 28.x-era rootless behavior, and Docker Engine 29.5 quietly rerouted two of the roads this article sends you down:

  1. --network host semantics flipped. Before 29.5, host-mode rootless containers landed in the RootlessKit network namespace — which is why tengine bound 80/443 into a world nobody outside could reach, and why this article told you to abandon host mode for explicit port mappings. Since 29.5, host mode shares the real host network namespace. The workaround is no longer corrective; it’s a topology choice.
  2. RootlessKit went 3.x, and the builtin port driver grew up. The reason old Step 1 existed — DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns for real client-IP propagation — has been superseded: on RootlessKit 3.0+ (bundled with Docker 29.5), the default builtin port driver propagates source IPs natively. Pinning the slirp4netns port driver now gets you the slow path for no benefit.

Step-by-step verdict#

Original step On 29.5+
Step 1 — slirp4netns port-driver override Obsolete — delete it. Builtin driver propagates IPs natively now.
Step 2 — net.ipv4.ip_unprivileged_port_start sysctl Unchanged — still required. Privileged ports are a user-namespace restriction, not a Docker-version one.
Step 3 — remove network_mode: host, explicit ports Optional. Host mode genuinely gives you the host netns now. I kept the explicit-ports shape anyway — clearer topology, and the port-driver path is where client IPs live.
The client-IP goal (the actual point) New recipe below. Different mechanism, same outcome.

The new recipe: real client IPs on 29.5+#

If your tengine access log shows every external visitor as 172.18.0.1 (or whatever your bridge gateway is), you’re being SNAT’d by Docker’s userland proxy — the userspace relay that terminates published-port connections and re-originates them from the bridge. RootlessKit 3.x propagates source IPs through the port driver, but only if the userland proxy isn’t sitting in the middle rewriting the connection. So:

1. Load br_netfilter — first, and this is the part nobody tells you:

sudo modprobe br_netfilter
echo 'br_netfilter' | sudo tee /etc/modules-load.d/br_netfilter.conf   # survive reboots

Without this module loaded, dockerd in rootless mode refuses to start with userland-proxy: false — it exits with a status of 1 including systemd-side messages that tell you nothing (The unit process exited with error code, See journalctl). The journal is equally useless here. The module is the prerequisite for the DNAT path the port driver needs; load it before the daemon restart, not after the crash.

2. Disable the userland proxy:

mkdir -p ~/.config/docker
echo '{ "userland-proxy": false }' > ~/.config/docker/daemon.json
systemctl --user restart docker
docker ps   # daemon alive = module did its job

3. Bring the stack back and verify at connection level:

cd /path/to/safeline && docker compose up -d
# hit your frontend from an external vantage, then:
docker exec safeline-tengine tail -5 /var/log/nginx/safeline/accesslog_1 # here for application ID#1 check what makes sense for you.

Success looks like your actual source address in the first column — connection-level, not merely riding along in X-Forwarded-For:

45.138.xxx.xxx | - | ... | "GET / HTTP/2.0" | 200 ...

Failure still looks like the bridge gateway squatting in the log (172.18.0.1 | - | ...). Note that X-Forwarded-For-derived displays (SafeLine’s dashboard, “what’s my IP” style endpoints) are not a valid test — they show real IPs even while the proxy masquerades the connection. The access log’s source column is the ground truth.

Migration footnotes (if you’re moving a 28.x host forward)#

  • The containerd store is a one-way door. 29.5+ ships containerd 2.x, which migrates the metadata DB on first start. Rolling back to 28.x afterwards means the old daemon can’t read the migrated store — so back up ~/.local/share/docker (and your bind mounts, which are unaffected) before upgrading, not “eventually”.
  • Hand-created networks may not survive. A docker network create-made network (no compose ownership) can vanish across the containerd migration. Capture its config with docker network inspect <name> beforehand; the recreate is one line: docker network create --subnet <same> <name>.
  • Startup races may surface. On my host, SafeLine’s luigi crashed twice (DNS “no such host”, then “connection refused”) while postgres was still passing its health check — it self-recovered once pg was up. If a container crash-loops right after an engine migration, check whether it’s just racing its dependencies before you debug anything deeper.
  • Expect one safe false start. The get.docker.com/rootless installer skips a download if ~/bin/dockerd exists — remove the old binary (after backing it up) so the new one actually lands.

Verified on: Docker Engine 29.10.1, RootlessKit 3.3.0, containerd 2.4.2, slirp4netns 1.2.0 (retained as network driver; harmless), Debian on Hetzner Cloud.

The original steps below were written for a Docker Engine 28.3.3 estate — and yes, this article now documents its own expiry date, which is the only honest way to write about Docker networking.


Prerequisites#

  • Docker installed in rootless mode (dockerd-rootless-setuptool.sh install)
  • SafeLine CE compose.yaml and .env present
  • sudo access for sysctl (one-time)

Setting up Docker in Rootless mode is a bit beyond the goal of that article, you’ll find all you need here.

Once this has been done, let’s get down at making SafeLine run on such a setup. In order to build your SafeLine setup, you’d need to do this by hands. That means that you’d need to download the docker-compose file and create your own .env file.

That is what I did logged in as the docker running user:

mkdir -p /home/user/data/safeline/
cd /home/user/data/safeline/
wget "https://waf.chaitin.com/release/latest/compose.yaml"
touch ".env"
cat > /home/user/data/safeline/.env << 'EOF'
SAFELINE_DIR=/home/user/data/safeline
IMAGE_TAG=latest
MGT_PORT=9443
POSTGRES_PASSWORD="<apassword>"
SUBNET_PREFIX=172.22.222
IMAGE_PREFIX=chaitin
ARCH_SUFFIX=
RELEASE=
REGION=-g
MGT_PROXY=0
EOF

Now comes a few identified issues, issues we will address further on:

Problem 1 — Ports 80/443 not binding on the host:#

In rootless Docker, network_mode: host does not mean the real host network. Containers land in the rootlesskit network namespace instead. As a result, nginx inside safeline-tengine binds to 80/443 correctly inside the container, but those ports are never exposed to the real host interface. Additionally, rootless Docker cannot bind privileged ports (< 1024) without a sysctl change.

Problem 2 — Real client IPs not visible to SafeLine (SNAT):#

Rootlesskit’s default port driver SNATs all incoming traffic before it reaches the container, so SafeLine/nginx sees the rootlesskit gateway IP instead of the real client IP. This breaks IP-based WAF features: block lists, rate limiting, geo-blocking and IP reputation rules all become ineffective. The fix is to switch the port driver to slirp4netns, which handles port forwarding at a lower level and preserves the original source IP.

Now let’s fix these issues:

Step 1 — Switch rootlesskit port driver to slirp4netns#

This is the most important step — it both enables privileged port binding and preserves real client IPs. With slirp4netns as the port driver, CAP_NET_BIND_SERVICE via setcap is no longer needed or effective; the sysctl approach (Step 2) is the only path for privileged ports.

Create the Docker daemon override file (under your docker user owner):

mkdir -p ~/.config/systemd/user/docker.service.d
cat > ~/.config/systemd/user/docker.service.d/override.conf << EOF
[Service]
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns"
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns"
EOF

Reload and restart the Docker user daemon:

systemctl --user daemon-reload
systemctl --user stop docker
pkill rootlesskit          # ensure full teardown
systemctl --user start docker
systemctl --user status docker

Verify the driver is active:

cat ~/.config/systemd/user/docker.service.d/override.conf
systemctl --user show docker | grep Environment

Step 2 — Lower the unprivileged port start on the host#

Required for binding ports 80/443 in rootless mode. With slirp4netns as the port driver, this is the only supported method — setcap cap_net_bind_service on rootlesskit does not work with the slirp4netns port driver.

# Temporary (verify first)
sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80

# Persistent (survives reboot)
echo "net.ipv4.ip_unprivileged_port_start=80" | sudo tee /etc/sysctl.d/99-unprivileged-ports.conf
sudo sysctl --system

Verify:

sudo sysctl net.ipv4.ip_unprivileged_port_start
# Expected: net.ipv4.ip_unprivileged_port_start = 80

Step 3 — Fix the tengine service in compose.yaml#

Why this is needed#

SafeLine’s default compose.yaml uses network_mode: host for tengine with no explicit port mappings. In rootless Docker this means nginx binds inside the rootlesskit netns only — invisible to the real host.

The fix#

Edit compose.yaml. Find the tengine service and remove network_mode: host, replacing it with explicit port mappings and a network assignment:

  tengine:
    container_name: safeline-tengine
    restart: always
    image: ${IMAGE_PREFIX}/safeline-tengine${REGION}${ARCH_SUFFIX}:${IMAGE_TAG}
    ports:
      - "80:80"
      - "443:443"
    networks:
      safeline-ce:
        ipv4_address: ${SUBNET_PREFIX}.x   # pick a free IP — see note below
    volumes:
      # ... unchanged ...
    environment:
      # ... unchanged ...
    ulimits:
      nofile: 131072
    # network_mode: host   ← REMOVE this line

Finding a free IP: Check .env for SUBNET_PREFIX, then review other containers' ipv4_address entries in compose.yaml to pick an unused last octet.

I went for this:
networks:
safeline-ce:
ipv4_address: ${SUBNET_PREFIX}.6

Remove any sysctls block from tengine (if present)#

If your compose file has this under tengine, remove it — it is not permitted with explicit port mappings:

# REMOVE if present:
sysctls:
  - net.ipv4.ip_unprivileged_port_start=0

Step 4 — Bring SafeLine up#

cd /path/to/safeline
docker compose up -d
docker compose ps

Expected state — all containers Up:

safeline-tengine    Up
safeline-mgt        Up
safeline-detector   Up
safeline-pg         Up
safeline-chaos      Up
safeline-fvm        Up
safeline-luigi      Up

Step 5 — Verify port binding on the host#

ss -tlnp | grep -E ':80|:443|:9443'

Expected — slirp4netns owning all three ports:

LISTEN 0 1 0.0.0.0:80        0.0.0.0:*    users:(("slirp4netns",...))
LISTEN 0 1 0.0.0.0:443       0.0.0.0:*    users:(("slirp4netns",...))
LISTEN 0 1 0.0.0.0:9443      0.0.0.0:*    users:(("slirp4netns",...))

You can also verify nginx is listening inside the container via /proc:

docker exec safeline-tengine cat /proc/1/net/tcp | awk '{print $2}' | grep -E "^00000000:(0050|01BB)"
# 0x0050 = port 80, 0x01BB = port 443

Step 6 — Configure upstream applications#

Connecting tengine to an external app network (optional)#

If your upstream apps live in a separate Docker compose stack, attach tengine to their network:

# In SafeLine compose.yaml

services:
  tengine:
    networks:
      safeline-ce:
        ipv4_address: ${SUBNET_PREFIX}.x
      your-app-network:            # join the upstream network
        aliases:
          - safeline-tengine

# Bottom of compose.yaml
networks:
  safeline-ce:
    external: false
  your-app-network:
    external: true
    name: actual_docker_network_name   # from: docker network ls

Find the network name:

docker network ls
docker inspect <upstream-container> | grep -A 5 Networks

Adding a site in SafeLine UI#

  1. Browse to https://<host>:9443
  2. Add your upstream app (IP:port or container name — see note below)
  3. SafeLine generates nginx vhost configs in /etc/nginx/sites-enabled/IF_backend_*
  4. nginx reloads automatically

Upstream addressing#

Method Status Notes
172.1x.x.x:PORT (static IP) ✅ Reliable if IPs are statically assigned in compose, I went for this
container_name:PORT ❌ SafeLine UI accepts it although nginx validation fails

Step 7 — Securing the SafeLine Admin Console on TCP:9443#

⚠️ Obviously, securing any external access toward port TCP:9443 is highly recommended, I did that through UFW rules on the host itself, thus allowing inbound connectivity to TCP:9443 for tolerated IP stacks only.

That’s it, you can now enjoy your Rootless SafeLine setup !
Hope this helps,
obuno