Skip to content

Conversation

@yashkukrecha
Copy link
Contributor

This PR makes nerdctl default the container's net.ipv4.ip_unprivileged_port_start sysctl to 0, unless the user has explicitly set this sysctl via --sysctl.

Key changes:

  • Adds a new helper withDefaultUnprivilegedPortSysctl in pkg/cmd/container/container.go.
  • Applies this helper during container creation, after user-supplied sysctls are parsed.
  • If the user passes a --sysctl for net.ipv4.ip_unprivileged_port_start, nerdctl does not override it.

Note: Host-wide sysctl configuration and containerd-rootless-setuptool.sh were intentionally left unchanged in this PR to keep the scope focused on the container namespace default requested in the issue.

Fixes #4595

opts = append(opts, umaskOpts...)

if !isHostNetwork(netLabelOpts) {
opts = append(opts, withDefaultUnprivilegedPortSysctl(options.Sysctl))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflicts with:

opts = append(opts, WithSysctls(strutil.ConvertKVStringsToMap(options.Sysctl)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the defaulting for net.ipv4.ip_unprivileged_port_start in create.go, building on top of the behavior in run_linux.go. Does this still conflict?

@AkihiroSuda
Copy link
Member

Please fix the lint errors, squash the commits, and sign off the DCO

@yashkukrecha yashkukrecha force-pushed the fix-unprivileged-port-default branch from 9d214b1 to 56f05ed Compare November 27, 2025 17:47
@yashkukrecha
Copy link
Contributor Author

Hi @AkihiroSuda, should all the tests be passing?

@haytok
Copy link
Contributor

haytok commented Dec 3, 2025

The tests for this update has failed.

=== Failed
=== FAIL: cmd/nerdctl/container TestContainerInspectHostConfigDefaults (0.67s)
    container_inspect_linux_test.go:343: HostConfig in TestContainerInspectHostConfigDefaults: &{ContainerIDFile: LogConfig:{Driver:json-file Opts:map[] LogURI: Address:/run/containerd/containerd.sock} PortBindings:map[] CgroupnsMode:private DNS:[] DNSOptions:[] DNSSearch:[] ExtraHosts:[] GroupAdd:[1 2 3 4 6 10 11 20 26 27] IpcMode:private OomScoreAdj:0 PidMode: ReadonlyRootfs:false Tmpfs:map[] UTSMode: ShmSize:0 Sysctls:map[net.ipv4.ip_unprivileged_port_start:0] Runtime:io.containerd.runc.v2 CPUSetMems: CPUSetCPUs: CPUQuota:0 CPUShares:0 CPUPeriod:0 CPURealtimePeriod:0 CPURealtimeRuntime:0 Memory:0 MemorySwap:0 OomKillDisable:false Devices:[] BlkioSettings:{BlkioWeight:0 BlkioWeightDevice:[] BlkioDeviceReadBps:[] BlkioDeviceWriteBps:[] BlkioDeviceReadIOps:[] BlkioDeviceWriteIOps:[]}}
    container_inspect_linux_test.go:365: assertion failed: 0 (int) != 1 (int)

Therefore, at least the following fixes are required:

@yashkukrecha yashkukrecha force-pushed the fix-unprivileged-port-default branch 2 times, most recently from a8eb601 to 96455de Compare December 8, 2025 17:50
@yashkukrecha
Copy link
Contributor Author

Hi, the only failing job is in-host - Windows. Looking at the logs, all the cmd/nerdctl/container tests are failing because nerdctl run returns a non-zero exit code with:

failed to create shim task: kernel: 'C:\Program Files\Linux Containers\kernel' not found

This seems like an environment issue in the Windows runner rather than something caused by my PR. Does this test need to be resolved before merging my PR?

@AkihiroSuda
Copy link
Member

Can you try rebasing with the current main branch ?

@yashkukrecha yashkukrecha force-pushed the fix-unprivileged-port-default branch from 96455de to 0a591e8 Compare December 12, 2025 21:12
@AkihiroSuda
Copy link
Member

Doesn't look rebased well
https://lima-vm.io/docs/dev/git/#rebasing-onto-upstream-master

@yashkukrecha yashkukrecha force-pushed the fix-unprivileged-port-default branch from b262ece to bc45754 Compare December 15, 2025 20:08
@yashkukrecha
Copy link
Contributor Author

I rebased and it resulted in some failing flaky tests but also some failures unrelated to my PR, such as logging and binding to host port 5000.

@AkihiroSuda AkihiroSuda added this to the v2.2.1 milestone Dec 16, 2025
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why Windows CI is still failing.
Maybe GHA is now deterministically picking a broken runner instance by the PR number?

@AkihiroSuda AkihiroSuda merged commit d43e143 into containerd:main Dec 16, 2025
108 of 116 checks passed
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.

Default the sysctl net.ipv4.ip_unprivileged_port_start to 0

3 participants