CL-0027: cap_add: SYS_PTRACE, DAC_READ_SEARCH¶
Severity: MEDIUM (how it is derived)
The service adds SYS_PTRACE or DAC_READ_SEARCH, which let it trace other
processes or read files it does not own. Remove it unless the service is a
debugger, profiler or backup agent, and then scope it to what it inspects.
Fix¶
Remove the capability unless the workload demonstrably needs it:
# Before
services:
profiler:
image: myprofiler:1.0
cap_add:
- SYS_PTRACE
# After — if the sidecar genuinely profiles a neighbour, scope it explicitly
services:
profiler:
image: myprofiler:1.0
cap_drop:
- ALL
cap_add:
- SYS_PTRACE
pid: "service:app" # not pid: host — see CL-0010
- Remove it and see whether the tool still works. A tracer without the capability fails to attach (captured on Docker 29.7.2, not CI-asserted):
strace: attach: ptrace(PTRACE_SEIZE, 1): Operation not permitted
- If it is needed, know what it does and does not do. Measured with
strace, attaching from a sidecar to the app's PID 1 throughpid: "service:app", where the tracer and its target run as the same uid, on two hosts that differ inkernel.yama.ptrace_scope:
| Tracer | ptrace_scope = 1 |
ptrace_scope = 0 |
|---|---|---|
| root, Docker's default capabilities | refused | attaches |
root, cap_drop: [ALL] + cap_add: [SYS_PTRACE] |
attaches | attaches |
| uid 1000, tracing a uid 1000 process | refused | attaches |
uid 1000 with cap_add: [SYS_PTRACE] |
refused | attaches |
(1: Docker 29.7.2, Arch Linux. 0: Docker 29.1.3, Debian 13 with
AppArmor enforcing, whose docker-default profile allowed every row. The
1 column reproduced on a second distribution without AppArmor: it is the
ptrace_scope value that decides, not the distribution.)
So for a same-uid target, SYS_PTRACE matters only at ptrace_scope = 1,
and only for a tracer running as root: a capability added to a non-root
user: never reaches the process. What it grants on every host is tracing
a process of a different uid, which is the grant this rule is priced on
and is re-proven on every CI run. Check your host with
cat /proc/sys/kernel/yama/ptrace_scope.
-
Scope it to one service.
pid: "service:app"lets the sidecar see only that service's processes;pid: hostwould hand it every process on the machine (CL-0010). -
For
DAC_READ_SEARCH, give the reader the files' group instead. A backup or indexing agent that cannot read the workload's files can join the group that owns them, which needs no capability:
services:
backup:
image: mybackup:1.0
user: "2000:2000"
group_add:
- "1000" # the group that owns the workload's files
cap_drop:
- ALL
volumes:
- data:/data:ro
On a 0640 file owned by 1000:1000, uid 2000 got
cat: can't open '/data/file': Permission denied without the group and
read the file with it (busybox, re-proven on every CI run by scripts/validate_rule_premises.py).
- Check what the container holds, and the finding:
docker compose exec profiler grep CapBnd /proc/1/status
# CapBnd: 0000000000080000
capsh --decode=0000000000080000 # on the host, from libcap
# 0x0000000000080000=cap_sys_ptrace
compose-lint -q compose.yaml | grep CL-0027
A sidecar you keep is suppressed per service with a reason, and still
prints its line, marked SUPPRESSED.
Not tested: SELinux.
When to suppress¶
These are the capabilities with the most legitimate uses in the set, so suppression here is ordinary rather than exceptional:
SYS_PTRACE— debugger and APM sidecars. Scope them to the container they inspect withpid: "service:<name>"rather thanpid: host.DAC_READ_SEARCH— backup and indexing agents that must read files the workload uid does not own. Prefer fixing the ownership.
Suppress per service with a reason: naming the workload.
What it detects¶
cap_add entries whose grant is real but bounded:
| Capability | Grants | Why it is not higher |
|---|---|---|
SYS_PTRACE |
trace and read other processes' memory | confined to this container's own PID namespace unless pid: host is also set, which CL-0010 flags |
DAC_READ_SEARCH |
bypass file-read checks; read host files via open_by_handle_at |
the host-read leg needs a host bind mount to be present, and that mount is flagged by CL-0013 or CL-0025 |
Why it matters¶
These weaken isolation without opening an escape, and without leaving the container. That distinction is the whole point of the tier: before the split they were graded HIGH alongside kernel-module loading, which made the higher tiers less believable and put a debugger sidecar in the same bucket as a container escape.
Both members are also conditional on something the compose file cannot see. On
the overwhelmingly common single-process, single-uid container, neither grants
anything at all: same-uid tracing and same-uid reads need no capability, at the
upstream kernel default kernel.yama.ptrace_scope = 0 the derivation is
grounded on. At 1, attaching to a process that is not your own child needs
SYS_PTRACE even at the same uid (Fix, step 2). What
they add is reach over a neighbour the image happens to supply — which is why
the precondition is Second flaw rather than Direct.
If you are looking for PERFMON or SYS_TIME, they are CL-0028.
Their reach is host-wide and needs nothing from the image, so they do not belong
in this cell.
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 |
|---|---|
| T1055 Process Injection | Privilege Escalation |
| T1003 OS Credential Dumping | Credential Access |
| T1552.001 Unsecured Credentials: Credentials In Files | Credential Access |
| T1611 Escape to Host | Privilege Escalation |
See also¶
- CL-0024 — host-code-execution capabilities (CRITICAL)
- CL-0011 — strong host-adjacent capabilities (HIGH)
- CL-0028 — host-reaching capabilities (HIGH), which
PERFMONandSYS_TIMEmoved to - CL-0010 —
pid: host, which removesSYS_PTRACE's namespace confinement - 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: Second flaw — each member's grant converts into impact only where the image supplies something this file cannot see: a process running as a different uid for
SYS_PTRACEto trace, or a file the workload uid cannot already read forDAC_READ_SEARCH. Same-uid tracing and same-uid reads need no capability at all. Parallel to CL-0003, whose named primitive is likewise a property of the image - Impact: Single container — priced at
SYS_PTRACE, whose grant is read and write access to another process's memory inside this container.DAC_READ_SEARCH's host leg reaches further but only where a host bind mount is already present — a sibling the model scores in isolation and CL-0013/CL-0025 flag separately - Qualifier/modifier: none —
SYS_PTRACEwrites process memory, soread-onlydoes not apply. It would fitDAC_READ_SEARCHalone, which is not the pricing member - Derived: Second flaw × Single container = MEDIUM
- Shipped: MEDIUM
- Scoping assumptions:
DAC_READ_SEARCH'sopen_by_handle_athost read, andSYS_PTRACE's reach into host processes, are both excluded — each is conditional on a sibling key the model scores in isolation (a host bind mount, flagged by CL-0013/CL-0025; andpid: host, flagged by CL-0010). That is what the clause is for.PERFMONandSYS_TIMEwere once excluded here too, which was wrong — neither depends on a sibling key, so there was nothing to hold at a secure default. They are CL-0028's - Daemon assumptions: grounded at the upstream kernel default
kernel.yama.ptrace_scope = 0(ADR-020). Arch and Ubuntu ship 1, which narrowsSYS_PTRACE's same-uid reach. It does not move the cell: the rule is priced on the cross-uid grant, which noptrace_scopevalue affects - Evidence:
_cl0011inscripts/validate_rule_premises.pyproves only thatcap_adddeposits the capability into the effective set — not what any member grants. The pricing member is checked by_t_sys_ptrace: with--cap-drop ALL --cap-add SETUID,SETGID,PTRACE_ATTACHto a different-uid process in the same container is refused (Operation not permitted), and addingSYS_PTRACEattaches. The probe crosses a uid boundary deliberately — that test isptrace_may_access's capability check and does not depend onkernel.yama.ptrace_scope, whereas the same-uid case does and is not the grant (it succeeds with every capability dropped)._t_dac_read_searchcovers the second member: a mode-000, other-owned file is unreadable at--cap-drop ALLand readable withDAC_READ_SEARCH. Both run against a live daemon on every CI run
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.