Review Kubernetes audit log backup count

Choose the rotated-file count for actual log volume and retention needs.

Description

--audit-log-maxbackup limits how many rotated API server audit files stay on disk. With 0, the file count is unlimited. If you omit the flag, the API server uses its version’s default.

Potential impact

A busy cluster can cycle through its backup files before an incident is investigated.

Remediation

  • Choose a file count based on daily log volume, file size and the number of days you need. Check the age limit and available storage too.
  • After rotation, verify that you can retrieve the oldest records you need locally or from your log collector.

Examples

These v1.30.0 excerpts show one flag. File logging also needs an audit policy, --audit-log-path and a writable log volume.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: kube-apiserver
spec:
  containers:
    - name: kube-apiserver
      image: registry.k8s.io/kube-apiserver:v1.30.0
      command:
        - kube-apiserver
      args:
        - --audit-log-maxbackup=5

The API server keeps up to five rotated files.

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: kube-apiserver
spec:
  containers:
    - name: kube-apiserver
      image: registry.k8s.io/kube-apiserver:v1.30.0
      command:
        - kube-apiserver
      args:
        - --audit-log-maxbackup=10

It can now keep up to ten. How many days they cover depends on how often files rotate.

References