Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 106/ 160
06. Docker Security & Hardening

Preventing Privilege Escalation (--security-opt=no-new-privileges)

Block setuid/setgid escalation paths with no-new-privileges.

Intermediateno-new-privileges · Escalation3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 true for 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

Loading interactive 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.

Concrete no-new-privileges setup

docker run --security-opt=no-new-privileges --cap-drop=ALL --user 10001:10001 alpine:3.21 true

Key takeaway: Prove Escalation with 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.

Deliberate failure test

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.

Key takeaway: NNP has almost no runtime cost, but legacy helpers or distro tools may rely on privilege transitions and need redesign.

How it works, step by step

Step 1 of 4
Design

1. 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.

Enable no-new-privileges as a cheap invariant for non-root, non-suid application containers.
Key numbers at this step
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 binary in 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

Explicit no-new-privileges
Best for: Block setuid/setgid escalation paths with no-new-privileges, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Escalation experiments with low blast radius.

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.

Managed security-opt
Best for: Teams that centralize security-opt policy across many workloads.

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 true as proof and skipping grep 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 true address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Linux Capabilities (--cap-drop=ALL, --cap-add)
Next topic
Read-Only Root Filesystems (--read-only)