Docker 54 🐳 Restricting System Calls: Custom Seccomp Profiles in Docker Engine
A container shares the host kernel. Every action the containerized process takes, from opening a file to sending a network packet, is a system call into that kernel. The kernel’s syscall interface is the largest attack surface in the container model: roughly 300 calls, each a potential entry point for a kernel vulnerability. Seccomp (secure computing mode) is the Linux feature that filters those calls. Docker enables a default seccomp profile for every container, and it blocks about 44 of the most dangerous syscalls. For applications with a narrow, well-understood set of syscalls, a custom profile tightens that list further. The trade is precision against maintenance: a tighter profile provides stronger isolation but breaks the moment the application needs a syscall the profile does not allow.
Key point: The default seccomp profile is an allowlist, not a blocklist. It denies all syscalls by default and permits only those on the list. A custom profile that does not preserve this structure by deriving from the default risks being weaker than the default, not stronger, because it may allow dangerous calls the default blocked.
Why seccomp matters
The kernel attack surface problem. A containerized process and a host process make the same syscalls into the same kernel. A kernel vulnerability reachable through a syscall is reachable from inside the container. The fewer syscalls the process can make, the fewer kernel bugs it can reach. Seccomp is the mechanism that limits which calls are available.
The default profile problem. Docker’s default profile is designed for compatibility, not maximum security. It blocks the most dangerous calls: module loading, kernel reboots, namespace cloning, kernel keyring access, and the io_uring family that has produced container escapes. It allows the rest, including calls that a specific application does not need .
The least-privilege problem. An application that only reads files and writes logs does not need ptrace, bpf, or mount. A profile that allows them provides no protection against an attacker who compromises the process and tries to use them. The principle of least privilege applies to syscalls the same way it applies to capabilities.
The escape problem. Container escapes frequently begin with a syscall that should not have been available. open_by_handle_at was the cause of an old container breakout . The io_uring family has produced multiple vulnerabilities . Blocking these calls at the seccomp layer prevents the exploit from reaching the kernel code that contains the bug.
The audit problem. A custom profile is developed by observing what the application actually calls. strace records the syscalls, and the recorded list becomes the profile’s allowlist. The audit log of a permissive profile tells the developer exactly what the application needs.
The maintenance problem. A profile is a contract. When the application is updated and begins using a new syscall, a profile that does not allow it breaks the application. The tighter the profile, the more often it needs review. The decision is whether the isolation gain justifies the maintenance cost for the specific application.
a. The default seccomp profile
Docker applies a default seccomp profile to every container unless the operator overrides it. The profile is a JSON document that defines a default action and a list of syscalls with per-call actions.
The allowlist structure
The profile’s structure is a defaultAction set to SCMP_ACT_ERRNO, which denies every syscall by default, followed by a syscalls array that overrides the action for specific calls .
{
"defaultAction": "SCMP_ACT_ERRNO",
"syscalls": [
{
"names": ["read", "write", "open", "close"],
"action": "SCMP_ACT_ALLOW"
}
]
}
The SCMP_ACT_ERRNO action returns a Permission denied error to the process. The SCMP_ACT_ALLOW action permits the call. The profile is therefore a whitelist: everything is denied unless explicitly allowed.
What the default blocks
The default profile blocks roughly 44 syscalls. The list includes the most dangerous operations across several categories .
| Syscall | Why It Is Blocked |
|---|---|
bpf | Loading eBPF programs can persist in the kernel |
clone | Cloning new namespaces, except user namespaces |
init_module | Loading kernel modules |
kexec_load | Loading a new kernel for later execution |
keyctl | Kernel keyring, which is not namespaced |
mount | Mounting filesystems |
open_by_handle_at | Cause of an old container breakout |
perf_event_open | Tracing/profiling, leaks host information |
ptrace | Process inspection, leaks host information |
reboot | Rebooting the host |
io_uring_setup | Security vulnerabilities enabling container escape |
The list is curated. Each entry has a documented reason, and the profile’s source file carries comments explaining why the call is blocked rather than allowed .
Checking the default
The default profile is active unless the daemon was started with seccomp disabled. The docker info command reports the security options.
docker info --format '{{.SecurityOptions}}'
# [name=seccomp,profile=builtin/default ...]
If the output shows seccomp,profile=unconfined, the daemon has seccomp disabled, and the default profile is not being applied .
Overriding the default
The default is replaced, not extended, by a custom profile. The --security-opt seccomp= flag takes the path to a JSON profile.
docker run --security-opt seccomp=/path/to/profile.json myapp
The path is resolved by the Docker CLI on the client host, not the daemon. On a remote daemon, the profile file must exist on the client that invokes the command .
b. Writing a custom profile
A custom profile is derived from the default and narrowed to the application’s actual syscalls. The process is empirical: observe the application, then write the profile.
Tracing the application
strace records the syscalls a process makes. Running the container with strace as the entrypoint and seccomp unconfined produces a summary of the calls the application uses.
docker run --rm --security-opt seccomp=unconfined \
--entrypoint strace myapp:latest -f -c /app/entrypoint.sh
The -f flag follows child processes, and -c produces a summary table rather than a raw trace. The container runs with seccomp=unconfined for the measurement only, because the default profile would hide denied calls from the trace . The trace must exercise the full application, not just startup, or the profile will break on the first request that triggers a new code path .
Extracting the syscall names
The summary table lists each syscall and its call count. The names are extracted and sorted.
awk '/^-+/ {section++; next} section==1 {print $NF}' /tmp/app.strace | sort -u
The output is a list of syscalls the application actually uses, such as accept4, bind, brk, close, epoll_pwait, futex, and read .
Drafting the profile
The profile sets defaultAction to SCMP_ACT_ERRNO and lists the observed syscalls as SCMP_ACT_ALLOW. The archMap declares the architectures the profile applies to.
{
"defaultAction": "SCMP_ACT_ERRNO",
"archMap": [
{
"architecture": "SCMP_ARCH_X86_64",
"subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"]
}
],
"syscalls": [
{
"names": ["accept4", "bind", "brk", "close", "epoll_pwait", "read", "write"],
"action": "SCMP_ACT_ALLOW"
}
]
}
The defaultErrnoRet field sets the error code returned to the process. The default is EPERM (1). Setting it to ENOSYS (38) is sometimes preferable, because glibc interprets ENOSYS as “this kernel does not support this call” and falls back to an alternative rather than aborting .
The baseline derivation rule
The safest way to write a custom profile is to derive it from the default. Starting from SCMP_ACT_ALLOW and blocking specific calls produces a blocklist, which allows every dangerous call the default blocked. The result is weaker than the default, not stronger .
// WRONG: blocklist structure
{
"defaultAction": "SCMP_ACT_ALLOW",
"syscalls": [
{ "names": ["chmod"], "action": "SCMP_ACT_ERRNO" }
]
}
The correct structure is the allowlist, derived from the default profile and narrowed by removing entries or adding explicit denials with higher priority.
c. Applying and testing the profile
A custom profile is applied with the --security-opt seccomp= flag. It is tested by running the application under the profile and observing what breaks.
The application command
docker run --rm \
--security-opt seccomp=/path/to/app-seccomp.json \
myapp:latest
The container runs with the custom profile. Every syscall the application makes is checked against the profile’s rules .
The denial signal
When the profile blocks a syscall the application needs, the process receives the configured error code. The application typically logs a permission error or crashes. The error identifies the missing syscall, and the profile is updated to allow it .
The audit mode
A profile can be set to SCMP_ACT_LOG instead of SCMP_ACT_ERRNO for development. The log action records the syscall without blocking it, which allows the application to run while the audit log captures the calls the profile would have denied .
# Check the kernel audit log for logged syscalls
sudo ausearch -m seccomp -ts recent
The logged calls become the profile’s allowlist.
The capability interaction
Seccomp and capabilities are independent layers. A syscall may be blocked by seccomp even if the process has the capability that would otherwise permit it. Conversely, a syscall may be allowed by seccomp but fail because the process lacks the required capability. The two layers must be considered together .
The container platform
Docker applies the profile per container. Kubernetes exposes the same control through the pod’s security context. The RuntimeDefault seccomp type uses the container runtime’s default profile, which is Docker’s default when the runtime is Docker .
securityContext:
seccompProfile:
type: RuntimeDefault
A custom profile on Kubernetes uses type: Localhost and a localhostProfile path relative to the kubelet’s seccomp root .
Complete Example Session
# ============================================
# PART 1: CONFIRM THE DEFAULT IS ACTIVE
# ============================================
docker info --format '{{.SecurityOptions}}'
# [name=seccomp,profile=builtin/default ...]
# If unconfined, seccomp is disabled on the daemon.
# ============================================
# PART 2: RUN WITH THE DEFAULT
# ============================================
docker run --rm alpine sh -c 'ls /'
# The default profile is applied automatically.
# ============================================
# PART 3: TRACE THE APPLICATION
# ============================================
docker run --rm \
--security-opt seccomp=unconfined \
--entrypoint strace \
myapp:latest -f -c /app/entrypoint.sh
# The trace records every syscall the application makes.
# ============================================
# PART 4: EXTRACT THE SYSCALL NAMES
# ============================================
awk '/^-+/ {section++; next} section==1 {print $NF}' /tmp/app.strace | sort -u
# accept4
# bind
# brk
# close
# epoll_pwait
# futex
# read
# write
# ============================================
# PART 5: DRAFT THE PROFILE
# ============================================
cat > app-seccomp.json <<'EOF'
{
"defaultAction": "SCMP_ACT_ERRNO",
"defaultErrnoRet": 38,
"archMap": [
{
"architecture": "SCMP_ARCH_X86_64",
"subArchitectures": ["SCMP_ARCH_X86", "SCMP_ARCH_X32"]
}
],
"syscalls": [
{
"names": ["accept4", "bind", "brk", "close", "epoll_pwait",
"futex", "read", "write"],
"action": "SCMP_ACT_ALLOW"
}
]
}
EOF
# ============================================
# PART 6: APPLY THE PROFILE
# ============================================
docker run --rm \
--security-opt seccomp=./app-seccomp.json \
myapp:latest
# The application runs under the custom profile.
# ============================================
# PART 7: THE BLOCKED SYSCALL
# ============================================
# If the application needs a syscall not in the profile:
# The process receives ENOSYS.
# The application logs an error.
# The profile is updated to add the syscall.
# ============================================
# PART 8: AUDIT MODE
# ============================================
# Change the action to SCMP_ACT_LOG to record without blocking.
cat > app-seccomp-audit.json <<'EOF'
{
"defaultAction": "SCMP_ACT_LOG",
"archMap": [ ... ],
"syscalls": []
}
EOF
docker run --rm \
--security-opt seccomp=./app-seccomp-audit.json \
myapp:latest
# Check the audit log:
sudo ausearch -m seccomp -ts recent
# ============================================
# PART 9: THE DEFAULT PROFILE AS BASELINE
# ============================================
# Download the default profile for reference.
curl -fsSL -o default.json \
https://raw.githubusercontent.com/moby/profiles/main/seccomp/default.json
# Narrow it by removing entries the application does not need.
# ============================================
# PART 10: THE HARDENED BASELINE
# ============================================
docker run --rm \
--cap-drop=ALL \
--cap-add=NET_BIND_SERVICE \
--security-opt=no-new-privileges \
--security-opt seccomp=./app-seccomp.json \
--read-only \
--tmpfs /tmp \
--user 1000:1000 \
myapp:latest
# Capabilities dropped.
# Syscalls restricted.
# Privilege escalation blocked.
# Filesystem read-only.
The ten parts progressed from confirming the default through tracing the application, extracting syscall names, drafting and applying the profile, handling blocked calls, audit mode, deriving from the default, and the hardened baseline. The same myapp example ran through every part, showing how a custom profile is developed and applied.
Quick Reference
Seccomp Actions
| Action | Effect |
|---|---|
SCMP_ACT_ALLOW | Permit the syscall |
SCMP_ACT_ERRNO | Return an error to the process |
SCMP_ACT_LOG | Record the syscall without blocking |
SCMP_ACT_KILL | Terminate the process |
Profile Structure
| Field | Purpose |
|---|---|
defaultAction | Action for unlisted syscalls |
defaultErrnoRet | Error code returned by SCMP_ACT_ERRNO |
archMap | Architectures the profile applies to |
syscalls | List of syscalls with per-call actions |
Default Profile Blocks
| Category | Examples |
|---|---|
| Kernel modules | init_module, delete_module |
| Namespaces | clone, unshare |
| Mounting | mount, pivot_root |
| Tracing | ptrace, perf_event_open |
| Keyring | keyctl, add_key |
| Reboot | reboot, kexec_load |
| Async I/O | io_uring_setup, io_uring_enter |
Development Workflow
| Step | Command |
|---|---|
| Trace | strace -f -c with seccomp=unconfined |
| Extract | awk over the summary table |
| Draft | defaultAction: SCMP_ACT_ERRNO |
| Test | Run with --security-opt seccomp=profile.json |
| Audit | SCMP_ACT_LOG and ausearch |
| Enforce | SCMP_ACT_ERRNO |
Best Practices
✅ Do This:
# Confirm seccomp is active before writing a profile.
docker info --format '{{.SecurityOptions}}' # ✅
# Trace the application with seccomp unconfined.
docker run --security-opt seccomp=unconfined --entrypoint strace ... # ✅
# Derive from the default profile.
curl -o default.json https://.../seccomp/default.json # ✅
# Use ENOSYS as the error code for compatibility.
"defaultErrnoRet": 38 # ✅
# Exercise the full application during tracing.
# Startup alone is not enough. # ✅
# Use SCMP_ACT_LOG for development.
"defaultAction": "SCMP_ACT_LOG" # ✅
# Combine seccomp with capabilities and AppArmor/SELinux.
--cap-drop=ALL --security-opt seccomp=profile.json # ✅
❌ Don’t Do This:
# Don't start from a blocklist structure.
"defaultAction": "SCMP_ACT_ALLOW" # ❌ Weaker than default
# Don't disable seccomp to make an application work.
--security-opt seccomp=unconfined # ❌ Removes the layer
# Don't assume the default profile is sufficient.
# It is a baseline, not a custom fit. # ❌
# Don't skip the audit log when a syscall is blocked.
# The error identifies the missing call. # ❌
# Don't trace only startup.
# The profile will break on the first new code path. # ❌
# Don't forget the architecture map.
# The profile may not apply on non-x86 systems. # ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| Application breaks | Missing syscall in profile | Trace, add the syscall |
| Profile weaker than default | Blocklist structure | Derive from default allowlist |
| Seccomp not active | Daemon started with seccomp=unconfined | Restart with seccomp enabled |
| Wrong error code | Default EPERM aborts the application | Use ENOSYS for fallback |
| Profile does not apply | Architecture mismatch | Check archMap |
| Remote path not found | Profile resolved on client | Copy profile to client host |
| Kubernetes profile ignored | Wrong path or type | Use Localhost with correct path |
Real-World Examples
1. Confirm Default
docker info --format '{{.SecurityOptions}}'
2. Trace Syscalls
docker run --rm --security-opt seccomp=unconfined --entrypoint strace myapp -f -c /app/run
3. Extract Names
awk '/^-+/ {section++; next} section==1 {print $NF}' trace | sort -u
4. Draft Profile
{"defaultAction": "SCMP_ACT_ERRNO", "syscalls": [{"names": ["read"], "action": "SCMP_ACT_ALLOW"}]}
5. Apply Profile
docker run --security-opt seccomp=./profile.json myapp
6. Audit Mode
{"defaultAction": "SCMP_ACT_LOG"}
7. Check Audit
sudo ausearch -m seccomp -ts recent
8. Derive from Default
curl -o default.json https://raw.githubusercontent.com/moby/profiles/main/seccomp/default.json
9. Kubernetes RuntimeDefault
securityContext:
seccompProfile:
type: RuntimeDefault
10. Combined Hardening
docker run --cap-drop=ALL --security-opt seccomp=profile.json myapp
Visual
The Syscall Path
┌────────────────────────────────────────────────────────────┐
│ SYSCALL PATH FROM APPLICATION TO KERNEL │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ APPLICATION │ │
│ │ read(), write(), open() │ │
│ └────────────────────────┬─────────────────────────┘ │
│ │ │
│ v │
│ ┌──────────────────────────────────────────────────┐ │
│ │ SECCOMP FILTER │ │
│ │ Is the syscall on the allowlist? │ │
│ └────────────────────────┬─────────────────────────┘ │
│ │ │
│ ┌────────────┴────────────┐ │
│ │ │ │
│ v v │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ ALLOW │ │ DENY │ │
│ │ Call reaches │ │ Return error │ │
│ │ the kernel │ │ or kill process │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ The filter is applied before the kernel sees the call. │
│ A blocked syscall never reaches the kernel. │
│ │
└────────────────────────────────────────────────────────────┘
Profile Structure
┌────────────────────────────────────────────────────────────┐
│ SECCOMP PROFILE STRUCTURE │
│ │
│ { │
│ "defaultAction": "SCMP_ACT_ERRNO", ← deny by default│
│ "defaultErrnoRet": 38, ← ENOSYS │
│ "archMap": [ ← architectures │
│ { "architecture": "SCMP_ARCH_X86_64", ... } │
│ ], │
│ "syscalls": [ ← allowlist │
│ { │
│ "names": ["read", "write", "open"], │
│ "action": "SCMP_ACT_ALLOW" │
│ } │
│ ] │
│ } │
│ │
│ Everything is denied unless explicitly allowed. │
│ The default action is the baseline. │
│ The syscalls array overrides it for specific calls. │
│ │
└────────────────────────────────────────────────────────────┘
Allowlist vs Blocklist
┌────────────────────────────────────────────────────────────┐
│ ALLOWLIST vs BLOCKLIST │
│ │
│ ALLOWLIST (correct) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ defaultAction: SCMP_ACT_ERRNO │ │
│ │ syscalls: [read, write, open, close] │ │
│ │ │ │
│ │ Only listed calls are allowed. │ │
│ │ Everything else is denied. │ │
│ │ Unknown calls are blocked by default. │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ BLOCKLIST (incorrect) │
│ ┌──────────────────────────────────────────────────┐ │
│ │ defaultAction: SCMP_ACT_ALLOW │ │
│ │ syscalls: [chmod → DENY] │ │
│ │ │ │
│ │ Only listed calls are denied. │ │
│ │ Everything else is allowed. │ │
│ │ Unknown calls are permitted by default. │ │
│ │ WEAKER than the default profile. │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ The default profile is an allowlist. │
│ A custom profile must preserve that structure. │
│ │
└────────────────────────────────────────────────────────────┘
Defense in Depth
┌────────────────────────────────────────────────────────────┐
│ SECCOMP IN THE CONTAINER SECURITY MODEL │
│ │
│ ┌──────────────────────────────────────────────────┐ │
│ │ CAPABILITIES │ │
│ │ May the operation run? │ │
│ └──────────────────────────────────────────────────┘ │
│ │ │
│ v │
│ ┌──────────────────────────────────────────────────┐ │
│ │ SECCOMP │ │
│ │ May the syscall run? │ │
│ │ ← This chapter │ │
│ └──────────────────────────────────────────────────┘ │
│ │ │
│ v │
│ ┌──────────────────────────────────────────────────┐ │
│ │ APPARMOR / SELINUX │ │
│ │ May the resource be touched? │ │
│ └──────────────────────────────────────────────────┘ │
│ │ │
│ v │
│ ┌──────────────────────────────────────────────────┐ │
│ │ FILESYSTEM / USER / NAMESPACES │ │
│ │ What can be seen and written? │ │
│ └──────────────────────────────────────────────────┘ │
│ │
│ Each layer is independent. │
│ A compromise must defeat all layers. │
│ │
└────────────────────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Seccomp | Linux syscall filtering |
| Default profile | Allowlist blocking ~44 syscalls |
SCMP_ACT_ERRNO | Deny and return an error |
SCMP_ACT_ALLOW | Permit the syscall |
SCMP_ACT_LOG | Record without blocking |
defaultAction | Action for unlisted syscalls |
archMap | Architectures the profile applies to |
defaultErrnoRet | Error code for denied calls |
strace | Trace the application’s syscalls |
SCMP_ACT_LOG | Audit mode for profile development |
--security-opt seccomp= | Apply a custom profile |
Key takeaways:
- Seccomp filters syscalls before they reach the kernel. A blocked syscall never executes. This is the layer that limits the kernel attack surface available to a compromised container.
- The default profile is an allowlist. It denies all syscalls by default and permits a curated list. It blocks about 44 dangerous calls, including module loading, namespace cloning,
ptrace, and theio_uringfamily. - A custom profile must preserve the allowlist structure. Starting from
SCMP_ACT_ALLOWand blocking specific calls produces a blocklist that is weaker than the default, because it permits every dangerous call the default blocked. - The profile is derived empirically. Trace the application with
strace, extract the syscall names, and build the allowlist from what the application actually uses. Startup alone is not enough; the full application must be exercised. SCMP_ACT_LOGsupports profile development. The log action records syscalls without blocking them, so the application runs while the audit log captures the calls the profile would deny.- The error code matters.
EPERM(1) aborts the application.ENOSYS(38) causes glibc to fall back to an alternative call, which is often gentler. - Seccomp is one layer among several. Capabilities govern operations, seccomp governs syscalls, and AppArmor or SELinux governs resource access. A container is hardened only when all layers are considered.
- The profile is a contract that needs maintenance. A tighter profile provides stronger isolation but breaks when the application needs a new syscall. The decision is whether the isolation gain justifies the maintenance cost for the specific application.
Remember: Seccomp restricts which system calls a containerized process may make. Docker’s default profile is an allowlist that blocks about 44 dangerous calls while permitting the rest for compatibility. A custom profile narrows the allowlist to the syscalls the application actually uses, reducing the kernel attack surface to the minimum. The profile is developed by tracing the application with strace, extracting the syscall names, and building the allowlist from the observed calls. The structure must remain an allowlist: SCMP_ACT_ERRNO as the default action, with specific calls overridden to SCMP_ACT_ALLOW. A blocklist structure is weaker than the default, not stronger. The profile is applied with --security-opt seccomp=, tested by observing what breaks, and refined with SCMP_ACT_LOG until it is ready to enforce. Seccomp is one layer in a defense-in-depth model that also includes capabilities, AppArmor or SELinux, and the filesystem. Each layer addresses a different attack surface, and the combination is stronger than any single layer.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!