← Back to Pull requests

Import `utiliptables`, update to do mode detection #23

Merged
danwinship merged 60 files (9303 lines) on Oct 23, 2026 19:07 UTC
View on GitHub
danwinship danwinship commented on Oct 15, 2026 14:50 UTC
Author

Imports utiliptables from k/k, fixes up the API some, and adds mode autodetection. With this, we'll be able to make kube-proxy just autodetect the mode itself (https://github.com/kubernetes/kubernetes/pull/143065), without needing an installed iptables-wrapper binary, which will make our lives simpler. (cc @BenTheElder )

(Built on top of #21 and #22; this PR starts from "Import utiliptables from k/k".)

Diff: 9303 lines (+9269 / -34) across 60 files Reviewer: aojea Review duration: 11776m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.72) × (1 − Review Confidence (0.80)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.72 · 9303 lines diff across 60 files
0.72
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.62 · 5 substantive comment(s)
0.62
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
79%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
12 items
BenTheElder BenTheElder commented on Oct 23, 2026 00:23 UTC
Contributor

Does this mean we'll have to go patch this image for every go CVE? k/k just exited that, and I think they've been more frequent than glibc etc.

https://docs.google.com/document/d/10HujH6PL0ez3vviA03I01_mbJWs9Xp99gIDWnnNXyco/edit?tab=t.0

BenTheElder BenTheElder commented on Oct 23, 2026 00:23 UTC
Contributor

cc @liggitt

danwinship danwinship commented on Oct 23, 2026 11:07 UTC
Author

Does this mean we'll have to go patch this image for every go CVE?

There's no image. This is just creating a new vendored dependency, which will then let us remove stuff from distroless-iptables:

  • Current system: distroless-iptables includes the old bash-based version of iptables-wrapper, which requires us to install a bunch of other debian binaries into distroless-iptables as well for support.

  • Original upgrade plan: We were supposed to update distroless-iptables to use the new golang-based iptables-wrapper (https://github.com/kubernetes/release/issues/2992) so we could drop all of the other binaries and have _just_ iptables-wrapper, iptables, ipset, and nft in the distroless-iptables image. But you (Ben) pointed out that this would mean having to rebuild iptables-wrapper any time there was a golang CVE, which would probably end up being more work than having to rebuild any time there was a bash, etc, CVE. This eventually led to the:

  • New-and-improved upgrade plan: We update kube-proxy's golang iptables package to do the legacy-vs-nft detection itself rather than depending on an external binary to do it (this PR plus https://github.com/kubernetes/kubernetes/pull/143065), and then we don't need either version of iptables-wrapper in distroless-iptables.
  • (The golang-based iptables-wrapper binary in this module still exists for anyone else who was using it, but kubernetes itself won't use it any more.)

    (Ah, I guess I didn't actually explain this entirely in the initial PR description, but we had discussed the idea in another PR a few months ago...)

    BenTheElder BenTheElder commented on Oct 23, 2026 13:13 UTC
    Contributor

    Thanks.

    Yeah, I'm having a hard time keeping up at the moment, apologies. Big pre-kubecon push for a new CNCF project.

    There are currently some release threads where the project is again doing a TON of work for what should be one-line .go-version patch and trigger a release soon. Can't wait for 1.35 to EOL and then cleanup the vestigial go-runner base. I got worried we're going the other way again. I recall that thread now.

    aojea aojea commented on code on Oct 23, 2026 17:10 UTC
    Code Review
    pkg/iptables/monitor_test.go:1
    @@ -292,8 +291,19 @@ func TestIPTablesMonitor(t *testing.T) {
     	close(stopCh)
     }
     
    +func pollImmediate(interval, timeout time.Duration, condition func() (done bool, err error)) error {
    +	for range timeout / interval {
    +		done, err := condition()
    +		if done {

    I think the semantics of pollImmediate here will be if done || err != nil is when it stop polling

    aojea aojea commented on code on Oct 23, 2026 17:12 UTC
    Code Review
    pkg/iptables/monitor.go:1
    @@ -0,0 +1,134 @@
    +//go:build linux
    +
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package iptables
    +
    +import (
    +	"time"
    +
    +	"k8s.io/klog/v2"
    +)
    +
    +const (
    +	// Max time we wait for an iptables flush to complete after we notice it has started
    +	iptablesFlushTimeout = 5 * time.Second
    +	// How often we poll while waiting for an iptables flush to complete
    +	iptablesFlushPollTime = 100 * time.Millisecond
    +)
    +
    +type monitor struct {
    +	runner     *runner
    +	canary     Chain
    +	tables     []Table
    +	reloadFunc func()
    +	interval   time.Duration
    +	stopCh     <-chan struct{}
    +}
    +
    +// Monitor is part of Interface
    +func (runner *runner) Monitor(canary Chain, tables []Table, reloadFunc func(), interval time.Duration, stopCh <-chan struct{}) {
    +	mon := &monitor{runner, canary, tables, reloadFunc, interval, stopCh}
    +	mon.run()
    +}
    +
    +func (mon *monitor) run() {
    +	defer mon.cleanupCanaries()
    +	for {
    +		mon.ensureCanaries()
    +
    +		for {
    +			time.Sleep(mon.interval)

    I don't know how much we care about this function but for completeness this should be cancellable

    timer := time.NewTimer(d)
    	defer timer.Stop()
    
    	select {
    	case <-mon.stopCh:
    		return false
    	case <-timer.C:
    		return true
    	}
    

    aojea aojea commented on Oct 23, 2026 17:16 UTC
    Contributor

    LGTM the only question is about how much we care about the apimachinery replacement for the Monitor method

    danwinship danwinship commented on code on Oct 23, 2026 17:59 UTC
    Code Review
    pkg/iptables/monitor.go:1
    @@ -0,0 +1,134 @@
    +//go:build linux
    +
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package iptables
    +
    +import (
    +	"time"
    +
    +	"k8s.io/klog/v2"
    +)
    +
    +const (
    +	// Max time we wait for an iptables flush to complete after we notice it has started
    +	iptablesFlushTimeout = 5 * time.Second
    +	// How often we poll while waiting for an iptables flush to complete
    +	iptablesFlushPollTime = 100 * time.Millisecond
    +)
    +
    +type monitor struct {
    +	runner     *runner
    +	canary     Chain
    +	tables     []Table
    +	reloadFunc func()
    +	interval   time.Duration
    +	stopCh     <-chan struct{}
    +}
    +
    +// Monitor is part of Interface
    +func (runner *runner) Monitor(canary Chain, tables []Table, reloadFunc func(), interval time.Duration, stopCh <-chan struct{}) {
    +	mon := &monitor{runner, canary, tables, reloadFunc, interval, stopCh}
    +	mon.run()
    +}
    +
    +func (mon *monitor) run() {
    +	defer mon.cleanupCanaries()
    +	for {
    +		mon.ensureCanaries()
    +
    +		for {
    +			time.Sleep(mon.interval)

    I was trying to keep it simple...

    We know the timeout will eventually time out, and then the very next line checks the context. So worst case is just that the goroutine lingers longer than it should before exiting. And there's no API that lets you know when the Monitor exited, so it's not like we'll be forcing anyone else to wait that extra time along with us. So it seemed harmless to just have the simpler one-liner rather than your more-correct 8-liner.

    danwinship danwinship commented on code on Oct 23, 2026 18:02 UTC
    Code Review
    pkg/iptables/monitor_test.go:1
    @@ -292,8 +291,19 @@ func TestIPTablesMonitor(t *testing.T) {
     	close(stopCh)
     }
     
    +func pollImmediate(interval, timeout time.Duration, condition func() (done bool, err error)) error {
    +	for range timeout / interval {
    +		done, err := condition()
    +		if done {

    ah, none of the cases in the unit test ever return an error... ~I should just remove that arg~. but I'll leave it, for consistency with the real PollImmediate, and in case we need it later.

    aojea aojea commented on Oct 23, 2026 19:03 UTC
    Contributor

    /lgtm
    /approve

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Oct 23, 2026 19:03 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/iptables-wrappers/pull/23#issuecomment-6372585076" title="Approved">aojea</a>, <a href="https://github.com/kubernetes-sigs/iptables-wrappers/pull/23#" title="Author self-approved">danwinship</a>

    The full list of commands accepted by this bot can be found here.

    The pull request process is described here

    <details >
    Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [aojea,danwinship]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Reviewers
    Assignees
    danwinship danwinship
    Labels
    risk: low confidence: 79.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 79.8% · Lower = rushed or shallow review
    79.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 14.4% · Safe to merge
    14.4%