OnCallReadyStart learning

Security and secrets Lesson 23.17 · Kubernetes Security (CKS) · 3 min read

seccomp: allow-list the system calls

In plain words

Every program talks to the kernel through a phone line of numbered calls: open a file, make a folder, open a network socket. seccomp is a call filter on that line. Some numbers go straight through, others get a busy tone and fail. A container cannot change the filter from the inside, so even a compromised program is stuck with the calls it is allowed to make.

The kernel interface, filtered

Every file, network and process action is a system call. A seccomp profile tells the kernel which ones a container may make. RuntimeDefault (chapter 19) blocks the dangerous few the container runtime knows about; a Localhost profile is your own, read from the node:

securityContext:
  seccompProfile:
    type: Localhost
    localhostProfile: profiles/deny-mkdir.json   # under /var/lib/kubelet/seccomp/ on the node
{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"names":["mkdir","mkdirat"],"action":"SCMP_ACT_ERRNO"}]}

SCMP_ACT_ERRNO makes the call fail with an error (here mkdir answers "Operation not permitted"); SCMP_ACT_KILL kills the process. A real hardened profile is the other way round: defaultAction: SCMP_ACT_ERRNO and an allow-list of what the app needs.

The path is relative to the kubelet's seccomp directory, and the file must exist on the node: if it does not, the container is not created ("cannot load seccomp profile"). (simulator) commands map to their main system calls.

On the exam: "copy this profile to the node and run the pod with it", then prove a blocked call fails.

Why it helps

Most container escapes need unusual system calls, so filtering them shrinks what an attacker can do after getting in. The exam asks you to put a given profile on a node and run a pod with it, and the same Localhost mechanics as AppArmor apply. Understanding the difference between RuntimeDefault and your own profile shows how far you can tighten a workload.

FAQ

What is the difference between RuntimeDefault and Localhost?

RuntimeDefault is the container runtime's own list of blocked calls, a sensible default for most workloads. Localhost is your own JSON profile, read from the kubelet's seccomp directory, /var/lib/kubelet/seccomp, on the node. Use Localhost when you need rules RuntimeDefault does not have.

What does SCMP_ACT_ERRNO do?

It makes the matching system call fail with an error, so a blocked mkdir answers Operation not permitted. SCMP_ACT_KILL is stricter and kills the process, which is harder to debug but leaves no way around the rule.

Where must the profile file be?

On the node that runs the pod, under the kubelet's seccomp directory, at the path given in localhostProfile, for example profiles/deny-mkdir.json. Every node the pod might run on needs the same file. A DaemonSet or the node image can place it everywhere at once.

What happens if the file is missing?

The container is not created, because the kubelet cannot load the seccomp profile. kubectl describe pod shows the error with the full path it looked for, which tells you which node is missing the file.

Should a production profile allow or deny by default?

Deny by default, with defaultAction SCMP_ACT_ERRNO and an allow-list of the calls the application needs. Until you know that list, start with RuntimeDefault, which already blocks the dangerous calls the runtime knows about. Tighten step by step and test the application after each change.

In an interview Mid

What is seccomp and how do you use it in Kubernetes?

A kernel filter on system calls. securityContext.seccompProfile type RuntimeDefault uses the runtime's filter; type Localhost with localhostProfile reads your JSON profile from /var/lib/kubelet/seccomp on the node, where SCMP_ACT_ERRNO rules make blocked calls fail with Operation not permitted. The file must exist on every node the pod can run on, or the container is not created.

Also asked: What happens when a Localhost seccomp profile is missing? · Why start with RuntimeDefault? · How is seccomp different from AppArmor?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.