Sub topic 11
Syscall and Mandatory Access Control Profiles
This chapter assumes you know how Linux capabilities work and how to run containers with docker run options. It covers two more kernel filters that limit what a container process can do: seccomp and AppArmor.
Why capabilities are not enough
Dropping capabilities limits privileged operations. A container can still call hundreds of system calls (syscalls), which are the requests a process makes to the kernel. Each syscall is attack surface in the shared host kernel. Seccomp and AppArmor shrink that surface.
| Mechanism | What it filters | Typical rule |
|---|---|---|
| Seccomp | Syscalls and their arguments | Block `keyctl`, `mount`, `ptrace` |
| AppArmor | File paths, network access, capabilities | Deny writes to `/proc/sys` |
Seccomp
Seccomp (secure computing mode) lets the kernel check each syscall against a list of rules. Each rule has an action, such as allow, return an error, or kill the process.
Docker applies a default seccomp profile to every container. It allows roughly 300 syscalls and blocks dangerous ones such as reboot, kexec_load, and init_module. You get this protection without doing anything, unless you turn it off.
A custom profile
A profile is a JSON file. This one allows everything except a few syscalls, which fail with a permission error:
{
"defaultAction": "SCMP_ACT_ALLOW",
"syscalls": [
{
"names": ["ptrace", "keyctl", "mount", "umount2"],
"action": "SCMP_ACT_ERRNO"
}
]
}Apply it with --security-opt:
docker run -d --name web \
--security-opt seccomp=./profile.json \
myapp:1.0An allow-by-default profile is easy to write but weak. A stronger approach starts from "defaultAction": "SCMP_ACT_ERRNO" and lists only the syscalls your application needs. Tools such as strace, or running the app in a test environment with logging, help you find that list.
Common errors
- Running with
--security-opt seccomp=unconfined. This removes the default filter. Use it only briefly to test whether seccomp causes a failure, then fix the profile. - Using
--privileged. This also disables seccomp, along with other protections. - Writing an allow-list that is too tight. The app fails with
Operation not permittedorFunction not implemented, often only on a rarely used code path.
AppArmor
AppArmor is a Linux Security Module (LSM) that implements mandatory access control (MAC). Mandatory means the policy is enforced by the kernel, and a process cannot opt out, even when it runs as root inside the container.
On hosts that use AppArmor, such as Ubuntu and Debian, Docker loads a profile named docker-default and applies it to containers. Red Hat-family hosts usually use SELinux instead, which serves the same purpose with different syntax.
Check the profile attached to a running container:
docker inspect --format '{{.AppArmorProfile}}' webTo use your own profile, load it into the kernel and then name it:
sudo apparmor_parser -r -W ./docker-myapp
docker run -d --name web \
--security-opt apparmor=docker-myapp \
myapp:1.0How the layers fit together
These layers are independent. A gap in one is limited by the others. This is defense in depth.
Practical guidance
- Keep the default seccomp and AppArmor profiles unless you have a measured reason to change them.
- Add a custom profile for high-risk or internet-facing services.
- Combine profiles with dropped capabilities and
no-new-privileges. - Test profiles in staging, because failures show up only when the blocked code path runs.
Exercise
A teammate fixes a "permission denied" error in a container by adding --security-opt seccomp=unconfined and leaves it in production. What is wrong with this, and what should they do instead?
Show answer
It removes Docker's default syscall filter, so the container can call syscalls that the default profile blocks, which widens kernel attack surface. They should find which syscall is blocked (for example with strace or the kernel audit log), then use a custom profile that allows only that syscall in addition to the defaults, and remove unconfined.