turbot/steampipe-mod-docker-compliance

Control: 5.10 Ensure that the host's network namespace is not shared

Description

When the networking mode on a container is set to --net=host, the container is not placed inside a separate network stack. Effectively, applying this option instructs Docker to not containerize the container's networking. The consequence of this is that the container lives outside in the main Docker host and has full access to its network interfaces.

Selecting this option is potentially dangerous. It allows the container process to open reserved low numbered ports in the way that any other root process can. It also allows the container to access network services such as D-bus on the Docker host. A container process could potentially carry out undesired actions, such as shutting down the Docker host. This option should not be used unless there is a very specific reason for enabling it.

Remediation

You should not pass the --net=host option when starting any container.

Default Value

By default, containers connect to the Docker bridge when starting and do not run in the context of the host's network stack.

Usage

Run the control in your terminal:

powerpipe control run docker_compliance.control.cis_v160_5_10

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run docker_compliance.control.cis_v160_5_10 --share

SQL

This control uses a named query:

select
id as resource,
case
when inspect -> 'HostConfig' ->> 'NetworkMode' = 'host' then 'alarm'
else 'ok'
end as status,
case
when inspect -> 'HostConfig' ->> 'NetworkMode' = 'host' then (names ->> 0) || ' host network namespace shared.'
else (names ->> 0) || ' host network namespace not shared.'
end as reason
, _ctx ->> 'connection_name' as connection_name
from
docker_container;

Tags