Skip to content

Response, New York. Noah Park: Check Point Patches Actively Exploited Management Server Path Traversal. Detection, Dallas. Ava Okello: Report Finds Nearly Half of Deployed Detections Need Attention Before SOCs Can Trust Them.

SOCtember

Always First. Fast SOC News.

Kubernetes documentation, Auditing, explaining that the audit policy file is passed to kube-apiserver with the --audit-policy-file flag and that no events are logged if the flag is omitted.
Screenshot: Kubernetes documentation, Auditing, Audit policy, the Kubernetes project (fair use).

Response

Did You Know: A Kubernetes Cluster Writes No API Audit Log Until Someone Gives It an Audit Policy, and an Evicted Pod Takes Its Container Logs With It

Responders called to a Kubernetes incident usually ask two questions first: who did what through the API, and what did the compromised container print. Upstream Kubernetes answers neither by default. The API server records no audit events unless it is started with a policy file, and container logs live on the node, rotate after 10Mi, and leave with the pod when it is evicted.

Noah Park, ResponseNew York3 min read

NEW YORK - When an attacker gets into a Kubernetes cluster, the first thing an incident responder wants is the API audit trail: which identity created a pod, read a secret or opened an exec session, and when. Kubernetes can produce that record. Its documentation describes auditing as "a security-relevant, chronological set of records documenting the sequence of actions in a cluster." But the record only exists if the cluster was set up to write it. The policy that decides what gets recorded is passed to kube-apiserver with the --audit-policy-file flag, and the documentation is plain about the alternative: "If the flag is omitted, no events are logged."

Kubernetes documentation, Auditing, Log backend section listing the --audit-log-path, --audit-log-maxage, --audit-log-maxbackup and --audit-log-maxsize flags.
Screenshot: Kubernetes documentation, Auditing, Log backend, the Kubernetes project (fair use).

A policy alone is not enough either. Events have to be written to a backend, and the current implementations are log files and webhooks. For the file backend, the --audit-log-path flag sets where events go, and "Not specifying this flag disables log backend." Further flags set how many days and how many old audit log files are kept, and how large a file grows before it is rotated. The documentation also notes that auditing increases the API server's memory use.

Kubernetes documentation, Logging Architecture, explaining that the kubelet keeps one terminated container with its logs and that evicted pods take their containers and logs with them.
Screenshot: Kubernetes documentation, Logging Architecture, the Kubernetes project (fair use).

The second gap is the workload itself. Container output written to standard output and standard error is stored on the node by the container runtime, and kubectl logs reads it from there through the kubelet. The Logging Architecture page sets out the limits: "By default, if a container restarts, the kubelet keeps one terminated container with its logs. If a pod is evicted from the node, all corresponding containers are also evicted, along with their logs." kubectl logs --previous reaches back one container instance, not further. Kubernetes itself "does not provide a native storage solution for log data," so anything not shipped to a separate backend can disappear when the pod does.

Kubernetes documentation note stating that only the contents of the latest log file are available through kubectl logs, with a 40 MiB example rotated at 10 MiB.
Screenshot: Kubernetes documentation, Logging Architecture, Log rotation, the Kubernetes project (fair use).

Rotation trims what is left. The kubelet settings containerLogMaxSize and containerLogMaxFiles default to 10Mi and 5, and the documentation warns: "Only the contents of the latest log file are available through kubectl logs." Its own example is a pod that writes 40 MiB of logs with rotation at 10 MiB, where kubectl logs returns at most 10MiB.

Amazon EKS User Guide, Enable or disable control plane logs, stating that cluster control plane logs are not sent to CloudWatch Logs by default.
Screenshot: Amazon EKS User Guide, Send control plane logs to CloudWatch Logs, Amazon Web Services (fair use).

Managed services move the switch rather than remove it. On Amazon EKS, audit is one of five control plane log types (api, audit, authenticator, controllerManager and scheduler) that can be sent to CloudWatch Logs. The EKS User Guide states: "By default, cluster control plane logs aren't sent to CloudWatch Logs." Each type must be enabled individually, CloudWatch Logs charges apply, and AWS describes delivery as best effort.

For a SOC team, the checks belong before the incident. Confirm that every cluster, self-managed or managed, has API audit logging switched on with a policy that records secrets, exec and pod changes, and that the audit log is shipped off the control plane. Forward container logs to a central backend so they outlive pods and nodes. And when a suspicious pod is found, collect kubectl logs and kubectl logs --previous before anyone deletes it or the node evicts it.

About the Author

Noah Park

Noah Park covers incident response and blue-team operations for SOCtember from New York.

Related stories

Response desk