An attacker who takes control of an application in a Kubernetes cluster often follows a path in three stages: run code in a container, gain more rights, then reach the node or the other services over the network. This lesson describes these three scenarios from the attacker's side, step by step, then matches each step with the defense that stops it. It is meant for someone who already knows the Kubernetes vocabulary and is preparing the "Kubernetes Threat Model" domain of the KCSA certification. It replays no attack: the defenses have their own lessons, linked throughout the text.
What you will learn
- Read an attack scenario as a sequence of steps, with what the attacker gains at each one.
- Describe malicious code execution in a container.
- Describe a privilege escalation from a container.
- Describe an attacker on the cluster network.
- Say for each defense whether it prevents, confines or detects, and name the first one that stops a scenario.
Prerequisites
- Know what a Pod is and read a YAML manifest.
- Know the principle of RBAC, which decides what a service account is allowed to do.
- Have followed the Trust boundaries and STRIDE lesson, which places MITRE ATT&CK next to STRIDE. The tactics used here (initial access, execution, privilege escalation) are explained along the way; to go further, the MITRE ATT&CK page (in French) details the matrix and After the intrusion (in French) describes what the attacker does once inside.
How do you read an attack scenario?
A scenario is read in four elements: the entry point, the steps, what the attacker gains at each step, and the defense that stops it. This grid avoids sorting defenses into a list: it places them on the attacker's path, where they are useful.
Each defense plays one of three roles. It prevents when it refuses the condition the attack needs, before it is even used. It confines when the attack takes place but its effects stay within a reduced perimeter. It detects when it lets the attack through but raises an alert in time to react.
The diagram shows the main path of this lesson. The thick arrows are the attacker's steps, from the compromised application to control of the node; the dotted arrows point to the defense that acts at each step.
How does an attacker run malicious code in a container?
The attacker runs code in a container through three main entries: a flaw in the application, a booby-trapped image, or a shell already open in a container they managed to reach. In all three cases, they first get the rights of the container's process, nothing more.
What this process gives them depends on the Pod configuration. It reads the environment variables and the mounted files, so the secrets the application uses. It writes to the container's filesystem if that is not read-only. It reaches the cluster network like any Pod. Finally, Kubernetes mounts a service account token in the Pod by default: the attacker can use it to call the cluster API with the rights of that account, within the limit of what RBAC grants it.
Defenses sit at three levels. A minimal image from a controlled chain reduces the entry points and the available tools: this is the subject of the Supply Chain Security lesson. A non-root process in a read-only filesystem limits what it can modify, which belongs to the Security Context. The seccomp (in French) and AppArmor (in French) profiles restrict the process's system calls and accesses: they confine. Finally, Falco watches the activity of containers and reports, for example, the opening of a shell: it detects, and does not replace a defense that prevents.
How does a privilege escalation get out of the container?
A privilege escalation starts from a compromised container and seeks more rights than the container has: those of the node, or those of a powerful API account. It is only possible if the configuration of the Pod or of the service account allowed it in advance. Each cause in the table is a setting that can be refused.
| What makes it possible | What the attacker gains | Defense that prevents it |
|---|---|---|
Privileged container (privileged: true) | Almost complete access to the node | Pod Security Standards, Baseline or Restricted level |
Shared host namespaces (hostPID, hostNetwork, hostIPC) | The view of the host's processes or network | Pod Security Standards, Baseline or Restricted level |
hostPath mount | Reading and writing files of the node | Pod Security Standards, Baseline or Restricted level |
Excess Linux capabilities, allowPrivilegeEscalation not blocked | Root powers wider than needed | securityContext: drop the capabilities and block escalation; the Restricted level of the Pod Security Standards enforces it |
| Overly powerful service account | Extensive rights on the cluster API | Minimal RBAC, and automountServiceAccountToken: false if the application does not call the API |
These settings are not equivalent. The first four rows open the way to the node: this is container escape. The last one gives access to the API, and that is another route: a perfectly isolated container remains dangerous if its service account can read all the Secrets of the cluster.
Pod Security Admission refuses these configurations when the Pod is created. It therefore prevents, before any start, but it removes nothing from Pods that are already running. For the service account, the RBAC lesson teaches granting only what is needed, and the audit logs let you spot an abnormal use of the token: they detect.
What can an attacker do on the cluster network?
In a cluster, the network is flat by default: a Pod can reach all the others. An attacker who has compromised a single Pod can therefore probe the other services and, depending on their position, listen to the traffic, modify it or impersonate a service. A call to a service that does not authenticate its clients succeeds with no extra obstacle.
Three attacker moves are worth telling apart. Eavesdropping reads the traffic that flows in clear between two Pods. Spoofing answers in place of a legitimate service, or calls a service while posing as an authorized client. The direct call exploits a service that accepts any call coming from the internal network, because it assumes that "inside the cluster" means "trusted".
Two defenses complement each other, as the Pod-to-pod mTLS lesson explains. NetworkPolicies filter flows by address and port: they confine, by reducing the number of Pods a compromised Pod can reach, but they neither encrypt nor authenticate anything, and they only apply if the cluster's network plugin implements them. mTLS encrypts each flow and checks the identity of both ends by certificate: it prevents eavesdropping and spoofing. Neither replaces the authentication that the service itself must demand.
Which defense stops which scenario?
Each defense in the course acts on a precise step, with a precise role. This table places them side by side so that the role (prevent, confine or detect) reads together with the step it handles.
| Scenario and step | Defense | Role | Lesson |
|---|---|---|---|
| Malicious code: process running in the container | securityContext (non-root, read-only filesystem) | Confines | Security Context |
| Malicious code: system calls and accesses of the process | seccomp, AppArmor | Confines | seccomp (in French), AppArmor (in French) |
| Malicious code: shell opened in the container | Falco | Detects | Falco |
Privilege escalation: privileged container, hostPath, host namespaces | Pod Security Standards | Prevents | Pod Security Standards |
| Privilege escalation: excess capabilities | securityContext, Pod Security Standards (Restricted) | Prevents | Security Context |
| Privilege escalation: overly powerful service account | Minimal RBAC, automountServiceAccountToken: false | Prevents, and the audit logs detect | RBAC, Audit logs |
| Network attacker: movement between Pods | NetworkPolicy | Confines | NetworkPolicies |
| Network attacker: eavesdropping and spoofing | mTLS | Prevents | Pod-to-pod mTLS |
How do you replay a scenario on paper?
Take this scenario: a web application has a flaw that lets an attacker run a command. The attacker opens a shell in the container, finds that the Pod is privileged and that it mounts the node's / with hostPath, then writes to the node's files. The question is to name the first defense that would have stopped the attack.
You place the defense at each step. The flaw in the application is stopped by no Kubernetes defense: only fixing the application closes it. The shell can be limited by seccomp and AppArmor, and Falco can alert when it opens. But the defense that acts first is Pod Security Admission, at the Baseline or Restricted level: it would have refused the privileged Pod's manifest, before its first start. Without that Pod, the hostPath step would not have existed.
The first defense that stops a scenario is therefore not the one closest to the attacker but the one furthest upstream in time: the one that removes the condition before it is used. The defenses that confine or detect remain useful, because they act when prevention has failed or was not in place.
Which reading mistakes should you avoid?
Four confusions come back. The first takes a defense that detects for a defense that protects: Falco alerts, but the alert alone does not stop the action. The second assumes that a NetworkPolicy encrypts the traffic or authenticates its ends: it only filters by address and port. The third believes that enabling Pod Security Admission fixes Pods that are already running: it only checks later creations. The fourth forgets the service account: a very hardened container does not protect the API if its token carries overly broad rights.
Key takeaways
- A scenario is read in steps: entry point, what the attacker gains, defense that stops it.
- A defense prevents, confines or detects: this role matters as much as its name.
- Code execution in a container first gives the rights of the process, including the service account token mounted by default.
- Privilege escalation requires a permissive configuration: privileged container,
hostPath, host namespaces, excess capabilities or an overly powerful service account. - The network of a cluster is flat by default: NetworkPolicy confines flows, mTLS encrypts and authenticates.
- The first defense that stops a scenario is the one that removes the condition earliest, often Pod Security Admission.
Knowledge check
Eight prediction and diagnosis questions: read a scenario, choose the defense that stops each step and say whether it prevents, confines or detects.
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)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: Denial of service: exhausting a cluster
A new full quiz with random questions
Work again only on the questions you missed