Skip to content

Avoid duplicate iptables NAT rule on container restart - #1024

Open
magic-peach wants to merge 1 commit into
urunc-dev:mainfrom
magic-peach:fix/992-iptables-nat-leak
Open

Avoid duplicate iptables NAT rule on container restart#1024
magic-peach wants to merge 1 commit into
urunc-dev:mainfrom
magic-peach:fix/992-iptables-nat-leak

Conversation

@magic-peach

Copy link
Copy Markdown
Contributor

Description

StaticNetwork.NetworkSetup() always ran iptables -t nat -A ... with no existence check, so restarting a container leaked a duplicate NAT rule each time. Adds an existence check (via iptables -C, exit 0 = exists) before appending, matching the fix approach suggested in the issue.

Related issues

How was this tested?

Cross-compiled and vetted clean (GOOS=linux GOARCH=amd64).

LLM usage

none

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

StaticNetwork.NetworkSetup() calls setNATRule() unconditionally on
every setup, appending a MASQUERADE rule with -A regardless of
whether it is already there. Since the network namespace survives a
Kubernetes container restart (the same condition that used to leak
TAP devices before CleanupAllUruncTaps() was added for urunc-dev#406), Kill()
never removes this rule, so every restart appends another identical
one to the same namespace.

Check for the rule with iptables -C before appending it with -A, so
setNATRule() becomes idempotent across restarts.

Fixes urunc-dev#992

Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit d9c342e
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a999bc753c0da00084bc389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StaticNetwork.NetworkSetup() leaks a duplicate iptables NAT rule on every container restart in the Knative user-container path

1 participant