Preventing Privilege Escalation (--security-opt=no-new-privileges)
Block setuid/setgid escalation paths with no-new-privileges.
In plain words
Enable no-new-privileges as a cheap invariant for non-root, non-suid application containers.
Think of it like…
No-new-privileges prevents a visitor badge from being upgraded at a door, but does not demote the all-access badge the visitor already carries.
Where you’ve seen it
In practice, docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true is the concrete move for this job: block setuid/setgid escalation paths with no-new-privileges. The release is not accepted until grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary confirms the result.
Words you’ll hear
- no-new-privileges
- The implementation control in
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 truefor block setuid/setgid escalation paths with no-new-privileges. - Escalation
- The result to observe with
grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary, rather than infer from a successful command alone. - security-opt
- The production boundary exposed when claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.
Visual diagram
Theory & deep dive
no-new-privileges control path
The concrete mechanism is docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true. The observable result is grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary; if those disagree, inspect the runtime evidence before changing unrelated settings.
Block setuid/setgid escalation paths with no-new-privileges. Keep no-new-privileges, Escalation and security-opt in the same deployment record so the intent and the observed state cannot drift apart.
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true
grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary, not with command success alone.security-opt failure boundary
An image that depends on ping file capabilities or a setuid helper will stop working, which is often a useful signal to remove the helper. A container starting UID 0 still has inherited root powers that NNP never removes. The narrow failure to design for is claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.
Accept this compromise explicitly: NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign. The controlled check-grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary-also identifies the point where a different design is safer.
Exercise this failure safely: claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: An image that depends on ping file capabilities or a setuid helper will stop working, which is often a useful signal to remove the helper. A container starting UID 0 still has inherited root powers that NNP never removes.
- Intent
- no-new-privileges
When to use it & trade-offs
What it is
--security-opt no-new-privileges sets NNP so an execve cannot gain additional privilege through setuid/setgid binaries or file capabilities. It blocks a specific escalation mechanism; it does not make a root process non-root or replace capability dropping.
Why it matters: An image that depends on ping file capabilities or a setuid helper will stop working, which is often a useful signal to remove the helper. A container starting UID 0 still has inherited root powers that NNP never removes.
When to reach for it
- The fit is strongest for this job: block setuid/setgid escalation paths with no-new-privileges. Pair it with
grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binaryin the runbook. - Production no-new-privileges changes should make Escalation observable through
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true, rather than trusting the runtime default. - Keep a rollback example for the case where claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.
When to avoid or be careful
- Do not accept command success while the system can still fail by claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.
- Avoid erasing security-opt protection merely to dodge this cost: “NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign”.
- Do not replace the evidence path-
grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary-with a screenshot or a mutable tag.
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true: practical choices
Strengths: --security-opt no-new-privileges sets NNP so an execve cannot gain additional privilege through setuid/setgid binaries or file capabilities. It blocks a specific escalation mechanism; it does not make a root process non-root or replace capability dropping.
Watch out: NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign.
Strengths: It can begin with docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true and fewer surrounding controls.
Watch out: It silently accepts claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency, which makes the result hard to reproduce after promotion.
Strengths: An image that depends on ping file capabilities or a setuid helper will stop working, which is often a useful signal to remove the helper. A container starting UID 0 still has inherited root powers that NNP never removes.
Watch out: The platform adds an ownership and debugging layer; retain grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true
- grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary
- Failure signature: claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency
- Trade-off: NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign.
Benchmarks & rules of thumb
- 1 NoNewPrivs bit
- set in the process status
- 2 restricted mechanisms
- setuid/setgid transitions and file capabilities
- 0 change
- to the starting UID or ambient capabilities
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 trueas proof and skippinggrep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary. - Claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency
- Optimizing no-new-privileges without accepting that nNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign.
Likely interviewer follow-ups
- Why does
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 trueaddress no-new-privileges here rather than through application code? - How would you distinguish healthy Escalation from the failure “claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency” using
grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary? - When would this trade-off-“NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign”-justify a different security-opt design?
docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true-and one proof-grep NoNewPrivs: /proc/1/status inside the container and attempt a controlled setuid binary. Then name the boundary: claiming no-new-privileges protects a container running as root with NET_ADMIN, or removing file capabilities without changing the app dependency.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Preventing Privilege Escalation (--security-opt=no-new-privileges) with generative AI interview Q&A and hands-on practice.