Linux Capabilities (--cap-drop=ALL, --cap-add)
Drop all capabilities and add back only what the workload truly needs.
In plain words
Express exact capabilities rather than --privileged, and verify them with a small denial test.
Think of it like…
Instead of granting the master key, hand over just the key for the supply cabinet and the loading-dock intercom.
Where you’ve seen it
In practice, docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 is the concrete move for this job: drop all capabilities and add back only what the workload truly needs. The release is not accepted until capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount confirms the result.
Words you’ll hear
- cap-drop
- The implementation control in
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1for drop all capabilities and add back only what the workload truly needs. - cap-add
- The result to observe with
capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount, rather than infer from a successful command alone. - Capabilities
- The production boundary exposed when using --privileged to bind a low port when one capability and an unprivileged port would suffice.
Visual diagram
Theory & deep dive
cap-drop control path
The concrete mechanism is docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1. The observable result is capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount; if those disagree, inspect the runtime evidence before changing unrelated settings.
Drop all capabilities and add back only what the workload truly needs. Keep cap-drop, cap-add and Capabilities in the same deployment record so the intent and the observed state cannot drift apart.
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1
capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount, not with command success alone.Capabilities failure boundary
Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets. The narrow failure to design for is using --privileged to bind a low port when one capability and an unprivileged port would suffice.
Accept this compromise explicitly: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance. The controlled check-capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount-also identifies the point where a different design is safer.
Exercise this failure safely: using --privileged to bind a low port when one capability and an unprivileged port would suffice.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.
- Intent
- cap-drop
When to use it & trade-offs
What it is
Linux capabilities split selected root powers into units such as NET_BIND_SERVICE, CHOWN and SYS_ADMIN. Docker starts with a default capability set; --cap-drop=ALL removes them and --cap-add restores the minimum required privilege.
Why it matters: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.
When to reach for it
- The fit is strongest for this job: drop all capabilities and add back only what the workload truly needs. Pair it with
capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mountin the runbook. - Production cap-drop changes should make cap-add observable through
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1, rather than trusting the runtime default. - Keep a rollback example for the case where using --privileged to bind a low port when one capability and an unprivileged port would suffice.
When to avoid or be careful
- Do not accept command success while the system can still fail by using --privileged to bind a low port when one capability and an unprivileged port would suffice.
- Avoid erasing Capabilities protection merely to dodge this cost: “A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance”.
- Do not replace the evidence path-
capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount-with a screenshot or a mutable tag.
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1: practical choices
Strengths: Linux capabilities split selected root powers into units such as NET_BIND_SERVICE, CHOWN and SYS_ADMIN. Docker starts with a default capability set; --cap-drop=ALL removes them and --cap-add restores the minimum required privilege.
Watch out: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.
Strengths: It can begin with docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1 and fewer surrounding controls.
Watch out: It silently accepts using --privileged to bind a low port when one capability and an unprivileged port would suffice, which makes the result hard to reproduce after promotion.
Strengths: Many teams add NET_ADMIN to solve a problem actually caused by missing route configuration, and SYS_ADMIN approximates broad host-administration power. Capabilities do not cover every isolation dimension such as seccomp, namespaces or mounted secrets.
Watch out: The platform adds an ownership and debugging layer; retain capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1
- capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount
- Failure signature: using --privileged to bind a low port when one capability and an unprivileged port would suffice
- Trade-off: A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.
Benchmarks & rules of thumb
- 0 capabilities
- initial state after cap-drop=ALL
- NET_BIND_SERVICE
- example single restored capability
- CAP_SYS_ADMIN
- a very broad capability that is often a warning sign
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1as proof and skippingcapsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount. - Using --privileged to bind a low port when one capability and an unprivileged port would suffice
- Optimizing cap-drop without accepting that a capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance.
Likely interviewer follow-ups
- Why does
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1address cap-drop here rather than through application code? - How would you distinguish healthy cap-add from the failure “using --privileged to bind a low port when one capability and an unprivileged port would suffice” using
capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount? - When would this trade-off-“A capability allowlist provides precise least privilege; it requires testing every runtime feature and can be hard to debug without policy provenance”-justify a different Capabilities design?
docker run --read-only --cap-drop=ALL --cap-add=NET_BIND_SERVICE -u 10001:10001 ghcr.io/acme/proxy:2.1-and one proof-capsh --print inside an equivalent debug image and attempt a low-port bind plus a denied mount. Then name the boundary: using --privileged to bind a low port when one capability and an unprivileged port would suffice.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Linux Capabilities (--cap-drop=ALL, --cap-add) with generative AI interview Q&A and hands-on practice.