feat(rootfs): blanket IPv4 PREROUTING DNAT to 127.0.0.1#2698
feat(rootfs): blanket IPv4 PREROUTING DNAT to 127.0.0.1#2698ValentaTomas wants to merge 1 commit into
Conversation
One systemd unit + iptables rule applied at boot replaces per-port socat for IPv4. envd's scanner still tracks IPv6 listeners (no route_localnet equivalent for v6) and keeps socat for those.
PR SummaryHigh Risk Overview Potential issues: blanket DNAT can unintentionally redirect non-target services/ports and expands localhost reachability via Reviewed by Cursor Bugbot for commit 64f8f2b. Bugbot is set up for automated code reviews on this repo. Configure here. |
❌ 8 Tests Failed:
View the full list of 13 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
There was a problem hiding this comment.
Code Review
The current iptables configuration only redirects TCP traffic, which fails to provide the intended blanket DNAT for all IPv4 listeners; a corresponding rule for UDP traffic should be added to ensure full protocol coverage and feature parity.
| Type=oneshot | ||
| RemainAfterExit=yes | ||
| ExecStart=/bin/sh -c 'echo 1 > /proc/sys/net/ipv4/conf/all/route_localnet' | ||
| ExecStart=/bin/sh -c 'iptables -t nat -C PREROUTING -i eth0 -p tcp -j DNAT --to-destination 127.0.0.1 2>/dev/null || iptables -t nat -A PREROUTING -i eth0 -p tcp -j DNAT --to-destination 127.0.0.1' |
There was a problem hiding this comment.
The current iptables rule only redirects TCP traffic. To achieve a true blanket DNAT for all IPv4 listeners as described in the pull request, a corresponding rule for UDP traffic should be added. This ensures that services listening on UDP ports remain reachable from the external interface, maintaining feature parity with the previous approach for all protocol types.
ExecStart=/bin/sh -c 'iptables -t nat -C PREROUTING -i eth0 -p tcp -j DNAT --to-destination 127.0.0.1 2>/dev/null || iptables -t nat -A PREROUTING -i eth0 -p tcp -j DNAT --to-destination 127.0.0.1'
ExecStart=/bin/sh -c 'iptables -t nat -C PREROUTING -i eth0 -p udp -j DNAT --to-destination 127.0.0.1 2>/dev/null || iptables -t nat -A PREROUTING -i eth0 -p udp -j DNAT --to-destination 127.0.0.1'
|
Closing this for now as it seems to not be related to the current investigation and this is a bigger rework. |
Replaces the per-port socat path for IPv4 listeners with one provision-time iptables rule + sysctl:
```
net.ipv4.conf.all.route_localnet=1
iptables -t nat -A PREROUTING -i eth0 -p tcp -j DNAT --to-destination 127.0.0.1
```
Applied at boot by `e2b-ipv4-forward.service`. envd's scanner still tracks IPv6 listeners and keeps socat for those (no `route_localnet` for v6). Idempotent: `iptables -C` check before `-A`.
Supersedes #2697.