How to Configure Kubernetes Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a kubernetes audit log by defining an audit policy on the API server. You also tell the API server where to write or send those recorded events. Most teams pair this log setup with role-based access control to track cluster changes. When teams grant broad roles to save time, users gain far too much power. A wide role lets someone read secrets or run commands in any pod. How a kubernetes audit log and RBAC work together Every request to a cluster passes through the API server first.

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a kubernetes audit log by defining an audit policy on the API server. You also tell the API server where to write or send those recorded events. Most teams pair this log setup with role-based access control to track cluster changes. When teams grant broad roles to save time, users gain far too much power. A wide role lets someone read secrets or run commands in any pod.

How a kubernetes audit log and RBAC work together

Every request to a cluster passes through the API server first. The API server checks who sent the request and whether their role allows it. As the request moves through stages, the API server writes entries to the kubernetes audit log. Your audit policy decides which API calls get logged and how much detail gets saved. Teams can record just the metadata or capture full request and response bodies.

Permissions in the cluster rely on roles and bindings that are purely additive. There are no deny rules in this native model. A standard role sets rules within a single namespace. A cluster role covers cluster-wide objects like nodes or spans across all namespaces. Role bindings attach these rules to users or groups within one namespace. Cluster role bindings grant those permissions across the entire cluster at once.

The API server also uses subresources to control specific actions like reading logs or entering pods. In role rules, these subresources appear with a slash after the main resource name. When an engineer runs a command inside a pod, the API server logs that request. This record helps security teams see who started an interactive session and when.

What native audit logging solves and what it misses

Native audit logging gives platform teams a strong record of API server calls. You can see who created a deployment, deleted a pod, or read a secret object. It proves that the API server checked the user role before allowing the request. For basic resource changes, the API server log tells the whole story.

Still, a large gap opens up when an engineer starts an interactive pod session. The API server logs the initial request to open the exec subresource. Once that stream opens, the user types shell commands straight into the container. The API server does not inspect or log the individual commands run inside that shell. It also does not see the standard output returned to the engineer's screen.

Audit Log Integrity + Kubernetes Audit Logs: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

The same problem happens when someone forwards a port to a database pod. The audit log records the port forward request, not the queries sent over that tunnel. Native roles decide who can open the door, not what happens inside the room. If a pod holds sensitive data like emails or card numbers, raw queries return everything. Teams need a way to inspect commands in flight and mask sensitive fields in results.

How to keep audit trails clear and useful

Start by trimming noisy read requests from your audit policy so logs stay small. Focus your policy on write actions, secret reads, and subresource calls like exec or attach. Pair your audit setup with tight, namespace-scoped roles instead of broad cluster bindings. Review your role bindings often to make sure engineers only keep permissions they need today.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev sits inline beside the API server as a sidecar for your Kubernetes API. For every production API call an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review alongside RBAC.

With hoop.dev Kubernetes controls, guardrails allow listing Secret names while refusing reads of Secret data before execution, and data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Does the kubernetes audit log capture commands typed inside a pod shell?

No, the API server only logs the initial request that opens the exec session. It does not record the shell commands or output that flow through the open stream.

Can I write a deny rule in Kubernetes RBAC to block specific audit events?

No, native permissions are purely additive and do not support deny rules. You must start with zero access and only bind the exact roles a user needs.

How does Kubernetes control who can read pod logs or run exec sessions?

The API server treats pod logs and exec sessions as subresources written with a slash. You must grant explicit permissions for those subresources inside a role or cluster role.

The query runs. The emails stay hidden.