← Back to Pull requests

fix: allow explicitly overlapping network subnets #5297

Open
mvanhorn opened this pull request with 57 lines diff across 3 files
View on GitHub
mvanhorn mvanhorn commented on Oct 28, 2026 07:28 UTC
Author

Motivation

Creating an explicitly configured network whose subnet overlaps an existing host or CNI subnet fails. This prevents valid setups such as macvlan networks and nested nerdctl environments.

parseSubnet rejected any subnet that intersected the set of already used subnets, returning an overlap error even when the caller explicitly requested that subnet.

What this changes

Removed the subnet-intersection rejection from parseSubnet, while retaining validation that the supplied address is the canonical network address. Added a regression test confirming that an explicitly overlapping subnet is accepted.

Testing

The netutil packages passed their Go tests. The modified files passed formatting and vet checks. The tests in pkg/netutil/netutil_test.go fail without the fix in the nerdctl change (checked by reverting the source changes).

Fixes #4281

Diff: 57 lines (+50 / -7) across 3 files Reviewer: AkihiroSuda Review duration: 8113m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.30) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.30 · 57 lines diff across 3 files
0.30
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
91%
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.243
Real PR Conversation Timeline
7 items
AkihiroSuda AkihiroSuda commented on Oct 28, 2026 07:33 UTC
Contributor

Testing

Did you test it with manual invocation of nerdctl too?
Also, can we have an integration test?

mvanhorn mvanhorn commented on Oct 28, 2026 18:12 UTC
Author

Yes to both. 27ac399 adds an integration subtest in cmd/nerdctl/network/network_create_linux_test.go that creates a network whose explicit subnet overlaps an existing one and runs a container on it.

Manual run in a Lima VM, before and after:

  • Stock nerdctl v2.3.5: nerdctl network create --subnet 10.4.0.0/25 ... with an overlapping network already present fails with subnet 10.4.0.0/25 overlaps with other one on this address space.

  • This branch: the same command succeeds, and a container on the new network gets 10.8.0.2/25. The rootful case where the subnet overlaps the host's own 192.168.5.0/24 works too.
  • The new integration test passes with the branch build and fails with stock nerdctl. That run was on 33f0d7b; 6c96741 since then only skips the used-subnet lookup when a subnet is given, so the explicit-subnet path it tests no longer reads that list at all.

    <!-- r:ef724be3d57e.99b077af96c0 -->

    AkihiroSuda AkihiroSuda commented on code on Oct 29, 2026 01:49 UTC
    Code Review
    cmd/nerdctl/network/network_create_linux_test.go:1
    @@ -326,6 +326,31 @@ func TestNetworkCreate(t *testing.T) {
     			},
     			Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
     		},
    +		{
    +			Description: "with an explicit subnet overlapping an existing network",

    The test should also verify the functionality of networking by running actual containers and let them communicate

    AkihiroSuda AkihiroSuda commented on code on Oct 29, 2026 01:50 UTC
    Code Review
    cmd/nerdctl/network/network_create_linux_test.go:1
    @@ -326,6 +326,31 @@ func TestNetworkCreate(t *testing.T) {
     			},
     			Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
     		},
    +		{
    +			Description: "with an explicit subnet overlapping an existing network",
    +			// Docker rejects overlapping pools, nerdctl honors an explicit --subnet (#4281).

    So why do we need to support overlapping pools?

    mvanhorn mvanhorn commented on code on Oct 29, 2026 13:30 UTC
    Code Review
    cmd/nerdctl/network/network_create_linux_test.go:1
    @@ -326,6 +326,31 @@ func TestNetworkCreate(t *testing.T) {
     			},
     			Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
     		},
    +		{
    +			Description: "with an explicit subnet overlapping an existing network",

    Done in 8b8c0a7. The subtest now starts a container on the overlapping 10.7.0.0/25 network, checks that its address is inside that subnet, and pings it by name from a second container on the same network.

    I ran it in a Lima VM (Ubuntu, rootless containerd). With the branch build it passes: the container got 10.7.0.4 and the ping came back. With stock nerdctl v2.3.5 it fails at network create with subnet 10.7.0.0/25 overlaps with other one on this address space. The rest of TestNetworkCreate passes too.

    <!-- r:8a537d86c552.18998ff369ba -->

    mvanhorn mvanhorn commented on code on Oct 29, 2026 13:32 UTC
    Code Review
    cmd/nerdctl/network/network_create_linux_test.go:1
    @@ -326,6 +326,31 @@ func TestNetworkCreate(t *testing.T) {
     			},
     			Expected: test.Expects(expect.ExitCodeSuccess, nil, nil),
     		},
    +		{
    +			Description: "with an explicit subnet overlapping an existing network",
    +			// Docker rejects overlapping pools, nerdctl honors an explicit --subnet (#4281).

    The cases from #4281 are mostly overlaps with subnets that already exist on the host, not with another nerdctl pool:

  • macvlan/ipvlan networks have to use the parent interface's LAN subnet, which is by definition already on the host.

  • nerdctl inside a nerdctl container: the outer bridge subnet (for example 10.4.0.0/24) shows up as an interface inside the inner one, so the inner default network can't be created.

  • Hosts whose DHCP lease falls inside the requested range.
  • usedSubnets() merges host interface addresses with the subnets of existing CNI configs, and any active nerdctl bridge also shows up as a host interface, so one check covered both. The test uses a second nerdctl network only because that's the overlap CI can set up anywhere. The change only applies when --subnet is given explicitly. Automatic allocation still picks a free subnet.

    If you'd rather keep rejecting overlaps between two nerdctl-managed networks and only allow overlaps with host interfaces, I can split the check that way.

    <!-- r:8a537d86c552.f74bc41581cf -->

    Reviewers
    Assignees
    mvanhorn mvanhorn
    Labels
    risk: low confidence: 91.1% 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: 30.2% (LOW) · Higher = larger blast radius
    30.2%
    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: 91.1% · Lower = rushed or shallow review
    91.1%
    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: 2.7% · Safe to merge
    2.7%