Repository navigation
fix: Remove privileged mode from proxy-init using DNAT instead of REDIRECT - #242
Conversation
3ed1c24 to
15f507a
Compare
E2E Test Results — Kind cluster with Istio ambient meshTested on a local Kind cluster ( With Istio Ambient Mesh (
|
| Test | Result | Details |
|---|---|---|
| proxy-init starts without privileged | PASS | privileged: false, caps NET_ADMIN+NET_RAW, drop: ALL |
| POD_IP injected via Downward API | PASS | Resolved to pod IP |
| iptables rules use DNAT (not REDIRECT) | PASS | nftables shows dnat to <pod-ip>:15124 |
| No sysctl route_localnet call | PASS | Logs show no sysctl, no errors |
| Outbound token exchange | PASS | agent -> auth-target:8081 via Envoy -> 200 authorized |
| Inbound JWT validation (no token) | PASS | test-client -> agent:8080 -> 401 unauthorized |
| Inbound JWT validation (invalid token) | PASS | -> 401 token validation failed |
| Inbound JWT validation (valid token) | PASS | -> 200 authorized |
| Ambient mesh DNAT interception | PASS | 3 packets matched the DNAT rule in PROXY_OUTPUT |
| Webhook injection (clean pod) | PASS | Pod in team1 got privileged=false, capabilities, POD_IP |
Without Istio Ambient Mesh (e2e-no-ambient namespace, no ambient label)
| Test | Result | Details |
|---|---|---|
| proxy-init starts without privileged | PASS | privileged: false, caps NET_ADMIN+NET_RAW, drop: ALL |
| iptables rules installed | PASS | PROXY_OUTPUT (REDIRECT to 15123), PROXY_INBOUND (REDIRECT to 15124) |
| DNAT rule present (0 hits) | PASS | DNAT rule installed but correctly idle — no ztunnel traffic |
| Outbound token exchange | PASS | agent -> auth-target:8081 -> 200 authorized |
| Inbound JWT validation (no token) | PASS | test-client -> agent:8080 -> 401 unauthorized |
| Inbound JWT validation (invalid token) | PASS | -> 401 token validation failed |
| Inbound JWT validation (valid token) | PASS | -> 200 |
Key observations
- The DNAT rule (
dnat to <pod-ip>:15124) is harmless when ambient mesh is not active (0 packet matches), while correctly intercepting ztunnel inbound delivery when ambient is active. sysctl route_localnet=1is no longer called — the init container runs successfully with justNET_ADMIN+NET_RAWcapabilities.SO_ORIGINAL_DSTworks identically with DNAT as with REDIRECT — Envoy'soriginal_dstcluster resolves the correct upstream.
|
does this PR encompasses #234 or focus on additional problems? |
pdettori
left a comment
There was a problem hiding this comment.
Review Summary
Well-crafted security hardening PR. Replaces privileged: true with the minimum capabilities (NET_ADMIN, NET_RAW) by switching from REDIRECT (which requires route_localnet=1 sysctl, hence privileged mode) to DNAT to the pod IP. The technical justification is correct and thoroughly documented.
Areas reviewed: Go, Shell, YAML/K8s, Docs
Commits: 2 commits, all signed-off ✓
CI status: all passing (17/17 checks)
| Check | Result |
|---|---|
| DCO sign-off | ✓ All commits signed |
| PR title/body | ✓ Conventional prefix, summary + context + test plan |
| Security | ✓ Positive — removes privileged, drops ALL caps except NET_ADMIN/NET_RAW |
| Manifest consistency | ✓ All 5 YAML manifests + Go webhook code updated consistently |
| Shell safety | ✓ POD_IP validated and quoted; set -e active |
| Docs | ✓ CLAUDE.md and README.md updated |
One non-blocking suggestion about IPv6 edge case noted inline. LGTM — this is a clear security improvement.
| ${IPT} -t nat -A PROXY_OUTPUT -m mark --mark ${ZTUNNEL_MARK} -m owner ! --uid-owner "${PROXY_UID}" -m addrtype --dst-type LOCAL -p tcp -j DNAT --to-destination "${POD_IP}:${INBOUND_PROXY_PORT}" | ||
|
|
||
| # --- Rule 2: Skip all remaining ztunnel traffic --- | ||
| # After rule 1 captured ztunnel's inbound delivery, any other ztunnel traffic |
There was a problem hiding this comment.
suggestion (non-blocking): IPv6 edge case — if POD_IP is an IPv6 address (dual-stack or v6-only cluster), iptables --to-destination will reject it since iptables is IPv4-only. This isn't a regression (the existing REDIRECT approach also doesn't handle IPv6), but worth considering a guard:
case "${POD_IP}" in
*:*) echo "ERROR: POD_IP is IPv6 (${POD_IP}); iptables DNAT requires IPv4" >&2; exit 1 ;;
esacOr even better, skip the DNAT rule for IPv6 with a warning if that's an acceptable degradation.
| sysctl -w net.ipv4.conf.all.route_localnet=1 | ||
| # POD_IP is required for the ztunnel inbound interception rule (DNAT target). | ||
| # It must be passed via the Kubernetes Downward API (status.podIP) or set manually. | ||
| # We use DNAT to the pod IP instead of REDIRECT to avoid needing route_localnet=1, |
There was a problem hiding this comment.
praise: Clean fail-fast guard with actionable error message. Good pattern.
| # routable non-loopback address, so no martian filtering occurs. | ||
| # SO_ORIGINAL_DST (used by Envoy's original_dst cluster) works identically | ||
| # with DNAT — conntrack stores the pre-NAT original tuple for both targets. | ||
| ${IPT} -t nat -A PROXY_OUTPUT -m mark --mark ${ZTUNNEL_MARK} -m owner ! --uid-owner "${PROXY_UID}" -m addrtype --dst-type LOCAL -p tcp -j DNAT --to-destination "${POD_IP}:${INBOUND_PROXY_PORT}" |
There was a problem hiding this comment.
praise: Excellent inline documentation explaining the REDIRECT → DNAT rationale. The conntrack/SO_ORIGINAL_DST note is particularly valuable for future maintainers.
Signed-off-by: Hai Huang <[email protected]>
- README: Replace "Privileged: Yes" with "Capabilities: NET_ADMIN, NET_RAW" - AuthBridge/CLAUDE.md: Replace route_localnet sysctl reference with DNAT to POD_IP - AuthBridge/CLAUDE.md: Add POD_IP to init-iptables.sh environment variables table Signed-off-by: Hai Huang <[email protected]>
15f507a to
7f5c5df
Compare
Summary
privileged: truewithcapabilities: [NET_ADMIN, NET_RAW]in the proxy-init init containerREDIRECTtoDNAT $POD_IPfor the ztunnel inbound interception rule, eliminating the need forsysctl route_localnet=1(which requires privileged mode)POD_IPenvironment variable via Kubernetes Downward API (status.podIP)Context
On OpenShift, agent pods fail to start because the
anyuidSCC doesn't allowprivileged: truecontainers. See rossoctl/rossoctl#933.The
init-iptables.shscript previously required privileged mode for two reasons:iptablesmanipulation — only needsNET_ADMIN+NET_RAWcapabilitiessysctl -w net.ipv4.conf.all.route_localnet=1— needed becauseREDIRECTin the OUTPUT chain rewrites dst to127.0.0.1, and when ztunnel delivers traffic with a non-local source IP (viaIP_TRANSPARENT), the kernel treats it as martian and drops itThis PR solves (2) by using
DNATto the pod's own IP instead ofREDIRECT. The pod IP is a routable non-loopback address, so no martian filtering occurs androute_localnetis no longer needed.SO_ORIGINAL_DST(used by Envoy) works identically with bothDNATandREDIRECT.Supersedes #234, which drops privileged mode but does not address the
sysctldependency ininit-iptables.sh.Files changed
kagenti-webhook/internal/webhook/injector/container_builder.go— capabilities +POD_IPenv varAuthBridge/AuthProxy/init-iptables.sh—DNATinstead ofREDIRECT, removesysctlAuthBridge/AuthProxy/k8s/auth-proxy-deployment.yaml— capabilities +POD_IPAuthBridge/demos/single-target/k8s/authbridge-deployment{,-no-spiffe}.yaml— sameAuthBridge/demos/multi-target/k8s/authbridge-deployment{,-no-spiffe}.yaml— sameTest plan