Join our Newsletter — 33% off our NHI Course
Home› Guides› Reference Monitors and Mandatory Access Control Guide: Confine…
Guide Endpoint Security

Reference Monitors and Mandatory Access Control Guide: Confine Linux Hosts and Containers

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 13 min read
On this page

On a Linux host, file permissions and root decide almost everything, so one exploited service or one escaped container process inherits far more than it should. Mandatory access control (MAC) adds a second, system-enforced decision that the process cannot switch off: the kernel's Linux Security Module (LSM) framework acts as a reference monitor and asks SELinux, AppArmor or another module whether each access is allowed. This guide explains the reference monitor idea in practical terms, how the LSM framework works, how SELinux and AppArmor differ, how to choose between them, how MAC applies to Docker and Kubernetes workloads, and how to roll it out and measure it. It is for Linux platform engineers, container platform teams and security architects. For SELinux contexts, booleans and policy modules in depth, use the SELinux Guide; this page sits above it.

Key takeaways

  • MAC is enforced by the kernel, not the application. LSM hooks run inside the kernel on security-relevant operations, so even a process running as root is held to the loaded policy.
  • SELinux labels objects, AppArmor confines programs. SELinux decides on security contexts attached to every process and file; AppArmor applies per-program profiles, and programs without a profile run unconfined.
  • Pick by distribution and team, not by benchmark. Use the module your distribution ships and supports by default; running against the grain costs more than any theoretical strength difference.
  • Containers depend on MAC more than hosts do. Docker's docker-default AppArmor profile, SELinux category labels and the Kubernetes Pod Security Standards all assume MAC is on; privileged or unconfined pods remove that layer.
  • Roll out through learning modes. AppArmor complain mode and SELinux permissive mode log what would be denied, which makes MAC deployable without outages if you actually read the logs.

The reference monitor in practice

James Anderson's 1972 Computer Security Technology Planning Study defined a reference monitor as the mechanism that validates every reference a program makes against what the subject is authorised to do, and set three principles for its implementation: it must be tamper-proof, always invoked, and small enough to be subject to analysis and tests. NIST SP 800-53 Rev. 5 still carries the idea as AC-25 Reference Monitor, alongside AC-3(3) Mandatory Access Control. See the Classic Security Models Guide for the models these mechanisms enforce.

PrincipleHow Linux MAC meets itWhere it breaks in practice
Always invokedLSM hooks sit on kernel paths for file, process, socket and IPC operationsModule disabled at boot, profile missing, or a process running unconfined
Tamper-proofPolicy is loaded by privileged tooling and enforced in kernel spaceRoot can switch to permissive or unload profiles unless that is itself restricted and monitored
Small enough to verifyEnforcement code is in the kernel; policy is declarative and reviewablePolicies grow large, broad allow rules and unconfined domains make review impractical

How the Linux Security Module framework works

The kernel documentation describes LSM as a framework that lets security checks be hooked by kernel extensions. Despite the name, these are not loadable kernel modules: they are built into the kernel and selected at build time (CONFIG_DEFAULT_SECURITY, with CONFIG_LSM controlling load order) or at boot with the security= argument. The capability module always runs first, followed by any minor modules, then the major MAC module. The active list, in check order, is in /sys/kernel/security/lsm.

ModuleTypeModelTypical use
SELinuxMajorLabels (security contexts) on every subject and object; type enforcement, optional MLS/MCSRed Hat family, Fedora, Android
AppArmorMajorTask-centred profiles loaded from user space; unprofiled tasks unconfinedUbuntu, Debian, SUSE
SmackMajorSimplified label-based MACEmbedded systems
TOMOYOMajorPath and process-history basedNiche deployments
LandlockMinor, stackableUnprivileged processes restrict themselves: filesystem rules, and TCP port rules from ABI v4Application self-sandboxing
Yama, LoadPin, SafeSetID, IPEMinorTargeted restrictions (ptrace scope, module loading source, UID transitions, integrity policy)Host hardening layers

The kernel's LSM index states that at most one major module is active alongside the minor ones, so a host is effectively either an SELinux host or an AppArmor host. Landlock is different in kind: it lets any process, including an unprivileged one, add sandbox layers that can only be tightened, never removed, up to 16 layers.

SELinux and AppArmor compared

AspectSELinuxAppArmor
Decision basisSecurity context labels stored on files (extended attributes) and assigned to processesProfiles attached to programs; rules mostly expressed as paths
Default coverageTargeted policy confines many system services; everything has a labelOnly programs with a loaded profile are confined
Learning modePermissive (global or per domain)Complain (per profile)
Key toolsgetenforce, semanage, audit2whyaa-status, aa-complain, aa-enforce, aa-genprof, aa-logprof, apparmor_parser -r
Denial evidenceAVC records in the audit logKernel log entries with apparmor="DENIED", operation, profile, name, pid and comm
ContainersContainer type plus unique MCS categories per containerdocker-default or containerd default profile, or custom Localhost profiles
Learning curveSteeper; labelling must stay correct after restores and movesGentler; profiles read like allow lists

AppArmor in more depth

On Ubuntu, AppArmor is installed and loaded by default and aa-status shows which profiles are in enforce or complain mode. Profiles live in /etc/apparmor.d/, named after the executable path with slashes replaced by dots (/bin/ping becomes bin.ping), and shared rules come from abstractions such as abstractions/base. Disabling a profile is done by linking it into /etc/apparmor.d/disable/ and unloading it, which makes it easy to audit: list that directory. Ubuntu's documentation notes that explicit deny rules are not logged, so a quiet log does not prove nothing is being blocked.

The kernel documentation is blunt about the default state: AppArmor enforces nothing beyond normal Linux permissions until policy is loaded from user space, and tasks without a profile run unconfined. Coverage, not strength, is therefore the main AppArmor metric.

What a good profile or policy looks like

  • Least privilege by path or type: the service can read its own configuration and libraries, write only its data and log directories, and nothing in home directories, /root or credential stores.
  • No shell or interpreter execution unless the service genuinely spawns one; an unexpected exec of /bin/sh is the most common sign of exploitation.
  • Network limited to what the service needs: a database client does not need raw sockets or to listen on ports.
  • Capabilities trimmed: profiles can deny Linux capabilities such as sys_admin or sys_ptrace even if the process holds them.
  • Abstractions reviewed, not trusted blindly: shared includes are convenient but can grant more than one service needs.
  • Policy as code: profiles and SELinux modules live in version control, pass review, and deploy through the same pipeline as the service, so a change in behaviour and its policy change ship together.

Test each new or changed profile against the service's full lifecycle, not just normal requests: start-up, log rotation, certificate renewal, backups and upgrades are where denials appear first.

Choosing a MAC approach

  • Follow the distribution: run SELinux on RHEL, Fedora and derivatives and AppArmor on Ubuntu, Debian and SUSE. Vendor policies, package scripts and support cases assume the default.
  • Need multi-level or category separation: SELinux MLS/MCS gives label-based separation between tenants and containers that AppArmor's program-centred profiles do not model.
  • Small team, mostly third-party services: AppArmor profiles shipped by packages plus complain-mode learning for your own daemons is the lower-effort path.
  • Your own application wants to drop privileges: use Landlock (and seccomp) inside the application regardless of the host MAC; it needs no root and stacks on top.
  • Mixed estate: standardise on metrics (coverage, unconfined count, denial review) rather than forcing one module everywhere.

Small versus large organisations: a small team gets most of the value by keeping the distribution default enforcing, never disabling it, and confining its two or three internet-facing services. A large estate needs a policy owner, a profile pipeline, an exception register with expiry dates, and confinement coverage reported per platform alongside patch compliance.

MAC for containers and Kubernetes

Containers share the host kernel, so MAC is one of the few controls that still applies after a process breaks out of its namespace view (MITRE ATT&CK T1611 Escape to Host).

  • Docker: Docker generates a profile called docker-default from a built-in template, loads it into the kernel and applies it to containers unless --security-opt apparmor= names another. Docker describes it as moderately protective with wide compatibility, so high-risk workloads deserve a custom profile.
  • Kubernetes AppArmor: stable since Kubernetes 1.31 and set with securityContext.appArmorProfile.type: RuntimeDefault, Localhost (with localhostProfile) or Unconfined. Before v1.30 annotations were used. The kubelet rejects a pod whose profile is not loaded, and Kubernetes has no built-in mechanism to load profiles onto nodes, so use node configuration management or the Kubernetes Security Profiles Operator.
  • Kubernetes SELinux: seLinuxOptions sets the user, role, type and level (for example level: "s0:c123,c456"). Volume relabelling now uses a mount option by default where eligible; seLinuxChangePolicy: Recursive opts out for volumes shared by pods with different labels, such as a privileged spc_t pod and an unprivileged one. The Kubernetes documentation records SELinuxChangePolicy as GA in 1.36 and SELinuxMount as GA and enabled by default in 1.37, and recommends enabling the SELinuxWarningController and checking the selinux_warning_controller_selinux_volume_conflict metric before upgrading.
  • Pod Security Standards: the Baseline profile expects the RuntimeDefault AppArmor profile to apply on supported hosts and forbids overriding or disabling it (or limits overrides to an allowed set). It restricts the SELinux type and forbids custom SELinux user or role. Enforce Baseline or Restricted with Pod Security Admission so developers cannot simply set Unconfined.

See the Kubernetes Security Guide and the Container Security Guide.

