turbot/docker_compliance

Control: 5.13 Ensure that the container's root filesystem is mounted as read only

Description

The container's root filesystem should be treated as a 'golden image' by using Docker run's --read-only option. This prevents any writes to the container's root filesystem at container runtime and enforces the principle of immutable infrastructure.

Enabling this option forces containers at runtime to explicitly define their data writing strategy to persist or not persist their data.

This also reduces security attack vectors since the container instance's filesystem cannot be tampered with or written to unless it has explicit read-write permissions on its filesystem folder and directories.

Remediation

You should add a --read-only flag at a container's runtime to enforce the container's root filesystem being mounted as read only.

docker run <Run arguments> --read-only <Container Image Name or ID> <Command>

Enabling the --read-only option at a container's runtime should be used by administrators to force a container's executable processes to only write container data to explicit storage locations during its lifetime.

Examples of explicit storage locations during a container's runtime include, but are not limited to:

  1. Using the --tmpfs option to mount a temporary file system for non-persistent data writes.
docker run --interactive --tty --read-only --tmpfs "/run" --tmpfs "/tmp"
centos /bin/bash
  1. Enabling Docker rw mounts at a container's runtime to persist container data directly on the Docker host filesystem.
docker run --interactive --tty --read-only -v /opt/app/data:/run/app/data:rw
centos /bin/bash
  1. Utilizing the Docker shared-storage volume plugin for Docker data volume to persist container data.
docker volume create -d convoy --opt o=size=20GB my-named-volume
docker run --interactive --tty --read-only -v my-named-volume:/run/app/data
centos /bin/bash
  1. Transmitting container data outside of the Docker controlled area during the container's runtime for container data in order to ensure that it is persistent. Examples include hosted databases, network file shares and APIs.

Default Value

By default, a container has its root filesystem writeable, allowing all container processes to write files owned by the container's actual runtime user.

Usage

Run the control in your terminal:

powerpipe control run docker_compliance.control.cis_v160_5_13

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

docker_container_root_filesystem_mounted

Tags