Review low port mappings and privileges

Publish only required ports and remove network privileges the service does not need.

Description

ports maps a published host port to a port the application listens on inside the container. Mapping a traditional system port (1–1023) does not give the container root privileges. The namespace’s ip_unprivileged_port_start determines which local ports require special privileges to bind.

Potential impact

Unneeded ports widen network exposure, and extra capabilities increase the impact of a compromise. Changing a port required by the protocol can prevent clients from connecting.

Remediation

  • If the application can change ports, consider a listener on port 1024 or higher and drop NET_BIND_SERVICE when unnecessary. Test with the actual user and namespace settings.
  • Keep protocol-required ports for services such as DHCP. Publish only the host ports you need, and apply authentication and firewall controls regardless of port number.

Examples

DHCP clients contact the server on UDP port 67. The second example is for a different application listening on 6700/udp. Set APP_IMAGE to that application’s image.

Before

yaml
services:
  dhcpd:
    image: networkboot/dhcpd:latest
    ports:
      - "67:67/udp"

After

yaml
services:
  app:
    image: ${APP_IMAGE:?set APP_IMAGE}
    ports:
      - "6700:6700/udp"
    cap_drop:
      - NET_BIND_SERVICE

Explanation:

  • Before: The DHCP server publishes 67/udp on the host.
  • After: The other application publishes 6700/udp and drops NET_BIND_SERVICE. Restrict access to this port as well.

References