Skip to main content
Security & multi-tenancyLesson 12 of 13

Audit Logs

"Who read the production database password yesterday?" To answer that, a record must be left as the request passes through. Let's follow what the Kubernetes API server's audit log records, at what level, and where it is sent for keeping. The gates a request passes inside the API server are covered first in How an API Request Gets Stored.

Applied levelNo policy
What was recordedNone
Developer AkubectlAPI serverentry for all requestsAudit logper-request recordsLog storagelong-termAudit policyrules filedb-passSecretSecurity teaminvestigationRequest
RequestWatchAppears in a later step

What you will learn

  • What one audit log entry contains
  • None vs Metadata vs Request vs RequestResponse
  • Why Secret requests must not be logged in detail
  • Why logs must be kept outside the cluster

Levels at a glance​

LevelWhat is recordedWhen to use
NoneNothingFrequent requests with no audit value
MetadataWho, when, on what, which verb, resultResources with secrets in the body, like Secrets
RequestAbove + request bodyChanges where what they tried to change matters
RequestResponseAbove + response bodyOnly where truly needed. Large storage, and secrets may be kept

Try it yourself​

kubectl get pod -n kube-system -l component=kube-apiserver -o yaml | grep audit # Is an audit policy and log path set?
sudo cat <audit-policy-file> # Rule order and level per resource
sudo grep '"resource":"secrets"' <audit-log-file> | tail -n 3 # Who read which Secret, and when
sudo grep '"resource":"secrets"' <audit-log-file> | grep -c '"level":"RequestResponse"' # Should be 0: no secret values in the log
kubectl auth can-i get secrets -n <namespace> --as=<user> # Did that user really need read access?

Check yourself

  1. An audit policy has a rule for Secrets at Metadata and, below it, a catch-all rule at RequestResponse. Which level applies to a get on a Secret?
  2. Why should Secret requests not be logged at RequestResponse?
  3. Audit records are written only to a file on the control plane node. What is the risk?

Further reading: Auditing · Using RBAC authorization