Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#992 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@magic-peach đang làm issue này rồi.

Từ ngày 3/9/2026.

  • #1024 của @magic-peach — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
54/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, kubernetes
Lĩnh vực
networking

Hướng nghiên cứu

Đọc pkg/network/network_static.go, đặc biệt là setNATRule() và StaticNetwork.NetworkSetup(), sau đó kiểm tra getNetworkType() và Kill() trong pkg/unikontainers/unikontainers.go. So sánh các cách tiếp cận được đề xuất cho việc thiết lập và dọn dẹp có tính idempotent; hoàn thành có nghĩa là việc khởi động lại user-container lặp đi lặp lại không còn để lại các quy tắc NAT trùng lặp trong network namespace bền vững.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug K8s/Tools

While reviewing pkg/network/network_static.go I noticed that setNATRule() (lines 35-89) always runs iptables -t nat -A POSTROUTING -s -o -j MASQUERADE, and never checks whether an identical rule already exists before appending it. I searched the whole repository for "iptables" and this file is the only place it shows up, so there is no matching delete call anywhere else in the codebase either.

This function is called from StaticNetwork.NetworkSetup() (same file, line 103), which is only used when getNetworkType() (pkg/unikontainers/unikontainers.go, around line 1419) detects the Knative annotation io.kubernetes.cri.container-name equal to user-container.

The problem is that Kill() (pkg/unikontainers/unikontainers.go, lines 807-838) does clean up the TAP device through network.CleanupAllUruncTaps(), but it never touches iptables or removes the NAT rule that was added on setup. In Kubernetes, when a container inside a pod restarts because of a crash or a failed liveness probe, the pod's network namespace is not recreated, only the container is. So every restart calls NetworkSetup() again, which calls setNATRule() again, which appends another identical rule to the same still-alive network namespace. Since StaticIPAddr is a fixed constant, the appended rule is byte-for-byte the same every time, so nothing ever gets deduplicated or removed. Over repeated restarts this leaves an unbounded number of duplicate NAT rules sitting in that namespace's iptables nat table.

There is already a precedent for this exact pattern of bug in this project. Issue #406 documented that the network namespace persists across container restarts in Kubernetes and that TAP devices used to leak because of it, before CleanupAllUruncTaps() was added to handle that specific resource on Kill(). The NAT rule added by the same NetworkSetup() call simply has no equivalent cleanup path, so the same underlying condition applies here but was never addressed for iptables.

I checked for duplicates by searching issues for setNATRule, NAT MASQUERADE leak, iptables, and user-container restart, and found nothing describing this. The closest related issue, #587, was about a different resource and was closed as not planned because the locking it worried about turned out to already be correct, so it does not cover this.

A fix could either make setNATRule idempotent by checking for the rule with iptables -C before appending with -A, or add a matching delete function that gets called from Kill() and Delete() the same way CleanupAllUruncTaps() already is.

This is not related to VM or sandbox isolation boundaries, it is a host network hygiene issue in the CNI setup helper, so a public issue seemed appropriate rather than private disclosure.

Ngôn ngữ chính
Go
Star
307
Fork
219
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
32

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của urunc-dev/urunc

Tất cả issue của urunc-dev/urunc

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.