Lesson 13 of 14 · Assurance and response
Responding to a compromised workload
The first hours after runtime detection fires on a production pod: confirm, contain without destroying evidence, revoke what the workload could use, preserve forensic data, scope the blast radius and hunt for persistence, then rebuild clean and learn.
The first rule: contain, then investigate, then remove
Instinct says "kill it". But a deleted pod takes its processes, temporary files and network connections with it: the evidence of how the attacker got in and what they touched. And if they have already created a foothold elsewhere, deleting one pod changes nothing.
If a stranger is found in a classroom, the teacher doesn't wipe the whiteboard and send everyone home. She closes the door so nobody else gets in or out, calls the office, and leaves the room as it is so they can see what was touched. Then they check every other classroom.
Phase 1: confirm and declare (minutes)
- Read the alert: which pod, which rule (shell spawned, unexpected outbound connection, write to
/etc, a known miner binary), which node. - Correlate quickly: Kubernetes audit log (was there an
execby a human?), recent deploys, cloud threat detection findings. - If it is real or unclear, declare a security incident, name an incident lead, open a private channel, start a timeline. Security incidents may have legal and contractual notification duties, so involve the security and legal owners early.
Phase 2: contain without destroying evidence
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: quarantine
namespace: shop
spec:
podSelector:
matchLabels: { quarantine: "true" }
policyTypes: [ Ingress, Egress ]
- Isolate the pod: label it
quarantine=trueand remove the label its Service selects on (app-). It drops out of the endpoints; the ReplicaSet starts a clean replacement; the policy above cuts all traffic in and out. - Cordon the node so nothing new lands there; consider isolating the node too if a container escape is possible.
- Revoke credentials the workload could use, in parallel: - cloud role: restrict the role (deny policy) or revoke its active sessions; - Secrets its ServiceAccount could read or that were mounted: rotate them; - database users, API keys and tokens it held: rotate or invalidate them.
Phase 3: preserve evidence
Before anything else changes:
- Pod spec (image digest, ServiceAccount, node), events and logs from all containers.
- A snapshot of the node's disk (cloud volume snapshot) and, if your tooling supports it, a memory capture and a container checkpoint.
- Runtime detection events, audit logs, flow logs and gateway logs for the time window.
- Store evidence in a separate, write-once location with a record of who collected what and when.
Phase 4: scope the blast radius
Ask "what could this identity reach?" rather than "what did we see?":
- In the cluster:
kubectl auth can-i --listas the workload's ServiceAccount. Could it create pods, read Secrets, reach other namespaces? - In the cloud: what the attached role allows; what the audit logs show it actually did.
- Network: which services and external hosts it could reach, and what flow logs show it contacted.
- Data: which tenants' data the service processes; this drives notification decisions.
Phase 5: hunt for persistence
Look for objects created or changed around the incident window:
- ClusterRoleBindings and RoleBindings, new ServiceAccounts and token requests.
- Mutating or validating webhook configurations (a malicious webhook can inject code into every new pod).
- DaemonSets, CronJobs, Jobs, privileged pods, hostPath mounts.
- Images pushed to your registry, changes to Git or pipeline configuration, new cloud users or access keys.
Phase 6: eradicate, recover, learn
- Find and fix the entry point: a vulnerable dependency, an exposed admin endpoint, leaked credentials, a compromised build.
- Rebuild from a clean, signed image and redeploy through the normal pipeline; replace the node rather than cleaning it.
- Watch closely for recurrence.
- Hold a blameless review: timeline, what helped, what slowed you down. Turn the gaps into guard-rails: tighter ServiceAccount permissions, default-deny egress, read-only filesystems, new detection rules, a pre-written quarantine runbook.
Practise before you need it
A quarantine NetworkPolicy, evidence-collection scripts and a credential-rotation runbook written during a calm week save hours during a real incident. Run a tabletop exercise or a game day with a simulated compromise.
Try it
On a test cluster with Falco installed, run a deployment and kubectl exec a shell into it: Falco should alert. Then follow phases 2-5 against that pod: quarantine it, collect logs and spec, list its ServiceAccount's permissions, and list cluster objects created in the last hour. Time yourself.
Recap
- Contain first (relabel, quarantine policy, cordon), revoke reachable credentials, then preserve evidence.
- Scope by what the identity could reach; hunt for persistence before closing.
- Rebuild clean through the pipeline, fix the entry point, and turn lessons into guard-rails and runbooks.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.