AppArmor limits what a container can reach on the node, files, capabilities and network, even if its process runs as root. Where RBAC controls access to Kubernetes resources, AppArmor controls access to the system that runs them. This guide covers how to apply it in Kubernetes; for the Linux basics, see the Linux AppArmor guide.
AppArmor has a twin that it does not replace: seccomp filters system calls, whereas AppArmor filters resources. The two apply at the same time, and the section "Combine AppArmor and seccomp" shows how.
AppArmor belongs to the System Hardening domain of the CKS certification, which weighs 10% of the exam. Three skills are expected there and structure this guide: apply a profile through securityContext, know what RuntimeDefault covers, and tell the current syntax, valid since 1.30, from the annotations it replaces.
What you will learn
- Check that AppArmor is active on a node with
aa-enabledandaa-status - Load a profile on a node with
apparmor_parser -r -W - Apply a profile to a Pod or a container through
securityContext.appArmorProfile, choosing between theUnconfined,RuntimeDefaultandLocalhosttypes - Recognize the legacy annotation syntax, deprecated since 1.30
- Check that a profile is really applied with
/proc/1/attr/current - Combine AppArmor and seccomp, and know what
privileged: truecancels
Prerequisites
- Kubernetes 1.30+ cluster for
securityContext.appArmorProfile(the field is stable since 1.31) - Linux nodes with AppArmor enabled (
aa-enabledanswersYes) kubectlaccess with the right to create pods
The second point is not a formality, and it rules out most labs. On a cluster whose nodes are containers, such as kind or k3d, AppArmor is not available, and the kubelet does not just ignore it: it rejects the Pod.
Status: FailedReason: AppArmorMessage: Pod was rejected: Cannot enforce AppArmor: AppArmor is not enabled on the hostThe message is the same whether the requested profile is RuntimeDefault or a named profile, and it also shows up as a Warning event. If you meet it, your manifest is not the problem: the node is. This page therefore needs a virtual machine, whereas seccomp, the next lesson, can be practised on a local cluster.
AppArmor, access control profiles
AppArmor restricts a process's access to files, directories, capabilities and network calls through declarative profiles loaded into the kernel.
Check AppArmor on the nodes
AppArmor is a feature of the node's kernel, not of Kubernetes: if the module is not active, no manifest will make it appear. Always start with this check, before even writing a profile. The file /sys/kernel/security/apparmor/profiles is the most reliable source, and it is the one the kubelet reads to decide whether to accept a Pod that asks for a Localhost profile.
# On the node (via ssh or node debug)aa-enabled # answers Yes or Noaa-status # List the loaded profilesapparmor_parser -V # Version
# Available profilesls /etc/apparmor.d/cat /sys/kernel/security/apparmor/profilesOn a Debian or Ubuntu distribution, aa-enabled answers Yes out of the box. On RHEL, Rocky or AlmaLinux, the answer will be No: these distributions use SELinux, and the AppArmor profiles of this page do not carry over.
Structure of an AppArmor profile
An AppArmor profile reads line by line as a list of paths followed by permissions: r read, w write, x execute, i inherit the current profile. Anything not explicitly allowed is denied. The two deny lines of the example are therefore redundant on paper, but they make the intent readable and take precedence over a more permissive rule inherited from an #include.
#include <tunables/global>
profile k8s-app-readonly flags=(attach_disconnected) { #include <abstractions/base>
# Allow read/execute on the binary /usr/bin/myapp rix,
# Read-only on /etc /etc/** r,
# Read/write on /tmp only /tmp/** rw,
# Forbid all network access deny network,
# Forbid ptrace (blocks introspection tools) deny ptrace,}Load a profile on the node
Kubernetes never loads an AppArmor profile for you: it only asks the runtime to apply a profile that is already present in the node's kernel. This step must therefore be repeated on every eligible node, and replayed after each reboot unless you dropped the file in /etc/apparmor.d/ (in that case, the apparmor service reloads it at startup).
# -r replaces the profile if it is already loaded, -W updates the cachesudo apparmor_parser -r -W /etc/apparmor.d/k8s-app-readonly
# Check that it is loadedsudo aa-status | grep k8s-app-readonlyA profile loads in enforce mode by default. To load it in observation mode, add flags=(complain) to its declaration or pass -C to apparmor_parser.
Apply AppArmor to a Pod, current syntax (v1.30+)
Since Kubernetes 1.30, AppArmor is configured through securityContext.appArmorProfile:
apiVersion: v1kind: Podmetadata: name: app-apparmorspec: securityContext: appArmorProfile: type: Localhost localhostProfile: k8s-app-readonly # Name of the profile loaded on the node containers: - name: app image: nginx:1.31-alpine@sha256:72ba65eb42c10344912a84ff42408db7d34f2feb642204570ab8fc5ffd29f1d3 securityContext: appArmorProfile: # Can be overridden per container type: RuntimeDefault # Use the runtime's default profileThe three types available for appArmorProfile.type:
| Type | Meaning |
|---|---|
Unconfined | No AppArmor profile (not recommended) |
RuntimeDefault | The runtime's default profile (its name varies with the runtime) |
Localhost | A specific profile loaded on the node |
The exact name of the RuntimeDefault profile depends on the runtime installed on the node. With containerd, the Kubernetes documentation shows cri-containerd.apparmor.d in the output of /proc/1/attr/current; docker-default is the historical name on the Docker side. Never hard-code this name in a manifest: ask for RuntimeDefault and let the runtime resolve it.
Pod vs container priority
AppArmor and seccomp can be set at Pod level and at container level. The container field always wins:
| Mechanism | Pod level | Container level | Priority |
|---|---|---|---|
| Seccomp | spec.securityContext.seccompProfile | spec.containers[].securityContext.seccompProfile | Container > Pod |
| AppArmor | spec.securityContext.appArmorProfile | spec.containers[].securityContext.appArmorProfile | Container > Pod |
This lets you apply a default profile to the Pod and override it for a specific container (init container, sidecar).
Legacy syntax, annotations (before v1.30)
You will still meet this syntax in existing repositories and in exam questions. Two differences matter: the annotation goes on the Pod metadata and not in securityContext, and it explicitly names the targeted container in its key, which rules out any declaration at the level of the whole Pod.
apiVersion: v1kind: Podmetadata: name: app-apparmor-legacy annotations: # Format: container.apparmor.security.beta.kubernetes.io/<container-name> container.apparmor.security.beta.kubernetes.io/app: localhost/k8s-app-readonly # Other possible values: runtime/default or unconfinedspec: containers: - name: app image: nginx:1.31-alpine@sha256:4a73073bd557c65b759505da037898b61f1be6cbcc3c2c3aeac22d2a470c1752The container.apparmor.security.beta.kubernetes.io/ annotation has been deprecated since v1.30 and will be removed in a future version. On new clusters, use securityContext.appArmorProfile. You will still come across it in older manifests: know how to read it and convert it.
Setting both forms on the same Pod is not a transition solution. If their values differ, the API server rejects the Pod at creation (apparmor type in annotation and field must match), and neither one takes precedence. If they are identical, the Pod is accepted. To migrate, replace the annotation with the field instead of keeping both.
Combine AppArmor and seccomp
The two are complementary mechanisms, they apply at the same time, and that is how they are set in production. The manifest below declares both, plus the three settings of securityContext that always go with them:
apiVersion: v1kind: Podmetadata: name: pod-hardenedspec: securityContext: seccompProfile: type: RuntimeDefault # Seccomp: filter the syscalls runAsNonRoot: true runAsUser: 1000 containers: - name: app image: nginx:1.31-alpine@sha256:4a73073bd557c65b759505da037898b61f1be6cbcc3c2c3aeac22d2a470c1752 securityContext: appArmorProfile: type: RuntimeDefault # AppArmor: restrict file/network access allowPrivilegeEscalation: false readOnlyRootFilesystem: true capabilities: drop: ["ALL"]This Pod applies defense in depth. Each line covers a different surface, and none replaces the others:
- Seccomp
RuntimeDefault: about 44 dangerous syscalls blocked out of more than 300 - AppArmor
RuntimeDefault: the runtime's profile (cri-containerd.apparmor.dwith containerd) capabilities: drop: ALL: zero Linux capabilitiesreadOnlyRootFilesystem: true: immutable filesystem- image referenced by digest: the executed content can no longer change under the same tag
This cancellation can be observed directly, with the same runtime as the cluster's. A normal container returns Seccomp: 2 and an AppArmor profile docker-default (enforce); the same container started with --privileged returns Seccomp: 0 and unconfined, with the default profile. No error message is emitted: the protection disappears silently.
Check that the profiles are applied
Never rely on the manifest to conclude that a profile is active. The quickest command is the one documented by Kubernetes: read the attribute of the container's process 1 from the Pod itself, with no need for SSH access to the node.
# The simplest way: read the PID 1 attribute from inside the containerkubectl exec pod-hardened -- cat /proc/1/attr/current# Expected: cri-containerd.apparmor.d (enforce) or k8s-app-readonly (enforce)If the Pod has no shell, or if you are investigating a container that has already stopped, you have to go through the node:
# Check the active AppArmor profiles on a nodessh node01sudo aa-status
# Confirm a container's profile (via its PID)# 1. Find the container's PID on the nodecrictl inspect <container-id> | jq '.info.pid'# 2. Read the profilecat /proc/<pid>/attr/current
# Test that a profile really blocks (complain mode → enforce)sudo aa-complain /etc/apparmor.d/k8s-app-readonly # Logs without blockingsudo aa-enforce /etc/apparmor.d/k8s-app-readonly # Actually blocksThe suffix in parentheses is what counts: (enforce) means violations are denied, (complain) that they are usually logged without being blocked. A profile left in complain after a tuning phase gives the illusion of hardening: most forbidden accesses go through.
Two exceptions, tested on Kubernetes v1.37.2: a deny rule also applies in complain mode, without leaving any trace in the log, so complain mode does not let you spot what it blocks. And if the profile contains no signal rule, the runtime can no longer stop the container.
Enforce at scale with Pod Security Admission
The restricted profile of Pod Security Admission does not mutate Pods: it injects no profile, it rejects those that explicitly declare Unconfined. The detail of this mechanism on the seccomp side, along with the kubelet's seccompDefault setting, lives on the seccomp page.
apiVersion: v1kind: Namespacemetadata: name: production labels: pod-security.kubernetes.io/enforce: restricted pod-security.kubernetes.io/enforce-version: latest pod-security.kubernetes.io/warn: restricted pod-security.kubernetes.io/warn-version: latest pod-security.kubernetes.io/audit: restricted pod-security.kubernetes.io/audit-version: latestThe Pod Security Standards also frame AppArmor: with restricted, only RuntimeDefault and Localhost are allowed. Use Kyverno or Gatekeeper if you want to go further, for example to explicitly require a Localhost profile or to manage exceptions per namespace:
apiVersion: policies.kyverno.io/v1kind: ValidatingPolicymetadata: name: require-apparmor-profilespec: validationActions: [Deny] matchConstraints: resourceRules: - apiGroups: [""] apiVersions: ["v1"] operations: ["CREATE", "UPDATE"] resources: ["pods"] validations: - expression: >- object.spec.containers.all(c, (has(c.securityContext) && has(c.securityContext.appArmorProfile) && c.securityContext.appArmorProfile.type in ['RuntimeDefault', 'Localhost']) || (has(object.spec.securityContext) && has(object.spec.securityContext.appArmorProfile) && object.spec.securityContext.appArmorProfile.type in ['RuntimeDefault', 'Localhost']) ) message: "Every container must declare an appArmorProfile of type RuntimeDefault or Localhost."The CEL expression first tests the container's securityContext, then the Pod's: this is exactly the order of precedence that Kubernetes applies. It deliberately does not read the deprecated annotations: the policy requires the appArmorProfile field, the syntax to adopt.
Troubleshooting
The first two rows of this table describe the same oversight seen from two different places: the profile is not loaded on the node where the Pod was placed. Always check the landing node (kubectl get pod -o wide) and not a random node, because a heterogeneous cluster may have the profile on only part of the fleet.
| Symptom | Likely cause | Fix |
|---|---|---|
Pod stays Pending | AppArmor profile does not exist on the node | aa-status on the node, check the profile name |
Error: failed to create containerd task | Profile not loaded | apparmor_parser -r /etc/apparmor.d/<profile> |
| Application denied with no clear message | Profile too strict, or a deny rule (it also blocks in complain mode, without a trace in the log) | Switch the profile to complain mode, read dmesg | grep -i apparmor and journalctl -k; if the denial persists without a trace, look for a deny rule in the profile |
| The container no longer stops when Kubernetes asks it to | The profile contains no signal rule: the runtime can no longer send it a signal | Add a signal rule to the profile, then reload it with apparmor_parser -r |
| Pod rejected with "apparmor type in annotation and field must match" | Deprecated annotation and securityContext.appArmorProfile set together with different values | At creation, the API server requires both to be identical: remove the annotation and keep only the field |
aa-enabled returns no | AppArmor not enabled in the kernel | Check GRUB_CMDLINE_LINUX="apparmor=1 security=apparmor" |
Limitations
These five points explain why AppArmor is rarely deployed everywhere in a real cluster. Points 1, 2 and 4 come from the infrastructure: the node's system, its runtime and the access you are given. Points 3 and 5 come from your own profiles and manifests. Remember the third above all: as soon as you leave RuntimeDefault, you add a profile to maintain on every node, and this operational debt often costs more than the security gain it brings.
- Linux only: AppArmor does not work on Windows nodes, nor on a node whose kernel does not enable it
- Runtime support: the
RuntimeDefaultprofile depends on the node's containerd or CRI-O implementation - Named profile = manual distribution: it must be loaded on every node where the Pod can be scheduled, which is expensive in a heterogeneous cluster
- Managed environments (EKS, GKE, AKS): access to the nodes to load a profile is often limited or impossible
privileged: truecancels the default hardening: with containerd, theRuntimeDefaultprofile is not applied and seccomp is disabled
Key takeaways
- AppArmor controls access to files, capabilities and network through named profiles
- The node must enable AppArmor: otherwise the kubelet rejects the Pod, it does not run it unprotected
- The container level wins over the Pod level
- Since Kubernetes 1.30: use
securityContext.appArmorProfile, the annotations are deprecated, the field is stable since 1.31 - The profile must be loaded on every node where the Pod can run
- Only the
(enforce)suffix protects;(complain)logs and lets through everything exceptdenyrules privileged: truecancels the default profiles without any message- Seccomp is complementary, not an alternative: apply them together
Knowledge check
The questions cover what really discriminates on the CKS exam: the appArmorProfile field versus the annotations it replaces, the priority between Pod level and container level, and what happens to a Pod when the profile is not loaded on the node. A missed answer points to the section to reread.
Knowledge check
Check what you have learned with this interactive quiz
How it works
- The timer starts when you click Start
- Multiple choice, true/false and short answer questions
- You can move between questions
- Detailed results are shown at the end
Starts the quiz and the timer
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Kubernetes Seccomp: filter a container's system calls
A new full quiz with random questions
Work again only on the questions you missed
Put it into practice
This confinement cannot be demonstrated on a cluster of containers, which shares the host's kernel: the lab runs on a virtual machine where the profile is really loaded. You load an AppArmor profile on the node, apply it to a container through the securityContext field, and prove that the confinement works by watching a forbidden write fail.