Skip to content
tezvyn:
Menu

Kubernetes Audit Logging: Your Cluster's Black Box Recorder

Source: kubernetes.ioHardHow cards are made

Kubernetes Audit Logging: Your Cluster's Black Box Recorder

Kubernetes audit logging is the security camera for your API server, recording every API call to answer "who did what, and when?". It's essential for security forensics and compliance, but a common footgun is using a weak default or logging everything.

Why it exists

A Kubernetes cluster is a dynamic system with many actors—users, controllers, service accounts—constantly making changes. Without a record, you can't investigate security incidents, satisfy compliance auditors, or debug why a critical application suddenly disappeared. Audit logs provide this essential, chronological record of all cluster activity.

The mental model

Think of the Kubernetes API server as the single, guarded entrance to your cluster's state. Audit logging is the security camera system installed at that entrance. It records every person (user) and robot (controller) that enters, what they were carrying (the request body), and what they did inside (the API verb like 'create', 'delete', 'patch').

How it works

You provide the kube-apiserver with an audit policy file. This policy contains rules that specify what to log. Each rule matches requests based on stages of execution, users, resources (pods, secrets), and verbs (get, delete). For each matching rule, you specify an audit level: None (ignore), Metadata (log who, when, where, but not what), Request (log metadata and the request payload), or RequestResponse (log everything). The API server then sends these generated audit events to a configured backend, typically a log file or a remote webhook endpoint.

When to use it

Always enable it in any cluster that runs meaningful workloads. It is critical for security incident response, allowing you to trace an attacker's actions. It's required for most compliance frameworks like PCI DSS, HIPAA, and SOC 2. It's also a powerful tool for debugging, helping you understand why a controller is behaving unexpectedly or what automated process is modifying a resource.

When not to use it

It's rarely a good idea to disable it completely. However, you might use a minimal policy on a short-lived, local development cluster to save resources. The more important question is what not to log. You must be selective to avoid creating a uselessly large and expensive dataset, which is a common failure mode.

One canonical example

A common and effective policy is to log all requests that modify data (create, update, delete, patch) at the RequestResponse level. For high-volume, read-only requests (get, list, watch), you might log them at the Metadata level or not at all, especially for internal system components. This strikes a balance between capturing critical changes and managing log volume. For example, you always want to know who created a Secret, but you may not need to log every time the kubelet checks a Pod's status.

Interview question

To effectively balance security forensics and log volume in Kubernetes audit logging, which policy approach is recommended?

  • a.Exclude all read-only operations (get, list, watch) from logging to drastically reduce volume.
  • b.Log data-modifying requests (create, update, delete) at a high detail level, and read-only requests at a lower detail or selectively.Correct
  • c.Restrict logging primarily to requests originating from external users, as internal system activity is less critical.
  • d.Configure all API requests to be logged at the RequestResponse level for complete visibility.
Why?

Option B directly reflects the card's advice to log data-modifying requests at a high detail level while logging high-volume, read-only requests at a Metadata level or not at all, balancing critical capture with log volume. Option D, logging everything at RequestResponse, is explicitly warned against as it creates a 'uselessly large and expensive dataset' and is a 'common failure mode'.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles