AppArmor & SELinux Mandatory Access Control for Containers
Apply AppArmor/SELinux profiles so containers only touch allowed host resources.
In plain words
Use the distribution’s default MAC framework and add workload-specific policy only for paths or capabilities the Linux DAC model cannot express.
Think of it like…
Unix mode bits are door locks; MAC is the building authority that can still deny a visitor who has a copied key.
Where you’ve seen it
In practice, docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent is the concrete move for this job: apply AppArmor/SELinux profiles so containers only touch allowed host resources. The release is not accepted until confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test confirms the result.
Words you’ll hear
- AppArmor
- The implementation control in
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recentfor apply AppArmor/SELinux profiles so containers only touch allowed host resources. - SELinux
- The result to observe with
confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test, rather than infer from a successful command alone. - MAC
- The production boundary exposed when running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.
Visual diagram
Theory & deep dive
AppArmor control path
The concrete mechanism is docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent. The observable result is confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test; if those disagree, inspect the runtime evidence before changing unrelated settings.
Apply AppArmor/SELinux profiles so containers only touch allowed host resources. Keep AppArmor, SELinux and MAC in the same deployment record so the intent and the observed state cannot drift apart.
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent
confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test, not with command success alone.MAC failure boundary
Loading an AppArmor profile without making it enforce, or using --security-opt label=disable, removes a protection silently. chmod 777 does not repair an SELinux AVC, and z/Z must match whether a host path is shared. The narrow failure to design for is running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.
Accept this compromise explicitly: Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise. The controlled check-confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test-also identifies the point where a different design is safer.
Exercise this failure safely: running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: Loading an AppArmor profile without making it enforce, or using --security-opt label=disable, removes a protection silently. chmod 777 does not repair an SELinux AVC, and z/Z must match whether a host path is shared.
- Intent
- AppArmor
When to use it & trade-offs
What it is
AppArmor attaches a path-oriented Linux Security Module profile; SELinux applies labels and type-enforcement rules. Docker can select the host’s supported profile and relabel bind mounts, but a compliant profile must still match the distro and application file/network behavior.
Why it matters: Loading an AppArmor profile without making it enforce, or using --security-opt label=disable, removes a protection silently. chmod 777 does not repair an SELinux AVC, and z/Z must match whether a host path is shared.
When to reach for it
- The fit is strongest for this job: apply AppArmor/SELinux profiles so containers only touch allowed host resources. Pair it with
confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file testin the runbook. - Production AppArmor changes should make SELinux observable through
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent, rather than trusting the runtime default. - Keep a rollback example for the case where running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.
When to avoid or be careful
- Do not accept command success while the system can still fail by running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.
- Avoid erasing MAC protection merely to dodge this cost: “Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise”.
- Do not replace the evidence path-
confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test-with a screenshot or a mutable tag.
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent: practical choices
Strengths: AppArmor attaches a path-oriented Linux Security Module profile; SELinux applies labels and type-enforcement rules. Docker can select the host’s supported profile and relabel bind mounts, but a compliant profile must still match the distro and application file/network behavior.
Watch out: Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise.
Strengths: It can begin with docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent and fewer surrounding controls.
Watch out: It silently accepts running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro, which makes the result hard to reproduce after promotion.
Strengths: Loading an AppArmor profile without making it enforce, or using --security-opt label=disable, removes a protection silently. chmod 777 does not repair an SELinux AVC, and z/Z must match whether a host path is shared.
Watch out: The platform adds an ownership and debugging layer; retain confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent
- confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test
- Failure signature: running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro
- Trade-off: Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise.
Benchmarks & rules of thumb
- 1 active LSM profile
- per workload process at a time for the relevant framework
- 2 host ecosystems
- AppArmor vs SELinux semantics differ
- AVC
- SELinux denial record used for diagnosis
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recentas proof and skippingconfirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test. - Running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro
- Optimizing AppArmor without accepting that default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise.
Likely interviewer follow-ups
- Why does
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recentaddress AppArmor here rather than through application code? - How would you distinguish healthy SELinux from the failure “running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro” using
confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test? - When would this trade-off-“Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise”-justify a different MAC design?
docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent-and one proof-confirm AppArmor: docker-default from /proc/1/attr/current or the SELinux AVC path during an intentional denied file test. Then name the boundary: running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.Knowledge check
Put it into practice
Practice related interview Q&A
Apply AppArmor & SELinux Mandatory Access Control for Containers with generative AI interview Q&A and hands-on practice.