StaticNetwork.NetworkSetup() leaks a duplicate iptables NAT rule on every container restart in the Knative user-container path
Maintainer thường phản hồi trong vòng 1 ngày
Đá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ả
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
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của urunc-dev/urunc
-
Containers handed over to runc cannot be started, killed or deleted when urunc runs without --rootCó thể làm lại được @Daksha1611 đã nhận 7 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
urunc-dev/urunc#1127 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
urunc-deploy cleanup never labels the node, so the cleanup DaemonSet does not runCó thể đã có người làm @Sarthak-Shreshtha01 đã nhận 10 ngày trước. Đang mởbug K8s/Tools
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
FreeBSD: docs update and rootfs detectionCó thể đã có người làm @yug105 đã nhận 4 ngày trước. Đang mởdocumentation enhancement Storage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
urunc-dev/urunc#1108 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Rumprun guests receive &, < and > as \u0026, \u003c and \u003eCó thể đã có người làm @Sarthak-Shreshtha01 đã nhận 15 ngày trước. Đang mởbug Guests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
urunc-dev/urunc#1074 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hooks run concurrently instead of in the listed orderCó thể đã có người làm @anishmehta24 đã nhận 21 ngày trước. Đang mởCore enhancement OCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
urunc-dev/urunc#1066 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của urunc-dev/urunc
Issue tương tự
-
fix(handlers): explicitly set Content-Type header in static Index handlerCó thể đã có người làm @kage-zero đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Quick Open: restore dependency-directory exclusions in filesystem fallbackCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
eugenioenko/ttt#1206 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
open-policy-agent/opa#9426 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rorkai/App-Store-Connect-CLI#3192 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t:urlDecodeUni does not map U+3002 and U+FF61 to a dot, unlike ModSecurityCó thể đã có người làm @fzipi đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày