Skip to content

Docker audit fix · Runtime & Resources

How to Audit AppArmor & SELinux in Docker Containers

A container whose AppArmor profile is empty or unconfined runs with no mandatory access control, leaving only capabilities and seccomp between it and the host. Keep Docker's docker-default profile, or an enforcing SELinux label.

Hiren KalariyaHiren KalariyaLast reviewed mac-confinement
CtrlOpsContainer AppArmor/SELinuxMEDIUM

What did your audit say?

WARN · when the audit printed

Neither AppArmor nor SELinux enforcing on the host

The host offers no mandatory access control at all, so no container on it can be confined; individual containers were not examined.

WARN · when the audit printed

Some containers run without an AppArmor/SELinux profile

AppArmor is present on the host but the named containers are running outside it, with no profile and no SELinux label.

Severity
Medium
Needs root or sudo
Yes
Results it can return
WARN · SKIP · PASS
Check in this audit
2 of 6

Every threshold on this page is transcribed from the docker-security-runtime-resources audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 6 Runtime & Resources checks, or how the audit runs.

The host is read first: AA_HOST is set to 1 when the directory /sys/kernel/security/apparmor exists or /usr/sbin/aa-status is executable, and SE_HOST is set to 1 only when getenforce prints exactly Enforcing. With both at 0 the check WARNs about the host and never looks at a container. When AppArmor is present it then reads .AppArmorProfile and .HostConfig.SecurityOpt for each running container, and adds that container to an unconfined list when the profile is empty or the literal string unconfined and no SecurityOpt entry contains the text label. An empty unconfined list is the PASS; anything on it is the second WARN, which names the containers.

Needs a reachable daemon and at least one running container; otherwise SKIP. The host is assessed first: AppArmor counts as present if /sys/kernel/security/apparmor exists or /usr/sbin/aa-status is executable, SELinux only if getenforce prints exactly Enforcing. If neither, the check WARNs about the host and never examines containers.

Note an asymmetry in the per-container logic: containers are only inspected when AppArmor is present. On an SELinux-only host (RHEL family) the host test passes and the per-container loop finds nothing, so the result is PASS without any container having been individually checked. Note also that AppArmor's presence is detected from the filesystem, not from whether it is actually enforcing, and that the SELinux test is a plain text match on label, so --security-opt label=disable, which switches SELinux confinement off, counts as a label too.

What each result means
ResultWhenWhat it means
SKIPNo running containersNothing was verified. No container was inspected and the host's AppArmor and SELinux state was never even read.
WARNNeither AppArmor nor SELinux enforcing on the hostThe host offers no mandatory access control at all, so no container on it can be confined; individual containers were not examined.
WARNSome containers run without an AppArmor/SELinux profileAppArmor is present on the host but the named containers are running outside it, with no profile and no SELinux label.
PASSAll confinedEvery container the loop examined carries an AppArmor profile or an SELinux label option - on an SELinux-only host that loop examines none of them.

