For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/default_rules/3we-9j9-qmk.md. A documentation index is available at /llms.txt.

Kernel capabilities in Linux should only be granted when necessary

docker

Classification:

compliance

Framework:

cis-docker

Control:

5.4

Description

Containers should keep only the Linux capabilities they need, and drop NET_RAW.

Rationale

Every capability widens what a process in the container can do to the kernel. NET_RAW, granted by default, lets a container craft raw packets, spoof addresses and reach other containers despite network restrictions.

Audit

Inspect the containers:

docker ps --quiet --all | xargs docker inspect --format '{{ .Name }}: CapAdd={{ .HostConfig.CapAdd }} CapDrop={{ .HostConfig.CapDrop }}'

Datadog passes the rule when a container is unprivileged, drops NET_RAW or ALL, and adds only capabilities of Docker’s default set, and fails it otherwise.

Remediation

Drop every capability and add back the ones the workload needs:

docker run --cap-drop=ALL --cap-add=CHOWN <image>

Impact

A workload that needs a capability fails until it is added back.

Default value

Docker grants 14 capabilities, NET_RAW among them.

References

  1. https://docs.docker.com/engine/security/#linux-kernel-capabilities
  2. https://docs.docker.com/compose/compose-file/compose-file-v3/#cap_add-cap_drop
  3. https://docs.docker.com/reference/cli/docker/service/create/#options
  4. https://docs.docker.com/reference/cli/docker/container/run/#configure-namespaced-kernel-parameters-sysctls-at-runtime