By restricting syscalls, Seccomp helps reduce the attack surface in containerized environments. This guide outlines both default behaviors and custom configurations for running secure Kubernetes workloads.
Default Seccomp Profile in Docker
Docker uses a built-in Seccomp profile to block approximately 60 syscalls by default. To inspect Docker’s default Seccomp configuration, we can use the open-source container introspection tool called amicontained. Run the following command to launch amicontained as a Docker container:Running the Container as a Kubernetes Pod
Deploying the same image as a Kubernetes pod yields a different outcome. In Kubernetes (version 1.20 during this recording), Seccomp is not enabled by default. Create a pod with the following command:By default, Kubernetes pods do not enforce Seccomp filtering; hence, fewer syscalls are blocked.
Enabling Seccomp in a Kubernetes Pod
To enable Seccomp filtering in a pod, specify a Seccomp profile in the pod (or container) manifest. The example below demonstrates using the default Docker profile via theseccompProfile field under the pod-level security context:
allowPrivilegeEscalation: false restricts the container process from gaining additional privileges beyond what is needed.
Apply the pod definition:
Using the Unconfined Seccomp Profile
If you prefer to run a pod without any Seccomp restrictions (which is the default behavior), explicitly set the Seccomp profile to Unconfined in your pod manifest:Using Custom Seccomp Profiles
Custom Seccomp profiles offer granular security control based on your application’s syscall needs. The following sections detail how to create a pod with a custom Seccomp profile, enforce strict policies, and tailor profiles for your specific requirements.Creating a Pod with a Custom Profile
In this example, we create a pod using the Ubuntu image. The container prints a message and then sleeps for 100 seconds. The pod manifest below applies a custom Seccomp profile from a file on the node.The
localhostProfile path is relative to the default Seccomp profile directory (typically /var/lib/kubelet/seccomp). For example, if you place your custom profile in /var/lib/kubelet/seccomp/profiles/, the path might be profiles/audit.json.audit.json), you could set the default action to log syscalls:
/var/log/syslog). You can check the logs with:
Creating a Profile That Rejects All Syscalls
To enforce a stricter security posture, you can create a profile that denies any syscall by default. Create a JSON file (e.g.,violation.json) with the following content:
While a strict Seccomp profile can improve security, it may render the pod non-functional if critical syscalls are blocked.
Customizing and Using a Tailored Seccomp Profile
After analyzing your application’s syscall requirements—by inspecting audit logs or using tools like Tracee—you can craft a custom Seccomp profile that allows only the required syscalls. Create a custom profile JSON file (for example,custom.json) with specific rules and place it in the node’s Seccomp profile directory (typically in a profiles folder under /var/lib/kubelet/seccomp).
Then reference your custom profile in a pod definition: