KCSA · Domain 4: Kubernetes Threat Model · 16% of the exam
Task 4.2: Persistence
How an attacker keeps a foothold: static Pods, DaemonSets, long-lived credentials, mutating webhooks and altered images.
Study it
Persistence, malicious code, attackers on the network, sensitive data and privilege escalation
Lesson coming
Sample questions
Try each one before opening the answer. Every option is explained, with the CNCF documentation page that proves it.
Question 1 · choose 1
During incident response, a team finds that every new Pod in the cluster gets an extra sidecar container that sends data to an unknown host. The attacker's own Pods were deleted and its credentials revoked, yet the injection continues for Pods of every team. Where should the team look, and which access should it then restrict?
AA DaemonSet in kube-system that patches Pods; restrict create on daemonsets
BA LimitRange that adds a default container; restrict who can edit LimitRanges
CA Pod Security exemption for the attacker's user; restrict access to the PodSecurity admission configuration
DA mutating webhook configuration the attacker added; restrict who can change webhook configurations
Show the answer and why
AA DaemonSet in kube-system that patches Pods; restrict create on daemonsets
Incorrect
A DaemonSet runs a copy of its own Pod on each node; it does not add containers to other teams' Pods as they are created.
BA LimitRange that adds a default container; restrict who can edit LimitRanges
Incorrect
A LimitRange sets default and maximum resource values for containers; it cannot add containers to a Pod.
CA Pod Security exemption for the attacker's user; restrict access to the PodSecurity admission configuration
Incorrect
An exemption only skips Pod Security checks for matching requests; it does not change the Pods that other users create.
DA mutating webhook configuration the attacker added; restrict who can change webhook configurations
Correct
Whoever controls mutating webhook configurations can read and mutate every admitted object, so a rogue webhook keeps altering new Pods after the attacker leaves; the guidance is to limit edit access to them.
Mutating admission webhooks see, and can change, every object they match before it is stored, so a webhook configuration added by an attacker is a persistence mechanism that survives the loss of its other footholds. The RBAC good practices and the webhook good practices both say to limit who can create or edit webhook configurations.
According to the Kubernetes guide to API server bypass risks, what can an attacker who can modify etcd directly do, even without any RBAC privileges?
AOnly read events, because etcd stores objects encrypted by default
BNothing, because admission control still checks every write
COnly change node labels, because other objects are signed
DRetrieve any API object or create new workloads in the cluster
Show the answer and why
AOnly read events, because etcd stores objects encrypted by default
Incorrect
etcd stores all API objects; encryption at rest is optional and covers only configured resources.
BNothing, because admission control still checks every write
Incorrect
Writes made directly to etcd never pass through the API server, so admission does not see them.
COnly change node labels, because other objects are signed
Incorrect
API objects in etcd are not signed; any of them can be changed.
DRetrieve any API object or create new workloads in the cluster
Correct
The guide says an attacker who can modify etcd can retrieve any API object or create new workloads inside the cluster, even without elevating RBAC privileges.
etcd is the API server's storage. Direct access bypasses authentication, authorization, admission and audit, so an attacker who can modify it can read everything or plant workloads that persist, which is why etcd access must be tightly restricted.
How is an ephemeral container added to a running Pod?
AThrough the ephemeralcontainers subresource, not by editing the Pod spec
BBy editing spec.containers with kubectl edit
CBy restarting the Pod with a new container image that includes the debug tools
DBy scaling the Pod's Deployment up by one replica
Show the answer and why
AThrough the ephemeralcontainers subresource, not by editing the Pod spec
Correct
The documentation says ephemeral containers are created through a special ephemeralcontainers handler in the API rather than by adding them to pod.spec, so kubectl edit cannot add one.
BBy editing spec.containers with kubectl edit
Incorrect
The documentation says it is not possible to add an ephemeral container using kubectl edit.
CBy restarting the Pod with a new container image that includes the debug tools
Incorrect
Ephemeral containers are added to the running Pod without a restart.
DBy scaling the Pod's Deployment up by one replica
Incorrect
Scaling creates another Pod; it does not add a container to the running one.
Ephemeral containers are added to an existing Pod through the pods/ephemeralcontainers subresource. Because they can run arbitrary images inside a running workload, access to that subresource deserves the same care as exec.