Learn how to use seccomp (secure computing mode) to restrict system calls in Kubernetes pods. Seccomp is a Linux kernel feature that limits which system calls a process can make, providing an additional security layer.
Prerequisites
Understanding Seccomp
Seccomp is a security mechanism that filters system calls:
Default behavior: Containers can make any system call
Security risk: Malicious code can exploit kernel vulnerabilities
Seccomp solution: Whitelist only necessary system calls
Kubernetes integration: Apply seccomp profiles to pods
Q1: What are the main seccomp profile types in Kubernetes?
Answer
Unconfined: No restrictions (default for most runtimes)
RuntimeDefault: Use the container runtime’s default seccomp profile
Localhost: Use a custom seccomp profile from the node’s filesystem
# Apply the podkubectl apply -f seccomp-pod.yaml
# Test system callskubectl exec -it seccomp-runtime-default -- sh
# Try some commands (these should work)ps aux
ls -la
cat /etc/passwd
# Try restricted operations (these might be blocked)mount
reboot # Should fail with permission error
Custom Seccomp Profiles
For more granular control, create custom seccomp profiles:
Step 1: Create a Custom Profile
Create a seccomp profile that blocks specific system calls:
# Create profiles directory on all nodessudo mkdir -p /var/lib/kubelet/seccomp/profiles
# Check if seccomp is enabled on the nodegrep -i seccomp /proc/version
# Check container's seccomp statuskubectl exec <pod-name> -- grep -i seccomp /proc/1/status
# Look for "Seccomp: 2" (filtered mode)
Test System Call Restrictions
# Create a test podkubectl run seccomp-test --image=busybox:latest \
--restart=Never \
--overrides='{"spec":{"securityContext":{"seccompProfile":{"type":"RuntimeDefault"}},"containers":[{"name":"seccomp-test","image":"busybox:latest","command":["/bin/sh"],"args":["-c","while true; do sleep 30; done;"],"securityContext":{"seccompProfile":{"type":"RuntimeDefault"}}}]}}'# Test restricted operationskubectl exec -it seccomp-test -- sh
# These might be restricted depending on the profilestrace -c ls 2>&1 | head -10 # System call tracingmount # Should failreboot # Should fail