CL-0006: cap_drop ALL — mapping “Operation not permitted” to capabilities¶
Severity: MEDIUM (how it is derived)
The service keeps the 14 capabilities Docker grants every container by default. Drop them all and add back only the ones the image actually uses.
Fix¶
Drop all capabilities and add back only the specific ones your application requires:
services:
web:
image: nginx:1.27-alpine
cap_drop:
- ALL
cap_add:
- CHOWN # entrypoint chowns /var/cache/nginx at startup
- SETUID # ...then drops the workers to the nginx user
- SETGID
Verified against Docker 29.7.2: this container reaches running, serves a
request, survives a restart, and its worker processes still run as nginx
rather than root. The capability list is image-specific — nginx:1.27-alpine
needs these three, and another image will need a different set. To find it:
- Start from nothing:
cap_drop: [ALL]and nocap_add. The commands below use the service nameweb; use your own.
docker compose up -d web
docker compose ps -a web # "exited" or "restarting" means something failed
running is not proof either: nginx without SETUID stays running while
every worker fails setuid(101) and nothing is served
(verify function, not just startup).
Many services (static binaries, images that already run as a non-root user) need no capabilities at all, and stop here.
- Read what failed. A missing capability almost always logs
Operation not permitted, naming the operation. Read the service's logs:
docker compose logs web # add --tail 50 for just the end
or show only the lines that point at a capability:
docker compose logs web 2>&1 | grep -i -E 'operation not permitted|permission denied'
For nginx:1.27-alpine with no capabilities that prints
nginx: [emerg] chown("/var/cache/nginx/client_temp", 101) failed (1: Operation not permitted)
(captured on Docker 29.7.2, not CI-asserted), which is CHOWN. Reading the failure maps the
other common messages.
You can also read the image's entrypoint script, even before you start the
container. It does not work for nginx, whose chown comes from the nginx
binary rather than the script, so this example uses postgres:16:
# Find the entrypoint's name
docker image inspect --format '{{json .Config.Entrypoint}}' postgres:16
# ["docker-entrypoint.sh"]
# Print the script and keep the lines that need capabilities
docker run --rm --entrypoint cat postgres:16 /usr/local/bin/docker-entrypoint.sh \
| grep -n -E 'chown|gosu|su-exec'
# 58: find "$PGDATA" \! -user postgres -exec chown postgres '{}' +
# 343: exec gosu postgres "$BASH_SOURCE" "$@"
(Output trimmed.) Run docker pull postgres:16 first if the image is not
local. A bare name like docker-entrypoint.sh is on the image's PATH,
usually /usr/local/bin. A gosu or su-exec line means SETUID and
SETGID; a chown means CHOWN, often with DAC_OVERRIDE.
-
Add back the capability that failure maps to, then repeat. One at a time, so you know which were needed. Each round, exercise what the service actually does and restart it once, not just the first start: a running container is not proof.
-
Check what the container ended up with. The kernel lists each process's capabilities in
/proc/<pid>/status. TheCapBndline is the bounding set, the most any process in the container can ever hold, written as a hex bitmask thatcapshturns into names:
# Read the bounding set of the container's main process (PID 1)
docker compose exec web grep CapBnd /proc/1/status
# CapBnd: 00000000000000c1
# Decode the hex into capability names (on the host; capsh ships with libcap)
capsh --decode=00000000000000c1
# 0x00000000000000c1=cap_chown,cap_setgid,cap_setuid
It should list exactly what you added. Docker's default, with nothing
dropped, reads 00000000a80425fb. Check CapBnd whether the service runs
as root or not: the CapEff line in the same file, what the process holds
right now, reads 0 for a non-root process even when the set is right.
capabilities(7)
explains each set.
Do not copy cap_add: [NET_BIND_SERVICE] here as a starting point. It is inert
for this image — under Docker's per-container network namespaces a low port
needs no capability since 20.10 — and on its own it leaves the chown from
step 2 failing, which crash-loops the container.
Tested on: Docker 29.7.2 with Compose 5.5.0, on a host without AppArmor (Yama ptrace_scope 1); the Fix steps above were re-run there in October 2026. Not tested: an AppArmor or SELinux host; BCC capable.
Determining required capabilities¶
There is no trustworthy registry mapping images to required capabilities — the required set depends on the image's entrypoint and your configuration (bind-mount ownership, user: overrides, network mode), so it has to be determined per service. The method is the drop-and-observe
loop in Fix; the sections below are the detail behind its steps.
Verify function, not just startup¶
A running, "healthy" container is not proof the required set is complete: applications routinely catch a capability failure and continue with that feature disabled, so the damage shows up only in the logs or as a feature quietly not working.
Real example: a home-automation stack under cap_drop: [ALL] booted clean and served its UI, while its DHCP device-discovery integration died silently — the only trace was Cannot watch for dhcp packets: [Errno 1] Operation not permitted in the logs, until NET_RAW was restored.
After startup, read the full container logs for Operation not permitted / permission denied, then exercise the service's actual functionality — background behaviors included (device discovery, scheduled jobs, notifications, transcoding), not just the landing page. Healthchecks and orchestrator rollback gates won't catch healthy-but-degraded: a monitoring agent that loses a collector to a missing capability (e.g. per-process metrics without SYS_PTRACE) keeps serving its dashboard while an entire metrics family quietly disappears.
Reading the failure¶
A missing capability almost always surfaces as Operation not permitted (EPERM) — occasionally Permission denied (EACCES) — in the container logs, naming the operation that failed. Find the message below and add the capability beside it. Exact wording varies between busybox, coreutils, and glibc builds of the same tool.
| Symptom in logs (verbatim) | Operation | Capability to add |
|---|---|---|
chown: /data: Operation not permitted (busybox) · chown: changing ownership of '/data': Operation not permitted (coreutils) |
ownership fixup at startup | CHOWN, often plus DAC_OVERRIDE, sometimes FOWNER |
chmod: /data: Operation not permitted (busybox) · chmod: changing permissions of '/data': Operation not permitted (coreutils) — target owned by another uid |
permission fixup on foreign-owned files | FOWNER |
su: can't set groups: Operation not permitted — likewise su-exec/gosu setuid/setgid failures |
entrypoint switches users | SETUID + SETGID |
nc: bind: Permission denied / bind failure on a port below 1024 — in practice only under network_mode: host or a hardened ip_unprivileged_port_start; in a container's own network namespace low ports need no capability (Docker 20.10+) |
privileged-port bind | NET_BIND_SERVICE |
ping: permission denied (are you root?) (busybox; other ping builds work capless via ICMP datagram sockets) · Cannot watch for dhcp packets: [Errno 1] Operation not permitted |
raw sockets: ping, DHCP/ARP watching, packet capture | NET_RAW |
mknod: /dev/foo: Operation not permitted |
device-node creation | MKNOD |
ip: RTNETLINK answers: Operation not permitted |
interface, route, or firewall changes (VPN and router containers) | NET_ADMIN |
renice: setpriority: Permission denied |
raising scheduling priority (media servers, realtime audio) | SYS_NICE |
date: can't set date: Operation not permitted |
setting the system clock (chrony, ntpd) | SYS_TIME |
kill: can't kill pid 1: Operation not permitted |
a root supervisor signaling children that run as another uid | KILL |
mlockall: Operation not permitted — surfaced by apps as vault's Failed to lock memory or Elasticsearch's Unable to lock JVM Memory; often silent: the service runs, the swap-protection is simply absent |
locking memory to keep secrets out of swap | IPC_LOCK |
How these are checked: every mapping is re-proven on each CI run (scripts/validate_rule_premises.py: the operation must fail under cap_drop: [ALL] and succeed with only the mapped capability added), with the busybox wordings asserted verbatim (the paths in the table are placeholders; the CI checks use their own). The coreutils variants were captured from a live Debian container but are not CI-asserted, and application-level wordings (DHCP watcher, vault, Elasticsearch) are as those applications report them.
Adding capabilities back¶
Repeat the loop — the functional check above included, not just the boot — until the service is fully working. Add one at a time — adding a batch hides which ones were actually needed. Never "fix" a failure with privileged: true or by skipping cap_drop: [ALL] entirely; that trades one MEDIUM finding for a worse posture (CL-0002).
The result is configuration-specific: changing a bind mount's ownership, the user: directive, or the image major version can change the required set, so re-verify after those changes.
Auditing tools¶
When log messages are too vague to map, observe the container directly:
capable(from BCC; bpftrace ships an equivalentcapable.bt) tracescap_capable()checks kernel-wide, printing which process checked which capability. Run it on the host while exercising the container's startup and main workflows. It shows checks, not verdicts — there is no granted/denied column, and the kernel checks some capabilities speculatively for operations the application tolerates failing — so treat its output as candidates and confirm each one with a drop-and-observe run rather than adding everything it prints.docker diff <container>lists files created or changed in the container's writable layer — volumes and bind mounts never appear in it. Run it against the service before hardening: ownership or permission churn on non-volume paths reveals startup fixups that will needCHOWN/FOWNERonce capabilities are dropped. The common fixup that targets a volume is exactly what it cannot see; for that, read the entrypoint or the logs (Fix, step 2).- Inspektor Gadget (
ig).ig run trace_capabilities --containername <name> --audit-onlytraces one container's capability checks with aCAPABLEcolumn (false= the check failed);<name>is the runtime name (<project>-<service>-1). Keep--audit-only: without it the trace also lists hundreds ofCAP_SYS_ADMINchecks the kernel makes on ordinary calls such asmmapandexecve, which fail harmlessly. Even then treat afalserow as a candidate: onnginx:1.27-alpineundercap_drop: [ALL]it flaggedDAC_OVERRIDEas well as theCHOWNthe service needs (ig v0.54.0, Docker 29.7.2). For a read-only root,ig run trace_open --containername <name> --failedlists failed opens, not failedmkdirorchown. Both run on the host as root. - Mint (formerly DockerSlim) observes a container and generates seccomp and AppArmor profiles from what it saw. It does not produce a capability set, and is only as complete as the workload it watched.
- Read the entrypoint (Fix, step 2). Most official images publish their entrypoint script; a
gosu/su-execinvocation or an explicitchownthere tells you the required set before you ever start the container.
Compatibility¶
cap_drop: [ALL] is incompatible with images whose entrypoints assume default capabilities. Common breakages:
gosu/su-execuser-switching entrypoints (postgres, redis, mysql, valkey) — needSETUIDandSETGID, plusCHOWNand oftenDAC_OVERRIDEfor volume initialization.postgres:16needs exactly those four (measured on Docker 29.7.2, serving queries across a restart); withoutFOWNERit logschmod: changing permissions of '/var/lib/postgresql/data': Operation not permittedand runs correctly anyway, so do not addFOWNERfor that line alone.tini/ dumb-init wrappers running as PID 1 with signal forwarding — usually fine, but check.- Init-style processes that fork helpers (cron, sendmail) — typically need
SETUID+SETGID.
Common capabilities that specific workloads may need:
- NET_BIND_SERVICE — binding to privileged ports (< 1024), only under network_mode: host (Reading the failure)
- CHOWN / DAC_OVERRIDE / SETUID / SETGID, sometimes FOWNER — entrypoints that switch users (gosu, su-exec) or fix volume ownership at startup (postgres, redis)
- NET_RAW — raw/AF_PACKET sockets: packet capture, ARP/DHCP watching, and ping binaries that don't use ICMP datagram sockets (tool-dependent — busybox's needs it, others don't)
What it detects¶
Any service that does not include cap_drop: [ALL] in its configuration.
Dropping only specific capabilities (e.g., cap_drop: [NET_RAW]) is not sufficient — the rule requires ALL to ensure a least-privilege baseline.
Why it matters¶
Docker's default capability set (moby/daemon/pkg/oci/caps/defaults.go) grants 14 capabilities to every container: AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, NET_RAW, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT.
This set is fixed and unconfigurable: it is compiled into the daemon, dockerd exposes no capability flag, and there is no daemon.json key for it. So every Docker Engine container starts with these 14 unless its own configuration drops them. Verified on Docker 29.7.2: a default container's CapBnd reads 00000000a80425fb, which decodes to the 14 above, NET_RAW included. (The 11-capability default without NET_RAW belongs to Podman, which is out of scope — see ADR-020.)
Highlights of what the defaults grant:
- NET_RAW — open raw/
AF_PACKETsockets; enables ARP spoofing and packet injection on attached networks - NET_BIND_SERVICE — bind to privileged ports (< 1024); a container in its own network namespace needs it for none of them since Docker 20.10
- SETUID / SETGID — change process UID/GID; required for
gosu/su-execuser-switch entrypoints - CHOWN / DAC_OVERRIDE / FOWNER / FSETID — bypass file ownership and permission checks
- MKNOD — create device nodes via
mknod(2)(cannot create device nodes the device cgroup denies access to) - SETFCAP — set file capabilities on binaries inside the container
Most containerized applications need none of these. Retaining them expands the attack surface that a compromised container can leverage in chained exploits.
ATT&CK coverage¶
Remediating this finding contributes to mitigating the following MITRE ATT&CK techniques (pinned to ATT&CK v18). compose-lint is a static analyser, so this is mitigation coverage — it detects nothing at runtime.
| Technique | Tactic |
|---|---|
| T1040 Network Sniffing | Credential Access (Enterprise/Linux, not on the Containers matrix) |
| T1557 Adversary-in-the-Middle | Credential Access (Enterprise/Linux, not on the Containers matrix) |
| T1548.001 Abuse Elevation Control Mechanism: Setuid and Setgid | Privilege Escalation (Enterprise/Linux, not on the Containers matrix) |
See also¶
- CL-0011 — dangerous capabilities added back via
cap_add - CL-0002 —
privileged: true(functional superset of all capabilities) - Hardening guide, step 5 — where this rule fits when hardening a whole file
Severity derivation¶
Derivation (see severity model):
- Baseline: A — the attacker already has code execution in this container, as the workload uid
- Precondition: Technique — ARP cache poisoning against the
NET_RAWprimitive Docker grants by default. A published technique that needs no software defect in any victim; ARP is unauthenticated by design - Impact: Cross-container — L2 neighbours on the same Docker network only
- Qualifier/modifier: none — the payoff is conditional on a reachable neighbour, but that condition is priced by the override rather than by a qualifier, so it is not counted twice
- Derived: Technique × Cross-container = HIGH
- Shipped: MEDIUM — override
detection-precision— the derived impact needs a co-resident neighbour emitting interceptable traffic, and this rule asks only whethercap_drop: [ALL]is present, so it fires on single-service stacks and on stacks that encrypt inter-service traffic alike (98.6% of real compose files in the study, the large majority with no exploitable neighbour). Services and networks are both declared in the file, so the matcher can be sharpened — revisit the override when it is. ADR-020 Appendix A carries the full dossier - Scoping assumptions: Docker Engine defaults —
--icctrue, so neighbours are reachable; the capability set fixed at the default 14 withNET_RAWincluded (unconfigurable;dockerdhas no capability flag) - Evidence:
_cl0006plus the eleven symptom-table mapping checks. The cross-container reach is observed end to end: a default-caps container overwrote a neighbour's ARP entry for the gateway and held it across 5/5 polls, and the same attempt across two separate Docker networks got no response (ADR-020 Appendix A)
References: - OWASP Docker Security Rule #3 - CIS Docker Benchmark 5.4 — Ensure that Linux kernel capabilities are restricted within containers
A reference means the rule relates to that source. It does not mean a file with no finding complies with it. The CIS, OWASP and ATT&CK mapping for every rule, and the tags SARIF output carries for it, are on Standards mapping.