SkillSprout
Chapter 2 · Lesson 3
Advanced
2 min read

Linux Capabilities and Runtime Policies

Overview

A container process has a Linux user and a set of privileges called capabilities. Docker grants a conservative set by default, but applications should drop every unnecessary capability. Seccomp and MAC policies restrict which system calls and host operations an application can use.

Detailed Notes

Linux capabilities

Historically, an application ran as root or as a non-root user, so root had every privilege. Linux divides many privileges into capabilities. Docker's default set is narrower than host root but still includes capabilities such as changing network settings in some configurations.

Drop all capabilities and add only the required one:

bash
docker run --cap-drop ALL --cap-add NET_BIND_SERVICE nginx

NET_BIND_SERVICE permits binding low ports such as 80. Avoid it when a container listens on 8080 and an external load balancer can handle privileged port access.

Reduce process and filesystem privileges

bash
docker run -d   --read-only   --tmpfs /tmp:rw,noexec,nosuid   --security-opt no-new-privileges   --pids-limit 256   --memory 512m   my-app:1.0
  • --read-only prevents writes to the container root filesystem.
  • --tmpfs provides temporary writable memory for specific paths.
  • no-new-privileges prevents set-user-ID binaries or exec calls from gaining extra rights.
  • --pids-limit prevents process forks from exhausting host resources.

Docker socket

Never bind /var/run/docker.sock into an untrusted application unless it is intentionally a Docker-management service:

text
/var/run/docker.sock

Access to that socket can let a process control Docker. It is often a host-privilege escalation path.

Seccomp and AppArmor

Docker applies a default seccomp profile that blocks many dangerous system calls. Some platforms provide AppArmor or SELinux profiles that restrict files and operations. Keep profiles and exceptions narrow. Do not disable security profiles merely to make a first container start.

Common Interview Questions

Finished this lesson?

0 of 27 lessons done · 0% of the course