Host devices should not be directly exposed to containers

docker

Classification:

compliance

Framework:

cis-docker

Control:

5.18

Description

Containers should have no host device mapped into them.

Rationale

A container given a host device can read and write it, a disk among others, below every file permission of the host.

Audit

Inspect the containers:

docker ps --quiet --all | xargs docker inspect --format '{{ .Name }}: Devices={{ .HostConfig.Devices }} DeviceRequests={{ .HostConfig.DeviceRequests }} DeviceCgroupRules={{ .HostConfig.DeviceCgroupRules }}'

Datadog passes the rule when a container maps no host device, with --device, --gpus or a device cgroup rule, and fails it otherwise. A container that needs a device, such as a GPU, fails and needs a manual review.

Remediation

Run the container without --device, or with only the devices it needs and the narrowest permissions, such as --device=/dev/xvdc:/dev/xvdc:r.

Impact

None.

Default value

Containers get the default devices of Docker, such as /dev/null and /dev/zero.

References

  1. https://docs.docker.com/reference/cli/docker/container/run/#add-host-device-to-container—device