Exercise: block mkdir with a seccomp profile
Host: worker (root) + controlplane · Time: 10 min · Domain: System Hardening
Task
- Write a seccomp profile that returns
EPERMformkdirandmkdirat. - Put it where the kubelet expects it.
- Apply it to container
testerin a Pod in namespaceprod; the Pod must run.
Acceptance criteria
kubectl exec -n prod tester-pod -- mkdir /tmp/x→Operation not permitted.kubectl exec -n prod tester-pod -- ls /still works./proc/self/statusshowsSeccomp: 2.
Solution
sudo mkdir -p /var/lib/kubelet/seccomp/profiles
sudo tee /var/lib/kubelet/seccomp/profiles/mkdir-deny.json >/dev/null <<'EOF'
{
"defaultAction": "SCMP_ACT_ALLOW",
"architectures": ["SCMP_ARCH_X86_64", "SCMP_ARCH_X86", "SCMP_ARCH_X32"],
"syscalls": [
{"names": ["mkdir", "mkdirat"], "action": "SCMP_ACT_ERRNO"}
]
}
EOF
securityContext:
seccompProfile:
type: Localhost
localhostProfile: profiles/mkdir-deny.json
Validate the JSON before applying: python3 -m json.tool /var/lib/kubelet/seccomp/profiles/mkdir-deny.json.
A malformed profile prevents the container from starting.