Skip to content

Default the sysctl net.ipv4.ip_unprivileged_port_start to 0 #4595

@polarathene

Description

@polarathene

What is the problem you're trying to solve

This FAQ entry:

nerdctl/docs/faq.md

Lines 319 to 323 in 2165e30

### `nerdctl run -p <PORT>` does not work with port numbers below 1024
Set sysctl value `net.ipv4.ip_unprivileged_port_start=0` .
See https://rootlesscontaine.rs/getting-started/common/sysctl/#optional-allowing-listening-on-tcp--udp-ports-below-1024

There is also this somewhat related issue regarding --cap-add NET_BIND_SERVICE with extra details (I chimed in Dec 2023, which would be containerd 1.x).

The sysctl is namespaced, affecting binding of a port within the container, not the port on the host. It's generally considered a safe default to lower this down to 0 for containers.

Describe the solution you'd like

Default net.ipv4.ip_unprivileged_port_start to 0.

It is considered safe:

  • Podman and Docker already lower this to 0 by default and have for some time now.
  • Containerd allows it since 2.0, but only via the CRI plugin which nerdctl does not use.
  • Kubernetes does not yet default to it, but it is considered a safe sysctl. Other tools in the k8s ecosystem (such as k3s, kind, minikube) do however default enable this setting.

Additional context

nerdctl was one of the few I came across that hasn't adopted this change - yet has a FAQ entry about it (and only one report where a user encountered an issue).

It's mostly a convenience, but it does help avoid a practice of images relying on setcap to enforce the associated capability for non-root processes to use. Which as my prior link details, when such images make a capability mandatory it prevents dropping it for security reasons (even when that capability would not be used within the container).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions