How does Kubernetes audit logging work?
IntermediateConceptKubernetes Security
Answer
The API server records requests according to an audit policy. Levels: None, Metadata (who, what, when), Request (plus request body), RequestResponse (plus response body). Rules are matched top-down; the first match wins.
apiVersion: audit.k8s.io/v1
kind: Policy
omitStages: ["RequestReceived"]
rules:
- level: Metadata
resources: [{ group: "", resources: ["secrets", "configmaps"] }]
- level: RequestResponse
resources: [{ group: "rbac.authorization.k8s.io" }]
- level: Metadata
Log Secrets at Metadata only, or you write secret values into logs. On EKS, enable the audit control-plane log type to send it to CloudWatch.
More on Kubernetes Security
What are the 4Cs of cloud native security?BeginnerWhat happens to a request between `kubectl apply` and etcd from a security point of view?IntermediateExplain Role, ClusterRole, RoleBinding and ClusterRoleBinding.BeginnerHow do you check what a user or service account is allowed to do?BeginnerWhich RBAC permissions are effectively cluster-admin in disguise?AdvancedHow do service account tokens work now, and what is `automountServiceAccountToken`?Intermediate