TMAegisBeta
More rules for docker

Docker

TMA-DOCKER-4.1

Ensure that a user for the container has been created

MediumLevel 1Automateddocker

Description

Containers should run as a non-root user defined in the image (USER) or at run time (--user). Flags containers whose configured user (Config.User) is empty, root or 0; processes that start as root and drop privileges themselves are reported too and need review. The audit inspects every running container (docker ps -q) and prints the offending names; a host with no running containers is compliant.

How it is checked

Audit method: Shell command

shell
ids=$(docker ps -q) || exit 1; [ -z "$ids" ] && { echo compliant; exit 0; }; out=$(docker inspect --format '{{.Name}} [{{.Config.User}}]' $ids) || exit 1; bad=$(printf '%s\n' "$out" | awk '$2=="[]" || $2 ~ /^\[(root|0)(:.*)?\]$/ {print $1}'); [ -z "$bad" ] && echo compliant || printf '%s\n' "$bad"
Expected output
compliant

How it is fixed

Fix method: Guidance or infrastructure patch

Add a USER instruction to the Dockerfile (RUN useradd -r app && ... USER app) or run the container with --user <uid>:<gid>.

Properties

Operating systems
Any
Tags
dockerimageruntime
Reference
CIS Docker Benchmark v1.9.0 - 4.1 Ensure that a user for the container has been created

Check this host

Run this on a machine you are allowed to audit. The scan is read-only.

shell
tmaegis scan --target docker