- Kubernetes auditing provides a security-relevant, chronological set of records documenting the sequence of actions in a cluster.
- The cluster audits the activities generated by users, by applications that use the Kubernetes API, and by the control plane itself.
- Capture all events for
pods
atRequestResponse
level - Capture
delete
events forsecrets
inprod namespace
atMetadata
level - Define policy at
/etc/kubernetes/audit-policy.yaml
- Log should be redirected to
/var/log/kubernetes/audit/audit.log
- Maximum days to keep the logs is
30
show
cat << EOF > /etc/kubernetes/audit-policy.yaml
apiVersion: audit.k8s.io/v1 # This is required.
kind: Policy
rules:
# Log pod changes at RequestResponse level
- level: RequestResponse
resources:
- group: ""
resources: ["pods"]
# Log secret delete events in prod namespaces at the Metadata level.
- level: Metadata
verbs: ["delete"]
resources:
- group: "" # core API group
resources: ["secrets"]
namespaces: ["prod"]
EOF
- --audit-policy-file=/etc/kubernetes/audit-policy.yaml
- --audit-log-path=/var/log/kubernetes/audit/audit.log
- --audit-log-maxage=30
volumeMounts:
- mountPath: /etc/kubernetes/audit-policy.yaml
name: audit
readOnly: true
- mountPath: /var/log/kubernetes/audit/
name: audit-log
readOnly: false
volumes:
- name: audit
hostPath:
path: /etc/kubernetes/audit-policy.yaml
type: File
- name: audit-log
hostPath:
path: /var/log/kubernetes/audit/
type: DirectoryOrCreate