Rolling out mandatory access control

  1. Confirm the module is active: read /sys/kernel/security/lsm on every image, and for AppArmor /sys/module/apparmor/parameters/enabled. Fail the build if MAC is missing.
  2. Inventory confinement: list unconfined processes (AppArmor aa-status, SELinux processes in unconfined domains) and rank by exposure: internet-facing first, then services holding credentials.
  3. Learn before enforcing: put new profiles in complain mode, or a single SELinux domain in permissive mode, on a pilot ring. Exercise the service with real traffic and its maintenance jobs, then refine with aa-logprof or the SELinux tooling.
  4. Enforce by ring: move pilot hosts to enforce, then wider rings. Keep the change in configuration management so it is reviewable.
  5. Rollback plan: switch one profile to complain or one domain to permissive; never disable MAC host-wide as a fix. Record every rollback as an exception with an expiry.
  6. Bring workloads in: require RuntimeDefault at minimum for every pod through Pod Security Admission, then build Localhost profiles for high-risk workloads.

Detection and measurement

MAC is also a detection source. A denial on a production service is either a policy bug or someone trying something the service never does, and both need a ticket. Forward AVC records and AppArmor DENIED entries to the SIEM and alert on:

  • Mode changes: setenforce 0, profiles moved to complain or into the disable directory, or MAC disabled on the kernel command line. Map these to ATT&CK T1685 Disable or Modify Tools.
  • Denials from internet-facing services: especially attempts to execute shells, read credential files or open unexpected sockets.
  • Pods admitted as Unconfined or privileged: from Kubernetes audit logs.
MetricTargetSource
Hosts with MAC enforcing100% of production imagesConfiguration scan of /sys/kernel/security/lsm and mode
Internet-facing services confined100%aa-status or SELinux domain inventory
Pods running Unconfined or privilegedZero outside approved exceptionsAdmission and audit logs
Open complain or permissive exceptions past expiryZeroException register
Median time to triage a production denialUnder one working daySIEM tickets

Where identity fits

Many of the files MAC should protect are machine credentials: service account tokens mounted into pods, cloud credentials in home directories, SSH host keys, TLS private keys and secrets agent sockets. Writing profiles that deny a web server read access to those paths limits what a code execution bug can steal. In Kubernetes, MAC does not stop a compromised container using its own projected service account token, so pair it with minimal service account permissions. See the Kubernetes Secrets Security Guide.

Framework mapping

FrameworkReferenceRelevance
NIST SP 800-53 Rev. 5AC-3(3) Mandatory Access Control; AC-25 Reference MonitorThe control itself and its enforcement mechanism
NIST SP 800-53 Rev. 5SC-39 Process Isolation; CM-7 Least FunctionalityConfining services and containers
NIST SP 800-53 Rev. 5AU-6, SI-4Reviewing and monitoring denials
NIST CSF 2.0PR.PS-01; DE.CM-09Configuration management and runtime monitoring
MITRE ATT&CKT1611 Escape to Host; T1068 Exploitation for Privilege Escalation; T1685 Disable or Modify ToolsTechniques MAC constrains or that target MAC

Common failure patterns

  • Disabling MAC to fix an outage: one host goes permissive "temporarily" and the image is cloned. Fix the profile or label instead.
  • Coverage assumed, not measured: AppArmor is "on" but the service that matters has no profile and runs unconfined.
  • Privileged and Unconfined pods: a single privileged DaemonSet removes MAC from the most exposed workloads; Docker notes privileged containers without an explicit profile run unconfined under its custom-template feature.
  • Complain mode forever: profiles stay in learning mode, logs fill up and nobody reviews them.
  • Treating confinement as full isolation: MAC limits a process, not its legitimate network routes or credentials. The OpenAI and Hugging Face AI agent breach, as reported, involved no kernel escape at all: agents used reachable internal services and harvested service account tokens and instance credentials.
  • Relabel surprises: restored files or shared volumes carry wrong SELinux labels, and teams respond by turning SELinux off rather than relabelling.

Practitioner checklist

  • Verify MAC is enabled and enforcing in every production image and fail builds that lack it.
  • Publish a confinement inventory and close gaps on internet-facing and credential-holding services first.
  • Use complain or permissive mode only on pilot rings, with an expiry for every exception.
  • Enforce Pod Security Admission at Baseline or Restricted so pods cannot opt out of RuntimeDefault.
  • Load custom AppArmor profiles onto nodes through configuration management or the Security Profiles Operator.
  • Write deny rules for credential paths and token mounts in service profiles.
  • Send AVC and AppArmor denials to the SIEM and alert on any mode change.
  • Before Kubernetes upgrades, check the SELinux volume conflict metric.
  • Use Landlock or seccomp inside your own applications as an additional layer.

Standards and references

Related NHI Mgmt Group resources: SELinux Guide · Linux Server Hardening Guide · Container Security Guide · Classic Security Models Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.