homek8s/infrastructure/controlplane/audit/audit-policy.yaml
Lance Walters f9d2594fe9 controlplane: enable kube-apiserver audit logging (audit F1)
The apiserver ran with no --audit-* flags at all: secret reads, pods/exec,
RBAC writes and serviceaccounts/token minting left no record anywhere.

- /etc/kubernetes/audit/audit-policy.yaml: RequestResponse for secrets
  get/write, pods/exec|attach|portforward, serviceaccounts/token, rbac.*,
  certificates.*, impersonate; Metadata for list/watch/update of secrets and
  for everything else (that split is what keeps 22.8 GB/day down to 2.5).
- static-pod flags: --audit-policy-file, --audit-log-path (JSON, 100 MiB x 48,
  maxage 7, compressed) + hostPath mounts for the policy dir and the log dir.
- install-audit.sh: idempotent, byte-identical re-application after a
  kubeadm upgrade silently regenerates the manifest (Flux does not own it).
- docs/kube-apiserver-audit-logging.md: design, measured volume, sensitivity
  (the log holds secret bodies), verify commands and rollback.
2026-11-27 00:20:29 -05:00

127 lines
4.7 KiB
YAML

apiVersion: audit.k8s.io/v1
kind: Policy
# One record per request instead of two (RequestReceived + ResponseComplete).
# The completion record carries responseStatus and is the forensic one.
omitStages:
- RequestReceived
# server-managed noise, never evidence
omitManagedFields: true
# Volume note (measured 2026-11-27 on this cluster): full bodies for EVERY secret
# verb cost 22.8 GB/day, because (a) flux helm-controller lists all secrets
# (1.9 MiB per list) and (b) it rewrites sh.helm.release.v1.* release blobs
# (~170 KiB each) every reconcile, plus prometheus-operator rewrites its
# tls-assets secrets. Rule 4 therefore keeps identity+object for those two
# verbs and reserves bodies for the single-object paths (rule 5) that actually
# answer "who read / who wrote this one secret".
rules:
# ---------------------------------------------------------------- 1. silence
# Liveness/version/discovery surface: polled by kubelet on every node every
# few seconds and carries no identity information.
- level: None
verbs: ["get"]
nonResourceURLs:
- /healthz
- /healthz/*
- /livez
- /livez/*
- /readyz
- /readyz/*
- /version
- /version/*
- /openapi/v2
- /openapi/v3
- /openapi/v3/*
- /metrics
# Leader election / heartbeat / event spam.
- level: None
resources:
- group: coordination.k8s.io
resources: ["leases"]
- group: ""
resources: ["events"]
- group: events.k8s.io
resources: ["events"]
# Informer watch subscriptions on high-volume, non-secret resources: recorded
# once at subscribe time and the payload never enters the record. secrets,
# RBAC and certificate objects are deliberately NOT here - a watch on those is
# itself worth a record (rules 4/6 keep it, minus the body).
- level: None
verbs: ["watch"]
resources:
- group: ""
resources: ["pods", "nodes", "services", "endpoints", "configmaps",
"persistentvolumes", "persistentvolumeclaims"]
- group: discovery.k8s.io
resources: ["endpointslices"]
- group: networking.k8s.io
resources: ["ingresses", "networkpolicies"]
- group: apiextensions.k8s.io
resources: ["customresourcedefinitions"]
- group: storage.k8s.io
resources: ["storageclasses"]
# ------------------------------- 2. secrets: bulk enumeration / automation rewrite
# user + verb + namespace/name + responseStatus, no bodies. list secrets is
# 1.9 MiB of every secret in the namespace; update is the flux helm release
# churn. Losing the body here loses only a copy of what etcd already holds.
- level: Metadata
verbs: ["list", "watch", "update"]
resources:
- group: ""
resources: ["secrets"]
# ------------------- 3. RBAC / certs enumeration: identity + request, no response
# list/watch of roles & bindings returns whole objects; the write paths are what
# matter and rule 6 keeps those at RequestResponse.
- level: Request
verbs: ["list", "watch"]
resources:
- group: rbac.authorization.k8s.io
resources: ["*"]
- group: certificates.k8s.io
resources: ["*"]
# --------------------- 4. secrets: single-object read/write, full bodies
# THIS FILE IS SECRET MATERIAL from here on: get/read responses and
# create/patch requests carry live secret values. 0600 root, never shipped
# off-node over an unauthenticated path.
- level: RequestResponse
verbs: ["get", "create", "patch", "delete", "deletecollection"]
resources:
- group: ""
resources: ["secrets"]
# -------------------------------- 5. everything privileged-but-authorized
- level: RequestResponse
resources:
- group: ""
resources:
- serviceaccounts/token
- pods/exec
- pods/attach
- pods/portforward
# every verb + subresource: create/update/patch/bind/escalate of a
# ClusterRoleBinding is a cluster takeover, not a config change
- group: rbac.authorization.k8s.io
resources: ["*"]
# CSR approval signs new client certs against the cluster CA
- group: certificates.k8s.io
resources: ["*"]
# acting as another identity
- level: RequestResponse
verbs: ["impersonate"]
# Metadata + request body only: kubelet/API proxies can return multi-MB bodies
# (metrics, pprof, logs) and the response is the volume, not the evidence.
- level: Request
resources:
- group: ""
resources: ["pods/proxy", "nodes/proxy", "nodes/log", "nodes/metrics",
"nodes/spec", "nodes/stats"]
# ------------------------------------------------------------------ 6. default
# who / what / when / from where / status code - no bodies.
- level: Metadata