Skip to main content
In this article, we explore how to implement Seccomp profiles in Kubernetes to bolster container security by filtering system calls (syscalls). We start by reviewing how Docker and Kubernetes apply Seccomp by default and then demonstrate how to enable and customize Seccomp profiles within Kubernetes pods.
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:
The command output indicates that 64 syscalls are blocked due to Docker’s default Seccomp profile. Notice that the Seccomp mode is set to filtering (mode 2):

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:
You should see:
Next, inspect the pod logs:
The log output will display Seccomp as disabled along with only 21 syscalls being blocked:
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 the seccompProfile field under the pod-level security context:
Setting allowPrivilegeEscalation: false restricts the container process from gaining additional privileges beyond what is needed. Apply the pod definition:
Then verify the pod logs:
The logs should now show that Seccomp filtering is active with additional syscalls being blocked:

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.
Inside your custom profile (e.g., audit.json), you could set the default action to log syscalls:
Once the pod is running, all container syscalls are logged to the node’s syslog (commonly /var/log/syslog). You can check the logs with:
A sample audit log might look like:
Additionally, tools like Tracee can be useful for analyzing syscalls. For instance, run the Tracee container to monitor new container syscalls:

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:
Apply this profile in your pod’s security context. When created, the pod status will be “ContainerCannotRun” because even essential syscalls are blocked. For example: Apply the pod definition:
Then check the pod status:
Expected output:
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:
Verify that the pod starts successfully:
Expected output:
Once your custom profile is applied, only the required syscalls will be allowed, enhancing container isolation and security.

Conclusion

Implementing and customizing Seccomp profiles in Kubernetes enhances container security by limiting unnecessary syscalls. Although creating a custom profile can be time-consuming, mastering existing profiles and tailoring them to your application’s needs is essential for a secure container environment. For further details, refer to the official Kubernetes Seccomp Documentation. Now is the time to experiment with Seccomp profiles in your environment. By leveraging these security measures, you can achieve a more robust and secure Kubernetes deployment.

Watch Video

Practice Lab