Description
An audit policy applies the first rule that matches a Kubernetes API request. Rule order, API group, resource, user and verb determine what gets recorded.
Potential impact
Missing records can hide who changed a resource. The Request and RequestResponse levels can copy sensitive data into logs.
Remediation
- Use
Metadatafor sensitive resources such as Secrets, ConfigMaps and TokenReviews when you only need to know who accessed them. Review pods, deployments and administrative subresources such aspods/execindividually. - Test requests against the policy and check the audit destination. Before recording bodies, assess their contents and storage needs, limit access to logs and set a retention period.
Examples
The revised policy covers only the resources and operations it lists. Add rules for any other requests you need to record.
Before
apiVersion: audit.k8s.io/v1
kind: Policy
rules: []
An empty rules list makes the policy invalid.
After
apiVersion: audit.k8s.io/v1
kind: Policy
omitStages:
- RequestReceived
rules:
- level: Metadata
resources:
- group: ""
resources: ["secrets", "configmaps"]
- group: "authentication.k8s.io"
resources: ["tokenreviews"]
- level: Metadata
resources:
- group: ""
resources: ["pods"]
- group: "apps"
resources: ["deployments"]
- level: RequestResponse
resources:
- group: ""
resources: ["pods/exec", "pods/portforward", "pods/proxy", "services/proxy"]
The policy records metadata for resources including tokenreviews in authentication.k8s.io and deployments in apps. It records RequestResponse events for the listed exec, port-forward and proxy operations. An exec audit event does not contain a session transcript.