Kubernetes auditing: audit policy, API server logs, and what to alert on
How the Kubernetes audit log works (stages, levels, and the Policy), how to enable it in kube-apiserver and kind, real events for a Secret read, an exec, and an RBAC change, auditing on EKS, AKS, and GKE, shipping to a SIEM, retention, and privacy laws.
Kubernetes$ docker exec blog-lab-control-plane tail -n 1 /var/log/kubernetes/audit.log | jq▍When someone asks “who deleted this Deployment?” or “did anyone read the database Secret last night?”, there is only one reliable source for the answer: the API server’s audit log. Every action in the cluster, whether from a person with kubectl, a pipeline, or a controller, goes through the API, and kube-apiserver can record each request with who made it, from where, what it was, and what the result was. The catch is that on a self-managed cluster it is off by default.
This guide shows the configuration and real events captured on a kind cluster running Kubernetes v1.37.0 with auditing already enabled.
Stages and levels
Each request can generate events at different stages:
RequestReceived: as soon as the request arrives, before it is processed.ResponseStarted: response headers sent; only for long-running requests such aswatch.ResponseComplete: the response is finished. This is the stage you’ll query most.Panic: the server panicked while handling the request.
And each policy rule sets the level of detail:
| Level | What it records | Typical use |
|---|---|---|
None |
nothing | known noise (health checks, kube-proxy watches) |
Metadata |
user, verb, resource, time, response code | Secrets, ConfigMaps, general default |
Request |
metadata + request body | changes to resources without sensitive data |
RequestResponse |
metadata + request and response bodies | RBAC and other critical resources |
The audit policy
The policy is an audit.k8s.io/v1 file. Rules are evaluated in order and the first match decides the level. This is the lab’s actual policy:
apiVersion: audit.k8s.io/v1
kind: Policy
omitStages: ["RequestReceived"]
rules:
- level: None
users: ["system:kube-proxy"]
verbs: ["watch"]
- level: Metadata
resources:
- group: ""
resources: ["secrets", "configmaps"]
- level: RequestResponse
resources:
- group: "rbac.authorization.k8s.io"
- level: Metadata
omitStages: ["RequestReceived"]
Look at the second rule: Secrets stay at Metadata on purpose. At Request or RequestResponse, the Secret value would land in the log in base64, which means you’d be copying every password in the cluster into your SIEM. RBAC, on the other hand, goes at RequestResponse, because you want to see exactly which permissions were granted. The last rule is the Metadata catch-all.
Enabling it in kube-apiserver
The main flags:
| Flag | Purpose |
|---|---|
--audit-policy-file |
path to the policy; without it, no events are logged |
--audit-log-path |
output file (- sends to stdout) |
--audit-log-maxage |
days to keep rotated files |
--audit-log-maxbackup |
maximum number of rotated files |
--audit-log-maxsize |
size in MB before rotating |
--audit-webhook-config-file |
kubeconfig for the webhook backend (ships directly to a collector) |
I checked the lab’s kube-apiserver v1.37.0 --help: the default format is json, the rotation defaults show up as 366 days, 100 files, and 100 MB, and there is --audit-log-compress to gzip rotated files. Set all three rotation values explicitly instead of relying on the defaults. The webhook backend (--audit-webhook-config-file, with --audit-webhook-mode set to batch or blocking) sends events to an HTTP endpoint, which is useful when you don’t want to depend on a file on the control plane’s disk.
In kind, auditing is enabled with a kubeadm patch and volume mounts. This is the configuration used in the lab (the host path has been shortened):
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: blog-lab
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
apiServer:
extraArgs:
audit-log-path: /var/log/kubernetes/audit.log
audit-policy-file: /etc/kubernetes/policies/audit-policy.yaml
audit-log-maxage: "7"
extraVolumes:
- name: audit-policies
hostPath: /etc/kubernetes/policies
mountPath: /etc/kubernetes/policies
readOnly: true
pathType: DirectoryOrCreate
- name: audit-logs
hostPath: /var/log/kubernetes
mountPath: /var/log/kubernetes
readOnly: false
pathType: DirectoryOrCreate
extraMounts:
- hostPath: /path/to/audit/policy.yaml
containerPath: /etc/kubernetes/policies/audit-policy.yaml
readOnly: true
- role: worker
- role: worker
There are two layers of mounts: extraMounts brings the file from your machine into the node container, and extraVolumes brings it from the node into the kube-apiserver static pod. On a regular kubeadm cluster, you only need the second part. For more on local labs, see lightweight local Kubernetes.
Hands-on: reading a Secret and finding the event
I created and read a Secret in a test namespace and searched for the events:
kubectl create ns f-audit-en
kubectl -n f-audit-en create secret generic db-cred --from-literal=password='do-not-use-in-prod'
kubectl -n f-audit-en get secret db-cred -o name
docker exec blog-lab-control-plane grep '"namespace":"f-audit-en"' /var/log/kubernetes/audit.log \
| grep '"resource":"secrets"' \
| jq -c '{verb, user: .user.username, name: .objectRef.name, level, stage, code: .responseStatus.code}'
{"verb":"create","user":"kubernetes-admin","name":"db-cred","level":"Metadata","stage":"ResponseComplete","code":201}
{"verb":"get","user":"kubernetes-admin","name":"db-cred","level":"Metadata","stage":"ResponseComplete","code":200}
The full event for the read (trimmed):
{
"kind": "Event",
"apiVersion": "audit.k8s.io/v1",
"level": "Metadata",
"auditID": "5446366a-7977-4b77-885c-d5564981e199",
"stage": "ResponseComplete",
"requestURI": "/api/v1/namespaces/f-audit-en/secrets/db-cred",
"verb": "get",
"user": {
"username": "kubernetes-admin",
"groups": ["kubeadm:cluster-admins", "system:authenticated"]
},
"sourceIPs": ["172.18.0.1"],
"userAgent": "kubectl/v1.37.2 (darwin/arm64) kubernetes/c50e539",
"objectRef": {"resource": "secrets", "namespace": "f-audit-en", "name": "db-cred", "apiVersion": "v1"},
"responseStatus": {"code": 200},
"requestReceivedTimestamp": "2026-11-25T04:43:14.936620Z",
"annotations": {
"authorization.k8s.io/decision": "allow",
"authorization.k8s.io/reason": "RBAC: allowed by ClusterRoleBinding \"kubeadm:cluster-admins\" of ClusterRole \"cluster-admin\" to Group \"kubeadm:cluster-admins\""
}
}
Note that the Secret value does not appear, and that the annotations say which binding authorized the access, which is great for tracking down overly broad permissions.
RBAC change at RequestResponse
Next, I created a Role that reads Secrets and bound it to a ServiceAccount:
kubectl -n f-audit-en create sa reports
kubectl -n f-audit-en create role secret-reader --verb=get,list --resource=secrets
kubectl -n f-audit-en create rolebinding reports-reader --role=secret-reader --serviceaccount=f-audit-en:reports
docker exec blog-lab-control-plane grep '"namespace":"f-audit-en"' /var/log/kubernetes/audit.log \
| grep '"resource":"rolebindings"' | grep '"verb":"create"' \
| jq '{level, user: .user.username, roleRef: .requestObject.roleRef, subjects: .requestObject.subjects}'
{
"level": "RequestResponse",
"user": "kubernetes-admin",
"roleRef": {"apiGroup": "rbac.authorization.k8s.io", "kind": "Role", "name": "secret-reader"},
"subjects": [{"kind": "ServiceAccount", "name": "reports", "namespace": "f-audit-en"}]
}
At RequestResponse, the event carries the whole object: you know who got which permission. More on the model in RBAC: ClusterRoles and RoleBindings.
Three other events from the same test deserve attention. A kubectl exec showed up with objectRef.subresource: "exec", verb get, and code 101 (current kubectl uses WebSocket; older clients produce create), so filter on the subresource, not the verb. A curl with no credentials produced a system:anonymous event with code 403 and decision: forbid. And a kubectl get secrets --as=system:serviceaccount:<namespace>:reports recorded the real user in user and the impersonated one in impersonatedUser.
Managed clusters
On EKS, AKS, and GKE you don’t control the API server flags; the provider exports the audit logs. The commands below had their flags checked with --help, with no real cloud calls:
# EKS: control plane logs to CloudWatch Logs (log group /aws/eks/<cluster>/cluster)
aws eks update-cluster-config --name production \
--logging '{"clusterLogging":[{"types":["api","audit","authenticator"],"enabled":true}]}'
# AKS: diagnostic settings to a Log Analytics workspace
az monitor diagnostic-settings create --name aks-audit \
--resource <aks-cluster-id> --workspace <workspace-id> \
--logs '[{"category":"kube-audit-admin","enabled":true},{"category":"guard","enabled":true}]'
# GKE: Cloud Audit Logs (Admin Activity)
gcloud logging read 'resource.type="k8s_cluster" AND logName:"cloudaudit.googleapis.com%2Factivity"' \
--limit=10 --freshness=1d
On EKS, the valid types are api, audit, authenticator, controllerManager, and scheduler, and none is enabled by default. authenticator shows which IAM identity became which Kubernetes user. With the terraform-aws-modules/eks/aws Terraform module (21.30.2), the input is enabled_log_types (default ["audit", "api", "authenticator"]) and retention is cloudwatch_log_group_retention_in_days (default 90); I validated it with terraform validate. On AKS, the log categories change over time (kube-audit records everything, kube-audit-admin excludes reads, guard covers Entra ID and Azure RBAC); check the current docs. On GKE, Kubernetes API auditing goes into Cloud Audit Logs; Admin Activity logs are on, and Data Access logs depend on configuration. Check the current docs before relying on them.
Shipping to a SIEM
The file on the control plane’s disk is not a security record: whoever compromises the node deletes the file. Get the events off the cluster as soon as possible:
- Self-managed: a collector (Fluent Bit, Grafana Alloy, or the OpenTelemetry Collector) reading
audit.logon the control plane node, or the webhook backend pointing at the collector. - Managed: the provider’s integration with its destination (CloudWatch Logs, Log Analytics, Cloud Logging) and, from there, export to the SIEM.
The destination should be append-only for the people who operate the cluster. The collection architecture is covered in monitoring, logging, and runtime security.
What to alert on
| Detection | Event condition |
|---|---|
| Exec or attach into pods | objectRef.subresource in exec, attach; more serious in production or kube-system |
| Unexpected Secret read | objectRef.resource == "secrets", verb get/list, user not on a known list |
| RBAC change | group rbac.authorization.k8s.io, verbs create/update/patch/delete, especially bindings to cluster-admin |
| Anonymous request | user.username == "system:anonymous" on anything other than health checks |
| Impersonation | presence of impersonatedUser |
| Burst of denials | many 403s from the same user or IP in a short time |
Start with these six; they cover much of what shows up in a real incident.
Retention and sensitive data
Set retention together with your security and legal teams: audit logs are often required by internal policies and external audits. At the same time, they contain personal data: user names and emails (via OIDC), source IPs, and, at the Request and RequestResponse levels, the bodies of objects that may carry customer data. Under privacy laws such as Brazil’s LGPD or the GDPR, that calls for a defined purpose, a documented retention period, access control on the SIEM, and disposal at the end of that period. In practice: keep Secrets and ConfigMaps at Metadata, use RequestResponse only where the body is needed (RBAC), and restrict who can query the logs.
Checklist
- Audit policy with Secrets at
Metadataand RBAC atRequestResponse -
--audit-policy-file,--audit-log-path, and all three rotation flags set explicitly - In the cloud:
auditandauthenticator(EKS) or the equivalent categories enabled - Events shipped off the cluster to an append-only destination
- Alerts for exec, Secret reads, RBAC changes, and anonymous access
- Documented retention and restricted access to the logs, with privacy laws in mind
An audit log that’s turned off is the question “who did this?” with no answer: turn it on before you need it.