rootlesskit icon indicating copy to clipboard operation
rootlesskit copied to clipboard

Propagation of source IP fails with rootlesskit v3.2.0

Open Toastienergy opened this issue 1 month ago • 6 comments

I upgraded docker to 29.9.0 today. This unfortunately broke the propagation of the source IP again. After trying to debug it myself, i couldn’t find the root cause. So I want to make it clear that the following report was written by AI. I hope that’s okay since I wanted to report the bug and don’t have enough knowledge myself to solve it and hope that it still helps.

Summary

Since v3.2.0, the builtin port driver's source-IP-transparent mode is silently disabled when --detach-netns is used (which dockerd-rootless.sh sets by default). The backend probe now runs in RunChildDriver, i.e. outside the detached netns, where the rootless user namespace has no CAP_NET_ADMIN over netfilter. The probe fails with Permission denied, the resolved backend becomes "none", and rootlesskit falls back to non-transparent mode — without any message at the default log level.

This is a regression from v3.1.0 (shipped with Docker 29.8.2), where source-IP preservation worked with the identical setup. Docker 29.9.0 bumped RootlessKit v3.1.0 → v3.2.0 (moby/moby#53607) and broke it.

Not a duplicate of #573 (that one is about the gvisor-tap-vsock port driver; this report is about the builtin port driver with --detach-netns).

Environment

  • rootlesskit: v3.2.0 (from docker-rootless-extras 29.9.0); regression vs v3.1.0 (Docker 29.8.2)
  • Docker: 29.9.0 rootless via dockerd-rootless.sh
  • Kernel: 6.8.0-146-generic (Ubuntu), x86_64
  • iptables v1.8.10 (nf_tables backend), nft also installed; both binaries in /usr/sbin, both in PATH of the rootlesskit process
  • plain unprivileged user (uid 1002), newuidmap/newgidmap
  • userland-proxy: false in daemon.json, br_netfilter loaded (the documented prerequisites for source-IP propagation with builtin are met)

rootlesskit command line (as reported by ps):

rootlesskit --state-dir=/run/user/1002/dockerd-rootless --net=gvisor-tap-vsock --mtu=65520 \
  --slirp4netns-sandbox=auto --slirp4netns-seccomp=auto --disable-host-loopback \
  --port-driver=builtin --copy-up=/etc --copy-up=/run --propagation=rslave --detach-netns \
  /usr/bin/dockerd-rootless.sh

Steps to reproduce

  1. Start rootless Docker via dockerd-rootless.sh (rootlesskit flags as above), publish a TCP port from a container.
  2. Connect to the published port from a remote host.
  3. The container sees the network driver's gateway IP (10.0.2.1) as the peer address instead of the real client IP.
  4. Restart with --debug appended to get the diagnostic messages (see below).

Expected behavior

Client source IP is preserved via IP_TRANSPARENT, as with v3.1.0 / Docker 29.8.2 and as documented in docs/port.md.

Actual behavior

The container always sees the gateway IP. With --debug:

level=debug msg="[rootlesskit:child ] port/builtin: source IP transparent (iptables): mangle table not available, disabling: exit status 4: iptables v1.8.10 (nf_tables): Could not fetch rule set generation id: Permission denied (you must be root)\n"
level=debug msg="[rootlesskit:child ] port/builtin: source IP transparent: falling back to non-transparent mode, client source IPs will not be preserved"

GET /v1/info on the API socket (note sourceIPTransparentBackend: "none" despite nft and iptables both being present and usable for a rootless process in its own netns):

{"apiVersion":"1.1.3","version":"3.2.0","stateDir":"/run/user/1002/dockerd-rootless","childPID":127788,"networkDriver":{"driver":"gvisor-tap-vsock","dns":["10.0.2.1"],"childIP":"10.0.2.100"},"portDriver":{"driver":"builtin","protos":["tcp","tcp4","tcp6","udp","udp4","udp6"],"extra":{"sourceIPTransparentBackend":"none"}}}

Forcing --source-ip-transparent-backend=iptables explicitly does not change anything — the probe for that backend fails with the same Permission denied. In auto mode both probes (nft, iptables) fail, hence "none".

Root cause

The probe was moved from the rule-installation path into RunChildDriver between v3.1.0 and v3.2.0 (PR #613 rework), but the two run in different network namespaces:

  • pkg/port/port.go documents the interface contract: "RunChildDriver is executed in the child's namespaces, excluding detached-netns."
  • The transparent rule installation, setupTransparentRouting(), is invoked from handleConnectRequest(), which is wrapped in ns.WithNetNSPath(detachedNetNSPath, ...) (pkg/port/builtin/child/child.go, routine()). It runs inside the detached netns — a netns created by the user namespace root, where CAP_NET_ADMIN is effective and iptables/nft work fine.
  • In v3.2.0, resolveBackendName() (with probeNFT/probeIPTables) runs in a goroutine started from RunChildDriver() (child.go, right after the unix listener is created) — outside the detached netns. In the non-detached netns, the user namespace root has no privileges over netfilter, so iptables -t mangle -L -n fails with Permission denied (you must be root) (exit status 4).
  • resolveBackendName then leaves resolvedBackend empty, and setupTransparentRouting() returns false at the gate (if d.resolvedBackend == "") before it ever runs the actual rule-installation commands — which would have run in the right netns and would presumably have succeeded.

In v3.1.0 the availability check was inline in setupTransparentRouting() (exec.Command("iptables", "-t", "mangle", "-L", "-n")), i.e. it ran inside the detached netns together with the rules — which is why v3.1.0 / Docker 29.8.2 worked.

So with --detach-netns (again: dockerd-rootless.sh default) the probe can never succeed, and source-IP transparency is dead for the builtin port driver regardless of the --source-ip-transparent-backend value.

Additional observations

  1. Silent degradation: every probe message and the fallback message ("source IP transparent: falling back to non-transparent mode, client source IPs will not be preserved") are logged at debug level only. Without --debug the user gets no indication at all that source-IP propagation is off. Since this changes externally observable behavior, it should be a warning at least — and arguably a hard error when --source-ip-transparent-backend is explicitly set and its probe fails.
  2. /v1/info reports sourceIPTransparentBackend: "none", but nothing surfaces the reason.

Suggested fix

Run the backend probes in the same namespace context as the rule installation — i.e. inside ns.WithNetNSPath(detachedNetNSPath, ...) when detachedNetNSPath is set (or move the probe back into setupTransparentRouting() as in v3.1.0). Optionally surface probe failures at warning level.

Workaround

Downgrade to Docker 29.8.2 (RootlessKit v3.1.0) and hold the packages until this is fixed. Verified to restore source-IP propagation with the identical configuration.

Toastienergy avatar Oct 09 '26 09:10 Toastienergy

Does it work if you revert:

  • https://github.com/rootless-containers/rootlesskit/pull/613

AkihiroSuda avatar Oct 09 '26 17:10 AkihiroSuda

I went back to docker version 29.8.2, which uses rootlesskit 3.1.0 and with this version, everything works as intended.

Toastienergy avatar Oct 09 '26 17:10 Toastienergy

Does this fix work?

  • https://github.com/rootless-containers/rootlesskit/pull/649

AkihiroSuda avatar Oct 09 '26 18:10 AkihiroSuda

Yes this works! Tried it with docker version 29.9.0

Edit: FYI curl --unix-socket /run/user/1002/dockerd-rootless/api.sock http://localhost/v1/info | grep -i backend

{"apiVersion":"1.1.3","version":"3.2.0+dev","stateDir":"/run/user/1002/dockerd-rootless","childPID":440138,"networkDriver":{"driver":"gvisor-tap-vsock","dns":["10.0.2.1"],"childIP":"10.0.2.100"},"portDriver":{"driver":"builtin","protos":["tcp","tcp4","tcp6","udp","udp4","udp6"],"extra":{"sourceIPTransparentBackend":"nft"}}}

Toastienergy avatar Oct 09 '26 19:10 Toastienergy

downgrade for ubuntu 24:

sudo apt-get install \
  docker-buildx-plugin=0.37.1-1~ubuntu.24.04~noble \
  docker-ce=5:29.8.2-1~ubuntu.24.04~noble \
  docker-ce-cli=5:29.8.2-1~ubuntu.24.04~noble \
  docker-ce-rootless-extras=5:29.8.2-1~ubuntu.24.04~noble \
  containerd.io=2.3.6-1~ubuntu.24.04~noble

sudo apt-mark hold docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras containerd.io

after fix

sudo apt-mark unhold docker-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras containerd.io

denbkh avatar Oct 10 '26 20:10 denbkh

Just an info: if you’re using HTTP/3, the source IP will also not be propagated. But it’s also noted in https://github.com/rootless-containers/rootlesskit/blob/master/docs/port.md.

Toastienergy avatar Oct 15 '26 10:10 Toastienergy