SELinux and AppArmor Profiles
You'll learn: How to enforce mandatory access control (MAC) on containers using SELinux labels or AppArmor profiles to restrict what actions a container can perform at the kernel level.
What Are SELinux and AppArmor?
Both SELinux (Security-Enhanced Linux) and AppArmor are Linux kernel security modules that enforce mandatory access control. Think of them as security guards that enforce strict policies about what files a process can touch, which network ports it can use, and what system calls it can make—regardless of the user's permissions.
While Linux capabilities let you add or drop specific privileges, SELinux and AppArmor provide a broader security framework that confines entire processes based on predefined policies.
Applying Security Profiles in Kubernetes
You configure these profiles in your Pod's securityContext:
SELinux (Common on RHEL/CentOS)
securityContext:
seLinuxOptions:
level: "s0:c123,c456"
role: "system_r"
type: "container_t"
user: "system_u"
The type field is most critical—it defines the SELinux domain that confines the container.
AppArmor (Common on Ubuntu/Debian)
metadata:
annotations:
container.apparmor.security.beta.kubernetes.io/nginx: localhost/k8s-nginx-profile
The annotation references an AppArmor profile loaded on the node. Profiles must exist on nodes before use.
When to Use Them
Apply these when you need defense-in-depth beyond capabilities—for example, preventing a compromised container from reading sensitive host files even if an attacker gains root access inside the container.
Key Takeaway: SELinux labels and AppArmor profiles provide kernel-level mandatory access control that restricts container actions beyond traditional permissions, adding an essential security layer for production workloads.