Sub topic 11
Verifying the restrictions from inside the container
This chapter assumes you can run docker run and kubectl exec, and that you know the earlier controls: dropped capabilities, no-new-privileges, seccomp, a read-only root filesystem, and a non-root user. Setting a flag does not prove it took effect. A typo, an overriding setting, or an unsupported kernel feature can leave a container less restricted than you intended. The reliable check is to ask the kernel from inside the running container.
Where the kernel reports its state
Every process can read /proc/self/status. It shows the capability sets, the seccomp mode, and the no-new-privileges flag. The table lists the fields to check.
| Field | Meaning | Hardened value |
|---|---|---|
| `CapEff` | Capabilities the process can use now | `0000000000000000` |
| `CapBnd` | Upper limit on any capability the process or its children can gain | `0000000000000000` if you dropped all |
| `NoNewPrivs` | 1 if privilege gain through setuid binaries is blocked | `1` |
| `Seccomp` | 0 = off, 1 = strict, 2 = filter | `2` |
Start with the capability masks:
docker run --rm --cap-drop ALL alpine grep Cap /proc/self/statusCapEff and CapBnd should be all zeros. Run the same command without --cap-drop ALL and you will see a non-zero mask. The exact value depends on your Docker version. To decode a mask into names, run capsh --decode=<mask> on a host that has libcap installed.
One check for the whole Docker setup
This command applies the combined settings from the earlier chapters and prints the evidence. It uses the plain alpine image, so it also works without Python.
docker run --rm \
--read-only \
--tmpfs /tmp:rw,noexec,nosuid,size=64m \
--cap-drop ALL \
--security-opt no-new-privileges:true \
--user 10001:10001 \
alpine sh -c '
id
grep -E "^(CapEff|CapBnd|NoNewPrivs|Seccomp):" /proc/self/status
mount | grep -E " on (/|/tmp) "
touch /tmp/ok && echo "tmp is writable"
touch /etc/blocked || echo "root filesystem is not writable"
'Expect these results:
idshowsuid=10001.CapEffandCapBndare zero.NoNewPrivsis1.Seccompis2, meaning the default profile is active.- The mount line for
/containsro. - The
/tmpmount is atmpfswithnoexecandnosuid. - Only
/tmpaccepts writes.
If Seccomp is 0, the profile is off. This happens with --security-opt seccomp=unconfined or when the daemon runs without seccomp support.
Test that actions fail, not only that flags are set
A flag value shows configuration. A failed action shows enforcement. Try operations that the restriction should block.
docker run --rm --cap-drop ALL alpine sh -c 'touch /tmp/f && chown 1000 /tmp/f'The container runs as root, but chown fails with Operation not permitted. Without CAP_CHOWN, even root cannot change file ownership. For a custom seccomp profile, run the deny-mkdir.json example and confirm that mkdir fails:
docker run --rm \
--security-opt seccomp=./deny-mkdir.json \
alpine mkdir /tmp/testVerifying in Kubernetes
Run the same reads against the hardened-app pod from the previous chapter:
kubectl exec hardened-app -- grep -E '^(CapEff|NoNewPrivs|Seccomp):' /proc/self/status
kubectl exec hardened-app -- id
kubectl exec hardened-app -- touch /etc/blocked
kubectl exec hardened-app -- touch /tmp/okThe first command should show CapEff as zero, NoNewPrivs as 1, and Seccomp as 2. allowPrivilegeEscalation: false sets NoNewPrivs, and RuntimeDefault sets the seccomp mode. The touch /etc/blocked command should fail with Read-only file system, and touch /tmp/ok should succeed because of the emptyDir mount. If the image has no shell or grep, attach an ephemeral container with kubectl debug and read the target process's status from there.
Exercise
A container started with --cap-drop ALL and the default seccomp profile shows "Seccomp: 0" in /proc/self/status. What does this mean, and which capability-related check still tells you something useful?
Show answer
Seccomp 0 means no seccomp filter is active, so something disabled the profile, for example seccomp=unconfined or a daemon without seccomp support. The capability check is separate. CapEff and CapBnd can still be all zeros, which shows the capability drop worked. Each control must be verified on its own.