Limits the container cannot lift
AppArmor is a Linux security module: a profile lists what a program may read, write or execute, and the kernel enforces it - even for root inside the container. Kubernetes picks the profile per pod or container:
spec:
securityContext:
appArmorProfile:
type: Localhost # RuntimeDefault = the container runtime's default profile
localhostProfile: k8s-deny-write
Localhost means "a profile already loaded on the node that runs the pod" - the kubelet does not ship it for you. Loading is done on the node:
sudo apparmor_parser -q /etc/apparmor.d/k8s-deny-write # load (or -r to replace)
sudo aa-status # what is loaded, in which mode
A small profile that refuses every write:
#include <tunables/global>
profile k8s-deny-write flags=(attach_disconnected) {
#include <abstractions/base>
file,
deny /** w,
}
If the profile is not loaded on that node, the container is not created: kubectl describe pod shows "apparmor profile not found k8s-deny-write". With it loaded, touch /tmp/x inside the container answers Permission denied. (simulator) only deny <path> w rules are evaluated, and the event reason reads CreateContainerConfigError.
Reading aa-status
learner@worker-1:~$ sudo aa-status
apparmor module is loaded.
118 profiles are loaded.
25 profiles are in enforce mode.
/usr/bin/man
...
cri-containerd.apparmor.d
k8s-deny-write
...
4 profiles are in complain mode.
...
89 profiles are in unconfined mode.
...
4 processes have profiles defined.
4 processes are in enforce mode.
/coredns (2005) cri-containerd.apparmor.d
/metrics-server (2011) cri-containerd.apparmor.d
/usr/bin/sleep (2017) k8s-deny-write
/usr/sbin/rsyslogd (612) rsyslogd
0 processes are in complain mode.
...
- The profiles: what Ubuntu 24.04 loads from /etc/apparmor.d (the 89 "unconfined" ones are AppArmor 4's user-namespace profiles for desktop apps, loaded on servers too), plus cri-containerd.apparmor.d - containerd's default, which every container gets when the pod says nothing (= RuntimeDefault) unless it is privileged - and yours.
- The processes: PID and executable per profile. A container under your profile shows up here; that line, not the pod spec, is the proof the kernel confines it. Privileged pods (kube-proxy, calico-node),
Unconfinedand the pause sandboxes have no line. - The executable is what aa-status resolves on the node: busybox's
/bin/sleepreads/usr/bin/sleep, because the same path exists on the host.sudo aa-status --jsongives the same data for a script;--enforcedonly the count. (simulator) one process per container.
In an interview: "the profile must exist on every node the pod can land on - load it with a DaemonSet or your node image, and pin the pod (nodeSelector) while you roll it out."
On the exam: domain "System hardening": load a given profile on a node and run a pod with it.