Skip to content

Lesson 11 of 13 · 10m

Audit Logs Are the Black Box Recorder

Policy levels and stages, the secrets RequestResponse trap, the high-signal verbs to alert on, and Falco for the dataplane.

The recorder only works if you turn it on

Every breach writeup ends with a forensic timeline — and every cluster without an audit log produces the same timeline: nothing. The API server's audit log is the cluster's black box recorder, and on most clusters it is either off or logging to a file on the API server that nobody ships anywhere.

The mechanism: --audit-policy-file points at a YAML policy; --audit-log-path (with -maxage, -maxbackup, -maxsize) writes JSON events; the webhook backend batches events to an HTTP endpoint instead. Each event records auditID, user.username (plus impersonatedUser when --as was used), verb, requestURI, sourceIPs, and responseStatus — who, what, where from, what the API server did about it.

A real event looks like:

{"verb":"create","requestURI":"/api/v1/namespaces/prod/pods/web/exec",
 "user":{"username":"ci-bot"},"impersonatedUser":{"username":"admin"},
 "sourceIPs":["10.2.4.7"],"responseStatus":{"code":201}}

impersonatedUser is the tell — ci-bot ran exec as admin. If your alerting doesn't key on that field, --as usage is invisible to you.

Policy granularity is the part people get wrong:

  • Levels: None (skip), Metadata (the envelope — user, verb, URI, status), Request (adds the request body), RequestResponse (adds the response body too).
  • Stages: RequestReceived, ResponseStarted, ResponseComplete, Panic; use omitStages to keep RequestReceived noise out.
  • Filters: per-rule users, verbs, resources, namespaces, nonResourceURLs.

The sharp edge: RequestResponse on secrets logs the response body — which contains the secret data itself. Base64 in the log is base64 anyone with log access decodes. The standard pattern logs secrets at Metadata — you see that system:serviceaccount:prod:ci listed secrets at 03:14, without the log becoming a credential store.

The verbs that mean something

A policy that earns its disk:

apiVersion: audit.k8s.io/v1
kind: Policy
rules:
  - level: Metadata
    resources: [{group: "", resources: ["secrets"]}]
  - level: Request
    verbs: ["create", "update", "patch", "delete"]
    resources:
      - {group: "", resources: ["pods/exec", "pods/portforward", "pods/ephemeralcontainers"]}
      - {group: "rbac.authorization.k8s.io", resources: ["clusterrolebindings", "clusterroles", "rolebindings", "roles"]}
      - {group: "", resources: ["serviceaccounts/token"]}
      - {group: "certificates.k8s.io", resources: ["certificatesigningrequests"]}
  - level: Metadata

Read it as an alert list. pods/exec at 3am is a shell in production — logged as verb create against the pods/exec subresource, which is why the subresource names go in resources, not verbs. A new clusterrolebinding is privilege redistribution — the persistence move in real campaigns. serviceaccounts/token mints credentials. impersonatedUser fields mean someone exercised --as. These are low-frequency, high-signal events; alert on them and the log becomes detection, not just forensics.

Runtime detection is the other half

Audit logging watches the control plane — API calls. It says nothing about what a container does after admission. Falco covers the dataplane: syscall-level rules via eBPF that fire on the behavioral signatures of compromise — an interactive shell spawned in a container, a process reading /var/run/secrets/kubernetes.io/serviceaccount/token, outbound connections to mining pools, unexpected binaries in a readOnlyRootFilesystem violation path. Falco also ships a Kubernetes-audit plugin that consumes the API server's webhook backend, folding control-plane events into the same rule engine — one alert surface for "a pod exec'd" and "a shell spawned inside a container."

One more honesty note on cost: audit logging is cheap at Metadata and heavy at RequestResponse — response bodies are the expensive stage, and on a busy cluster RequestResponse everywhere is gigabytes a day and a log-pipeline bill. That's the real reason the secrets-at-Metadata pattern exists, not just leak hygiene.

The two together split the coverage cleanly: audit answers "who asked the cluster to do what," Falco answers "what is the workload actually doing." Breaches look different in each — clusterrolebindings create in one, bash -i in a Node container in the other.

What to actually do

Write the policy file, ship the events off-node (webhook backend or a log agent — a log file on the API server is forensics that evaporates with the node), alert on the short verb list, run Falco on the dataplane. If you're setting it up after an incident, you're doing forensics on a recorder that was off.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.