Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 109/ 160
06. Docker Security & Hardening

AppArmor & SELinux Mandatory Access Control for Containers

Apply AppArmor/SELinux profiles so containers only touch allowed host resources.

AdvancedAppArmor · SELinux3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 recent for 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

Loading interactive 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.

Concrete AppArmor setup

docker run --security-opt apparmor=docker-default --security-opt label=type:container_t app:prod; ausearch -m AVC -ts recent

Key takeaway: Prove SELinux with 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.

Deliberate failure test

Exercise this failure safely: running setenforce 0 globally to debug one container denial, or assuming AppArmor JSON syntax works on a SELinux-only distro.

Key takeaway: Default profiles are low-friction; custom enforcement yields strong host-resource policy but needs change and audit expertise.

How it works, step by step

Step 1 of 4
Design

1. 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.

Use the distribution’s default MAC framework and add workload-specific policy only for paths or capabilities the Linux DAC model cannot express.
Key numbers at this step
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 test in 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

Explicit AppArmor
Best for: Apply AppArmor/SELinux profiles so containers only touch allowed host resources, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived SELinux experiments with low blast radius.

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.

Managed MAC
Best for: Teams that centralize MAC policy across many workloads.

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 recent as proof and skipping confirm 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 recent address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Seccomp Profiles (Filtering Linux System Calls)
Next topic
Securing the Docker Daemon Socket (/var/run/docker.sock Risks)