AppArmor and SELinux for Containers
What you'll learn: How to use mandatory access control (MAC) systems to enforce fine-grained security policies that restrict what containerized processes can do, even if compromised.
The Core Idea
While seccomp filters syscalls, AppArmor and SELinux are mandatory access control frameworks that enforce what files, network ports, and capabilities a container process can access. Think of them as sophisticated security guards that check every action against a rulebook—even root can't bypass these policies.
These MAC systems operate at the kernel level, creating an additional security layer beyond container isolation. If an attacker escapes into your container or exploits a vulnerability, AppArmor or SELinux policies can still prevent them from reading sensitive files, binding to privileged ports, or loading kernel modules.
AppArmor vs SELinux
AppArmor (common on Ubuntu/Debian) uses path-based policies. You define which files a profile can read/write/execute by their filesystem paths.
SELinux (Red Hat/CentOS) uses label-based mandatory access control. Every process and file has a security context (label), and policies define which labels can interact.
Why This Matters for Containers
Containers share the host kernel. Without MAC policies, a compromised container might:
- Read
/etc/shadowif mounted - Access other containers' volumes
- Exploit kernel vulnerabilities with elevated capabilities
By applying restrictive AppArmor or SELinux profiles, you ensure container processes operate within tightly defined boundaries—limiting blast radius if compromised.
Container Runtime Integration
Docker and containerd support both systems. You can load custom profiles to deny file access, restrict network operations, or prevent capability escalation. Kubernetes can also enforce these policies through annotations or security contexts.
Key Takeaway: AppArmor and SELinux provide mandatory access control that restricts container processes at the kernel level, containing potential breaches even when traditional isolation fails.