Seccomp filters the system calls a container can send to the Linux kernel, and a RuntimeDefault profile already blocks about forty of them without any ordinary application noticing. It is a cheap protection: one line of securityContext, no file to distribute, no node restart. This guide shows you how to apply it, how to write a custom profile when the runtime's profile is not enough, and above all how to check that the filter is working, because a manifest that declares a profile does not guarantee that the kernel applies it.
Prerequisites: a Kubernetes cluster and kubectl. Unlike
AppArmor,
seccomp works on nodes that are themselves containers, kind
included: this whole guide can be practised on a workstation.
What you will learn
- What a system call is and why filtering it reduces the attack surface
- Applying
RuntimeDefaultto a Pod, the form to aim for by default - Writing a
Localhostprofile and understanding what it costs to maintain - Checking in
/procthat the filter is really in place - Recognising what cancels seccomp without emitting a single warning
What is a system call, and why filter it?
A system call, or syscall, is the only door through which a program asks the Linux kernel for anything: opening a file, writing to a socket, creating a process, mounting a filesystem. A recent x86_64 kernel exposes more than 300 of them. A typical web application uses a few dozen and ignores all the rest.
That remainder is precisely the problem. A container without a seccomp profile can call all 300, including those that only serve to administer the kernel or to escape a sandbox: mount, unshare, ptrace, kexec_load, perf_event_open. None of them is useful to a business application, and each has already served as a stepping stone to privilege escalation. Seccomp (short for SECure COMPuting) installs a filter in the kernel that refuses the calls that are not allowed, and this filter applies to the process before the application code even starts.
The three types of seccomp profile
RuntimeDefault is the only one to aim for by default; the other two are exceptions that need a justification. Unconfined disables the filter completely and is only for the time it takes to identify the call that blocks an application. Localhost requires you to distribute and maintain a JSON file on every node, which is a real operational debt.
| Type | Description | When to use it |
|---|---|---|
Unconfined | No restriction, the historical default | Debugging only |
RuntimeDefault | Profile shipped by the container runtime | Production, universal starting point |
Localhost | Custom JSON profile, present on the node | When RuntimeDefault is too restrictive |
The RuntimeDefault profile is the one the runtime embeds, containerd or CRI-O depending on your cluster. The Docker documentation, where this profile comes from, says that it "disables around 44 system calls out of 300+". In other words, an ordinary application will see no difference, and that is exactly what makes it possible to enable it everywhere without a test campaign.
Apply RuntimeDefault to a Pod
Declared at the spec.securityContext level, the profile applies to every container of the Pod, init containers and sidecars included. This is the form to prefer: a single declaration, and no container forgotten when one is added later.
apiVersion: v1kind: Podmetadata: name: app-seccompspec: securityContext: seccompProfile: type: RuntimeDefault # Runtime profile (containerd/cri-o) containers: - name: app image: nginx:1.31-alpine@sha256:72ba65eb42c10344912a84ff42408db7d34f2feb642204570ab8fc5ffd29f1d3Pod or container: which one wins?
Both levels exist, and their priority is the one you would expect: the container's securityContext takes precedence over the Pod's. A Pod that declares RuntimeDefault for everyone can therefore host a container that goes back to Unconfined, and this is a legitimate way out for a debugging sidecar.
spec: securityContext: seccompProfile: type: RuntimeDefault # applies to all containers containers: - name: app # inherits RuntimeDefault image: nginx:1.31-alpine@sha256:72ba65eb42c10344912a84ff42408db7d34f2feb642204570ab8fc5ffd29f1d3 - name: debug image: nicolaka/netshoot:v0.16@sha256:b09d9b21381f47a79b3cbcb30da25266dc17186ea00ae65e99fdc51396f48e70 securityContext: seccompProfile: type: Unconfined # this override winsIt is also the first thing to look at when a Pod seems protected and is not: the Pod's declaration says nothing about what each container applies. A manifest review must go down to the container level, and an admission policy must test both levels in that order.
Write and deploy a Localhost profile
When an application needs calls that RuntimeDefault refuses, or when you want on the contrary a strict allowlist, the profile goes through a JSON file present on the node. The deciding field is defaultAction: with SCMP_ACT_ERRNO, every call missing from the names list is refused with EPERM. Here is the file, which you first create on your workstation, in a profiles folder:
{ "defaultAction": "SCMP_ACT_ERRNO", "architectures": ["SCMP_ARCH_X86_64"], "syscalls": [ { "names": ["read", "write", "close", "fstat", "mmap", "mprotect", "munmap", "brk", "rt_sigaction", "rt_sigprocmask", "ioctl", "access", "execve", "exit_group", "openat", "newfstatat", "pread64", "prlimit64"], "action": "SCMP_ACT_ALLOW" } ]}This example is deliberately minimal and will not be enough for any real application: it is a starting point to complete by watching the refusals, not a profile to copy into production. Three actions appear in these files, and they do not serve the same purpose: SCMP_ACT_ALLOW allows, SCMP_ACT_ERRNO refuses by returning an error to the program, and SCMP_ACT_LOG lets the call through while logging it, which makes it the tuning tool for a profile before you tighten it.
The file must then be in /var/lib/kubelet/seccomp/profiles/ on every node. How you put it there depends on what your node is.
On a kind cluster: mount the folder into the nodes
On kind, a node is a Docker container. A sudo mkdir run on your workstation would create the file on the workstation, not in the node, and the kubelet would never see it. The profiles folder is therefore mounted into each node when the cluster is created, with extraMounts:
kind: ClusterapiVersion: kind.x-k8s.io/v1alpha4nodes: - role: control-plane image: kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5 extraMounts: - hostPath: ./profiles containerPath: /var/lib/kubelet/seccomp/profiles - role: worker image: kindest/node:v1.37.0@sha256:a1ed56cfb0e7b93589bdf97c8cd566405a265939e3620fc4f5de89adff580ae5 extraMounts: - hostPath: ./profiles containerPath: /var/lib/kubelet/seccomp/profilesThe mount is declared for each node: the scheduler can place a Pod on any of them, and a single node without the folder is enough to block it. Create the cluster from the folder that contains profiles (the ./profiles path is relative to the folder where you run the command), then check that the node sees the file:
kind create cluster --name seccomp-lab --config kind-seccomp.yamldocker exec seccomp-lab-worker ls /var/lib/kubelet/seccomp/profilesThe second command must print myapp.json. If it prints nothing, the mount did not happen: the configuration file was not read, or ./profiles did not exist when the cluster was created.
On a real machine: copy the file to the node
On a node that is a real machine or a VM, you copy the file into the directory the kubelet expects, with sudo and on every node where a Pod can be placed:
sudo mkdir -p /var/lib/kubelet/seccomp/profilessudo cp profiles/myapp.json /var/lib/kubelet/seccomp/profiles/myapp.jsonReference the profile in the Pod
The manifest then designates the file by a path relative to /var/lib/kubelet/seccomp/:
apiVersion: v1kind: Podmetadata: name: app-seccomp-customspec: securityContext: seccompProfile: type: Localhost localhostProfile: profiles/myapp.json containers: - name: app image: nginx:1.31-alpine@sha256:72ba65eb42c10344912a84ff42408db7d34f2feb642204570ab8fc5ffd29f1d3This Pod should not reach Running: the profile on this page allows 18 system calls, and a server like nginx needs far more (creating a socket, listening on a port, changing user). Every call missing from the list gets an error, because defaultAction is SCMP_ACT_ERRNO. The official Kubernetes tutorial shows a similar case, a profile that refuses all calls: the Pod is created, but its container does not start, and kubectl get pod shows CrashLoopBackOff. That is the first symptom in the troubleshooting table. To get a usable profile, switch defaultAction to SCMP_ACT_LOG, note the calls that are really made, then add them to the names list.
If the file does not exist on the node chosen to host the Pod, the kubelet refuses to start the container instead of launching it without protection. The behaviour is the right one, but it turns the presence of the profile on every node into an operational prerequisite: in a heterogeneous cluster, a Pod placed on the wrong node stays stuck.
How can you check that a profile is really applied?
Never conclude from the manifest. The first command rereads what the Pod declares, which proves nothing about the state of the process. The second reads the real attribute in /proc, and it is the only one that is authoritative. The number it returns comes from the Linux kernel, not from Kubernetes.
# What the manifest declareskubectl get pod app-seccomp -o jsonpath='{.spec.securityContext.seccompProfile}'
# What the kernel applies, read from inside the container itselfkubectl exec app-seccomp -- grep Seccomp /proc/1/statusSeccomp: 2Seccomp_filters: 1The value that matters is 2, for "filter in place". 0 means Unconfined and 1 is the historical strict mode, which Kubernetes does not use. The difference shows up between two Pods identical except for one field, on the same cluster:
| Pod | securityContext.seccompProfile | /proc/1/status |
|---|---|---|
| with | type: RuntimeDefault | Seccomp: 2 and Seccomp_filters: 1 |
| without | none | Seccomp: 0 |
If the Pod has no shell, or if you are investigating a container that has already stopped, you have to go through the node and find the process by its identifier:
crictl inspect <container-id> | jq '.info.pid'grep Seccomp /proc/<pid>/statusWhat silently cancels seccomp
This is why the check through /proc is needed. A 0 on a Pod that nevertheless declares RuntimeDefault points first to a privileged container, or to an Unconfined override at the container level (see above): in both cases, the hardening is cancelled silently. The same trap applies to AppArmor, whose profiles are ignored under the same conditions.
Seccomp and AppArmor: two filters, two surfaces
Both mechanisms live in the Linux kernel and look alike from a distance, but they do not filter the same thing and do not replace each other. Applying them together is what the term defense in depth refers to.
| Mechanism | What it controls | Examples |
|---|---|---|
| Seccomp | System calls | Block unshare, mount, ptrace, setuid |
| AppArmor | Files, capabilities, network | Forbid writing to /etc, restrict the network |
One practical difference separates them, and it decides what you can try out in a lab: AppArmor requires a node whose kernel enables it, which rules out clusters whose nodes are containers, whereas seccomp works on those same nodes. The details of AppArmor profiles, how they are loaded and how they are checked live on its dedicated page.
Applying seccomp at scale
Two levers exist, and they are often confused. seccompDefault: true on the kubelet side changes the default behaviour at runtime: any Pod without a declaration runs with RuntimeDefault, without the Pod's seccompProfile field being modified. Pod Security Admission, for its part, mutates nothing and reads the Pod specification: its restricted profile refuses the Pods that declare Unconfined, and also those that declare no profile, even if the kubelet applies RuntimeDefault at runtime.
apiVersion: v1kind: Namespacemetadata: name: production labels: pod-security.kubernetes.io/enforce: restricted pod-security.kubernetes.io/enforce-version: latestThe combination that holds up in production is therefore the sum of both: seccompDefault so that the absence of a declaration becomes protective at runtime, and PSA so that every Pod declares an allowed profile and nobody goes back with Unconfined. To go further, for example to require a specific Localhost profile, you need an admission policy written with Kyverno or Gatekeeper.
Troubleshooting
The first symptom in the table is often confusing: the application starts then dies with no clear message, because a call it needs to send is refused. The method is always the same: switch the profile back to logging mode to see what is refused before tightening it again.
| Symptom | Likely cause | Solution |
|---|---|---|
| The application crashes at startup | A necessary system call is refused | Switch the profile to SCMP_ACT_LOG, read journalctl -k and dmesg | grep -i seccomp |
| The container does not start at all | Localhost profile missing from the node that hosts the Pod | Check the node with kubectl get pod -o wide, copy the file there, or go back to RuntimeDefault |
Seccomp: 0 although the Pod declares a profile | Container with privileged: true | Remove privileged, the filter is cancelled without warning |
| The profile seems ignored | Override at the container level | The container's securityContext takes precedence over the Pod's |
| The Pod is refused at admission | Explicit Unconfined, or no profile declared, in a restricted namespace | Declare RuntimeDefault at the Pod level, or justify a namespace exception |
Limits of seccomp
Four limits explain why seccomp is not deployed everywhere, even though it costs almost nothing. The first three come from the infrastructure, the last one from your own manifests.
- Linux only: none of this applies to Windows nodes.
- Runtime dependency: the exact content of
RuntimeDefaultcomes from containerd or CRI-O, it is not defined by Kubernetes. Localhostis distributed by hand: the file must exist on all the nodes where the Pod can be placed, and managed environments often limit access to the nodes.privilegedcancels everything: a single privileged container is enough to make the whole measure meaningless.
A fifth limit is of a different nature: seccomp allows or refuses a system call, it does not judge how it is used. A process allowed to openat can open any file its permissions give it access to. AppArmor, SELinux or a runtime sandbox answer that question.
What comes up on the CKS
Seccomp belongs to the System Hardening domain, which weighs 10% of the exam. Three points are discriminating, and they are rarely the most obvious ones: the priority of the container level over the Pod level, the difference between seccompDefault on the kubelet side and the restricted profile of Pod Security Admission, and the fact that a privileged container cancels the filter. Knowing how to write the seccompProfile field is not enough, the exam tests what happens when two mechanisms contradict each other.
Hands-on practice
A profile is not judged by its JSON but by what it refuses. This lab has you write a seccomp profile that forbids a family of system calls, apply it through the securityContext, then check that the confinement holds from inside the container: the forbidden call fails, and everything else keeps working.
Key takeaways
- Seccomp filters the system calls a container sends to the kernel, about 44 blocked out of more than 300 with
RuntimeDefault RuntimeDefaultis the universal starting point: no ordinary application notices it- Without
seccompDefault: trueon the kubelet side, a Pod that declares nothing staysUnconfined - PSA does not mutate: in
restricted, it rejectsUnconfinedand the absence of a profile, it never adds a profile - The container level wins over the Pod level, including to go back to
Unconfined - A
Localhostprofile must exist on every node where the Pod can be placed privileged: truecancels the filter silently: only/proc/1/statusis authoritative
Knowledge check
The questions cover what really decides in production as well as in the exam: the default profile when nothing is declared, the priority between the two levels, and what Pod Security Admission really does. A wrong answer points to the section to reread.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Pod Security Standards (PSS): securing Kubernetes workloads
A new full quiz with random questions
Work again only on the questions you missed