Mandatory access control adds a second independent layer beyond capabilities/seccomp: Docker's docker-default AppArmor profile denies writes to /proc/sys, /sys, mounting, and ptrace of other processes; on SELinux hosts, container_t with MCS labels isolates containers from the host and from each other. OWASP Docker Cheat Sheet Rule #6; CIS Docker 5.1 "Ensure that, if applicable, an AppArmor Profile is enabled" and 5.2 (SELinux); NIST SP 800-190 4.4.

  • AppArmorProfile is empty when the docker-default profile could not be loaded (missing apparmor userspace package, apparmor_parser absent, or AppArmor disabled in the kernel command line). docker info shows apparmor under Security Options when it is active.
  • On SELinux hosts (RHEL/Fedora), containers are confined by default only if Docker runs with --selinux-enabled (daemon.json "selinux-enabled": true); many Docker CE installs on RHEL do not enable it, and this check does not inspect containers in that case (it reports PASS once SE_HOST=1). Podman enables SELinux by default.
  • --security-opt apparmor=unconfined or --privileged produce unconfined.
  • Any SecurityOpt entry containing label exempts a container from the AppArmor test, including label=disable, which turns SELinux confinement off.
  • Debian 10+ and Ubuntu hosts ship with AppArmor enabled; Alpine and other minimal host distributions often do not.
  1. Enable AppArmor on Debian or Ubuntu

    sh
    sudo apt install apparmor apparmor-utilssudo systemctl enable --now apparmorsudo aa-status | grep docker-defaultsudo systemctl restart docker

    Docker attaches docker-default to every container it creates once AppArmor is available.

  2. Alternative

    Or enable SELinux labelling on RHEL-family hosts

    Put SELinux in enforcing mode (setenforce 1, and SELINUX=enforcing in /etc/selinux/config), then tell Docker CE to label containers:

    json
    {  "selinux-enabled": true}

    Add that to /etc/docker/daemon.json, restart Docker, and relabel bind mounts with :z (shared) or :Z (private) so containers can still read them.

  3. Remove apparmor=unconfined and label=disable

    Delete these from docker run commands and from Compose security_opt lists. Both switch confinement off for that container, and the second one hides it from this check.

  4. Write a custom profile where docker-default is too strict

    If a workload fails under the default, find the exact denial with journalctl -k | grep -i 'apparmor="DENIED"', write a profile that allows only that operation, and load it:

    sh
    sudo apparmor_parser -r /etc/apparmor.d/containers/myprofiledocker run --security-opt apparmor=myprofile ...

  5. Recreate the containers

    The profile is attached when a container is created.

    sh
    docker compose up -d --force-recreate

sh
# Host side:sudo aa-status | head -3          # AppArmor: profiles loaded and in enforce modegetenforce                        # SELinux: expected Enforcingdocker info --format '{{.SecurityOptions}}'# Per container:docker inspect -f '{{.Name}} apparmor={{.AppArmorProfile}} opts={{.HostConfig.SecurityOpt}}' $(docker ps -q)# expected: docker-default (or a custom profile), never empty/unconfined, and no label=disable# The kernel's view from inside:docker exec <name> cat /proc/1/attr/current# expected: docker-default (enforce) - or an SELinux label such as system_u:system_r:container_t:s0:...

Debugging

  • This one message covers two different cases: the audit could not reach the Docker daemon, or it reached it and nothing was running. Run docker ps as the audit user, then sudo docker ps. If both fail, the daemon is unreachable: check systemctl status docker, then run the audit as root or give the account sudo. If they work but list nothing, there is genuinely nothing to evaluate, and a stopped container is never checked. The Docker Inventory check reports the two cases separately, so its result tells you which one you hit.
  • The host has no mandatory access control. On Debian/Ubuntu: apt install apparmor apparmor-utils, ensure apparmor.service is enabled, and restart Docker so it applies docker-default. On RHEL family: setenforce 1 and set SELINUX=enforcing in /etc/selinux/config.
  • Usually --security-opt apparmor=unconfined was set to work around a denial. Fix the profile instead: check journalctl -k | grep -i 'apparmor="DENIED"' for the exact operation and write a custom profile.
  • The structural gap described above. Verify individually with docker exec <name> cat /proc/1/attr/current, and confirm selinux-enabled is set with docker info --format '{{.SecurityOptions}}', which should list name=selinux.
  • The check treats any SecurityOpt entry containing label as an SELinux label, so label=disable exempts a container even though it disables confinement. List them with docker inspect -f '{{.Name}} {{.HostConfig.SecurityOpt}}' $(docker ps -q) | grep label=disable and remove the option.
  • Presence is detected from the filesystem. Confirm the mode with sudo aa-status, which reports how many profiles are in enforce versus complain mode.
  • The docker-default profile blocks some legitimate operations for unusual workloads. The denial appears in journalctl -k; write a targeted custom profile and load it with apparmor_parser -r, rather than reverting to unconfined.

Sources

Next

Re-run the Runtime & Resources audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 6 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

Download for MacDownload for WindowsAll 6 Runtime & Resources fixes

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google Analytics cookies and live chat stay off until you allow them. Cookie policy