Hi Team,
I am trying to get k8 audit logs only for level “Metadata” but I am logs for level “Request” and “RequestResponse”. I tried multiple combinations to achieve the same but no luck. Also, followed K8 audit documentation but seems it’s not helpful. Although they have mentioned to pull only metadata level logs but in my case it is pulling other level logs too. Can someone please help me here.
I am using below configurations
apiVersion: audit.k8s.io/v1
kind: Policy
# Don't generate audit events for all requests in RequestReceived stage.
omitStages:
- "RequestReceived"
- "RequestResponse"
- "Request"
- "ResponseStarted"
- "ResponseComplete"
rules:
# The following requests were manually identified as high-volume and low-risk,
# so drop them.
- level: None
resources:
- group: ""
resources:
- endpoints
- services
- services/status
- pods
users:
- "system:kube-proxy"
- "system:nodes"
- "system:kube-scheduler"
- "system:apiserver"
- "system:kube-controller-manager"
- "system:authenticated"
- "system:anonymous"
- "system:serviceaccounts"
- "system:serviceaccounts:controller-xperi-k8s"
- "system:serviceaccount:controller-xperi-k8s:controller"
verbs:
- watch
- get
- list
- update
# Don't log authenticated requests to certain non-resource URL paths.
- level: None
userGroups:
- "system:kube-proxy"
- "system:nodes"
- "system:kube-scheduler"
- "system:apiserver"
- "system:kube-controller-manager"
- "system:authenticated"
- "system:anonymous"
- "system:serviceaccounts"
- "system:serviceaccounts:controller-xperi-k8s"
- "system:serviceaccount:controller-xperi-k8s:controller"
nonResourceURLs:
- "/api*" # Wildcard matching.
- "/version"
# Secrets, ConfigMap, so only log at the Metadata level.
- level: Metadata
omitStages:
- RequestReceived
resources:
- group: ""
resources:
- secrets
- configmaps
# Default level for all other requests.
- level: Metadata
omitStages:
- RequestReceived