A custom seccomp profile is a JSON file that tells the kernel which syscalls a container is allowed to make, and what to do about the rest. Docker already applies a default profile that blocks roughly 40 of the most dangerous syscalls, but the default is written to keep almost every workload running — it is a floor, not a fit. This article shows how to go from that floor to a per-service allowlist: how to find the syscalls your app actually issues, how to write the profile, how to apply it in docker run and in Compose, and how to prove it is enforced instead of assuming it.
What you’ll accomplish
- Read
Seccomp: 2inside a running container and know exactly which profile produced it. - Produce a syscall inventory for one service using
strace -f -c, then confirm it with aSCMP_ACT_LOGpass under audit. - Write a profile with
defaultAction: SCMP_ACT_ERRNOand an explicitsyscallsallowlist that covers both x86_64 and aarch64. - Apply it per-container and in
docker-compose.ymlalongsidecap_dropandno-new-privileges. - Demonstrate a denied syscall returning
EPERMrather than trusting that the file was loaded.
Prerequisites
- Docker Engine 20.10 or newer.
defaultErrnoRetandSCMP_ACT_LOGboth need a reasonably current engine and libseccomp 2.4+. - A Linux kernel 4.14 or newer for
SCMP_ACT_LOG. Checkcat /proc/sys/kernel/seccomp/actions_avail— iflogis absent, the discovery pass in step 3 will not work and you are limited tostrace. - Root or
dockergroup access on the host, plusstraceinstalled either on the host or in a debug image. auditdandaudispd-pluginsif you want structured seccomp records. Without auditd, kernel seccomp messages land indmesgonly, which is usable but easy to lose.- Honest caveat: this is Linux-kernel machinery. On Docker Desktop the filter is applied inside the Linux VM, so the workflow works but host-side
dmesgandausearchdo not — run them inside the VM. Podman uses the same OCI profile format, so profiles port over, but the CLI flag is--security-opt seccomp=in both.
How it works
seccomp (secure computing mode) is a kernel facility that attaches a BPF program to a process. Every syscall that process or any of its children makes is evaluated by that program before the kernel runs the corresponding handler. The program sees the architecture, the syscall number, and the raw register values of the first six arguments — nothing else. It cannot dereference pointers, so it can filter on int and flag arguments but never on a path string.
The filter returns one of a fixed set of actions. The four that matter in practice are SCMP_ACT_ALLOW (proceed), SCMP_ACT_ERRNO (return -1 with an errno, EPERM by default), SCMP_ACT_LOG (proceed, but record it), and SCMP_ACT_KILL_PROCESS (terminate). Filters are one-way: once installed, a process cannot remove or loosen its own filter, only add a stricter one.
Docker’s default profile sets defaultAction to SCMP_ACT_ERRNO and then allows most of the syscall table. The denied set is the interesting part: keyctl, add_key and request_key (kernel keyring, historically a container-escape vector), the module family init_module, finit_module and delete_module, bpf, perf_event_open, kexec_load, reboot, swapon, swapoff, clock_settime, settimeofday, acct, quotactl, open_by_handle_at, setns, pivot_root, mount and umount2. Several entries are conditional: mount becomes available if the container carries CAP_SYS_ADMIN, and clone is allowed only when the namespace flags in argument 0 are clear, expressed as an argument filter with SCMP_CMP_MASKED_EQ.
That default is the reason --security-opt seccomp=unconfined is such a bad reflex. It does not relax one syscall; it removes the filter for the whole container, restoring keyctl, bpf, perf_event_open and the module loaders. A container that needed exactly one extra syscall now has the full table. The correct move is always a profile that starts from the default and adds the one call, or a purpose-built allowlist.
Two neighbouring controls do different jobs and are often confused with this one. Capabilities are checked inside the syscall handler, after seccomp has allowed the call through — dropping CAP_SYS_ADMIN makes mount() fail with EPERM, while a seccomp deny stops it before the handler runs at all. And no-new-privileges sets the PR_SET_NO_NEW_PRIVS bit, which prevents a setuid binary inside the container from regaining privileges that cap_drop removed. All three belong on the same service.
Step-by-step
1. Confirm the default is active before you change anything. If seccomp is off host-wide, everything below is theatre.
docker info --format '{{ .SecurityOptions }}'
[name=apparmor name=seccomp,profile=builtin/default name=cgroupns]
If you see name=seccomp,profile=unconfined the daemon has been started with seccomp disabled, and that is the first thing to fix.
2. Capture the syscalls your service actually issues. Run the container’s real command under strace with -f so child threads are followed, and -c so you get a summary rather than gigabytes of trace. Exercise the app properly — start it, hit its endpoints, trigger a reload, let it shut down. A trace of a 3-second idle boot will produce a profile that breaks the first time the app opens a second connection.
docker run --rm --cap-add SYS_PTRACE --security-opt seccomp=unconfined \
--entrypoint strace myapp:1.4 -f -c -o /tmp/app.strace /usr/local/bin/app
--security-opt seccomp=unconfined here is deliberate and temporary: it is the one case where you want it, because the default profile would hide denied calls from the trace. This container is for measurement only and never reaches production.
Extract just the names from the summary table:
awk '/^-+/ {section++; next} section==1 {print $NF}' /tmp/app.strace | sort -u
accept4
brk
clone3
close
epoll_pwait
execve
futex
...
3. Draft the profile. Set defaultAction to SCMP_ACT_ERRNO, declare the architectures, and list the allowed names. Save this as app-seccomp.json.
{
"defaultAction": "SCMP_ACT_ERRNO",
"defaultErrnoRet": 1,
"archMap": [
{
"architecture": "SCMP_ARCH_X86_64",
"subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"]
},
{
"architecture": "SCMP_ARCH_AARCH64",
"subArchitectures": ["SCMP_ARCH_ARM"]
}
],
"syscalls": [
{
"names": [
"accept4", "bind", "brk", "clock_gettime", "clone", "clone3",
"close", "connect", "epoll_create1", "epoll_ctl", "epoll_pwait",
"eventfd2", "execve", "exit", "exit_group", "fcntl", "fstat",
"futex", "getdents64", "getpid", "getrandom", "getsockname",
"getsockopt", "ioctl", "listen", "lseek", "madvise", "mmap",
"mprotect", "munmap", "nanosleep", "newfstatat", "openat",
"prctl", "pread64", "read", "readlinkat", "recvfrom",
"restart_syscall", "rseq", "rt_sigaction", "rt_sigprocmask",
"rt_sigreturn", "sched_getaffinity", "sched_yield", "sendto",
"set_robust_list", "set_tid_address", "setsockopt", "shutdown",
"sigaltstack", "socket", "tgkill", "uname", "write", "writev"
],
"action": "SCMP_ACT_ALLOW",
"comment": "Baseline for a single-process network service"
}
]
}
Treat that list as a starting shape, not an answer — your trace is the answer. Two schema details are worth knowing. defaultErrnoRet is the errno returned for denied calls; 1 is EPERM. Setting it to 38 (ENOSYS) is sometimes kinder, because glibc interprets ENOSYS as “this kernel is older than I thought” and falls back to an alternative call rather than aborting. And per-entry args lets you allow a syscall only for certain flag values, the way the default profile constrains clone:
{
"names": ["clone"],
"action": "SCMP_ACT_ALLOW",
"args": [
{ "index": 0, "value": 2114060288, "op": "SCMP_CMP_MASKED_EQ" }
]
}
That mask covers the namespace-creation flags, so clone is allowed for threads and forks but refused when it is asked to create a new namespace.
4. Find what the trace missed, using SCMP_ACT_LOG. strace only sees the code paths you exercised. Copy the profile to app-seccomp-log.json, change defaultAction to SCMP_ACT_LOG, and run the service normally. Every syscall outside the allowlist now runs and is recorded, so nothing breaks while you collect the gaps.
docker run -d --name app-audit --security-opt seccomp=./app-seccomp-log.json myapp:1.4
sudo ausearch -m SECCOMP -ts recent -i | grep -oP 'syscall=\K\d+' | sort -u
16
72
262
Those are syscall numbers, not names. Resolve them for the running architecture:
ausyscall x86_64 262
newfstatat
scmp_sys_resolver 262 from the libseccomp tools does the same job. Add each resolved name to the allowlist and repeat until a full working day produces no new records.
5. Apply it in Compose alongside the other two controls. A profile on its own is one layer; the value comes from stacking it.
services:
app:
image: myapp:1.4
read_only: true
security_opt:
- seccomp=./app-seccomp.json
- no-new-privileges:true
cap_drop:
- ALL
tmpfs:
- /tmp
docker compose up -d
docker compose ps
NAME IMAGE STATUS PORTS
app-app-1 myapp:1.4 Up 12 seconds 8080/tcp
The path in security_opt is resolved by the Docker CLI relative to the working directory, not by the daemon, so keep the JSON in the repository next to the Compose file and commit it. A profile that lives only on one operator’s laptop is not a control.
Validate it works
First, confirm a filter is loaded at all. Seccomp: 2 means filter mode; 0 means no filter and 1 means the legacy strict mode.
docker compose exec app grep Seccomp /proc/1/status
Seccomp: 2
Seccomp_filters: 1
Next, confirm the running container is using your file rather than the builtin:
docker inspect --format '{{ .HostConfig.SecurityOpt }}' app-app-1
[seccomp=./app-seccomp.json no-new-privileges:true]
Finally, prove the denial path. chmod is not in the allowlist above, so the underlying fchmodat call is refused by the filter:
docker run --rm --security-opt seccomp=./app-seccomp.json busybox chmod 777 /tmp
chmod: /tmp: Operation not permitted
Compare against the same command with the default profile, which permits fchmodat and succeeds silently. That difference is the whole point: the syscall never reaches the kernel handler, regardless of what capabilities or file ownership say.
If instead the container dies before printing anything, the profile is refusing a process-startup call rather than fchmodat — arch_prctl on x86_64 is the usual one, since the allowlist above was traced from a long-running service and not from busybox. Add the startup syscalls the SCMP_ACT_LOG pass reports, then repeat the test; you want the denial to land on the call you are demonstrating, not on execve’s aftermath.
Troubleshooting
The container exits immediately with no log output. The allowlist is missing something the runtime needs before your app’s first log line — usually execve, mmap, mprotect, set_tid_address, rseq, or arch_prctl on x86_64. Rerun with defaultAction set to SCMP_ACT_LOG and read ausearch -m SECCOMP -ts recent. If the process dies before any record appears, the profile JSON itself was rejected — see below.
“Operation not permitted” with no indication which syscall. The errno is all the application gets; the kernel knows more. Check that errno denials are being logged, then read the audit records:
cat /proc/sys/kernel/seccomp/actions_logged
sudo ausearch -m SECCOMP -ts recent -i | tail -5
kill_process kill_thread trap errno trace log
If errno is missing from that list, add it with sysctl -w kernel.seccomp.actions_logged='kill_process kill_thread trap errno trace log'. On a host with no auditd, the same records appear in dmesg as audit: type=1326 lines.
The daemon rejects the profile. Docker fails the container create rather than starting it unfiltered, which is the right behaviour but produces a terse message. Validate the JSON first, then check the field names — defaultAction, architectures / archMap, syscalls, names, action, args are the whole schema, and anything else is silently meaningless or fatal depending on version:
python3 -m json.tool app-seccomp.json > /dev/null && echo "JSON parses"
docker run --rm --security-opt seccomp=./app-seccomp.json busybox true
An unknown syscall name is also a common cause. Names are validated against the host’s libseccomp, so a call that is too new for the installed library fails the whole profile.
Everything is denied on arm64. If your profile lists only SCMP_ARCH_X86_64, the filter is still installed on an aarch64 host but no rule ever matches, so defaultAction applies to every call. Use archMap with both entries as shown above. Beyond the architecture list, the syscall names themselves differ: arm64 has no open, stat, fork, vfork, epoll_wait or select — the app uses openat, newfstatat, clone, epoll_pwait and pselect6 instead. A profile traced on x86_64 will not transfer unchanged. Trace once per architecture you ship to.
The app works in staging and fails under load. Concurrency pulls in syscalls that a light test never triggers: membarrier, sched_setaffinity, getcpu, futex_waitv on newer glibc, or io_uring_setup and io_uring_enter if the runtime opportunistically uses io_uring. Run the SCMP_ACT_LOG pass under realistic load before enforcing.
When this is the wrong approach
A hand-written allowlist is a maintenance commitment. Every runtime upgrade — a new glibc, a Go or JVM release that switches to io_uring or futex_waitv, a base-image bump — can introduce a syscall your profile does not know about, and the failure shows up as a confusing EPERM rather than an obvious error. If nobody owns re-running the discovery loop at upgrade time, the profile will eventually be disabled in a hurry during an incident, which is worse than never having written it.
For most services, the honest ordering is: run as a non-root user, drop all capabilities, mount the root filesystem read-only, set no-new-privileges, and keep Docker’s default seccomp profile. That combination removes far more attack surface per hour invested than a bespoke allowlist. Reach for a custom profile when you are running genuinely untrusted or third-party code, when a compliance regime asks for syscall-level restriction specifically, or when you have one high-value service whose syscall set is small and stable.
If the driver is multi-tenant isolation rather than defense in depth, seccomp is the wrong layer entirely — a virtualized runtime such as Kata Containers or gVisor gives you a real boundary instead of a filter list. And if you find yourself writing a profile because a container needs mount or setns, stop: that container wants privileges it should not have, and the fix is architectural.
Related reading: container image hardening for PaaS covers the non-root user and read-only filesystem side of the same problem, and writing and maintaining AppArmor profiles covers the path-based control that pairs with syscall filtering. The upstream references are the Docker seccomp security profiles page and the kernel’s seccomp(2) manual page.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.