Skip to main content

More Info:

The audit policy should cover access to Secrets, modification of Pod and Deployment objects, and use of exec/portforward/proxy subresources. This ensures key security events are captured.

Risk Level

High

Address

Security

Compliance Standards

  • CIS Kubernetes

Triage and Remediation

Remediation

Manual Steps

  1. Locate and inspect the current audit policy
    • On every control plane node, display the policy file:
    • If the file is empty or missing, you must design and deploy an audit policy; capture that as a gap.
  2. Verify coverage of Secrets, ConfigMaps, and TokenReviews (metadata-only)
    • In the displayed YAML, look for rules with level: Metadata (or higher) that match at least these resources:
      • secrets
      • configmaps
      • tokenreviews (usually group: authentication.k8s.io)
    • Example patterns you should see in some rule(s):
    • If level is Request or RequestResponse for these resources, assess the risk of sensitive data being logged and consider reducing to Metadata where possible.
  3. Verify coverage of Pod and Deployment modifications
    • In the same file, confirm there are rules that log at least Metadata for modifications (e.g., verbs: ["create","update","patch","delete"]) on:
      • pods (group "")
      • deployments (group apps)
    • Example patterns you should see:
    • If verbs are not restricted, ensure at minimum that modification verbs are covered; you may add or refine verbs as needed for your risk tolerance.
  4. Verify coverage of exec/portforward/proxy subresources
    • Still in /etc/kubernetes/audit-policy.yaml, ensure rules exist that log at least Metadata for these subresources:
      • pods/exec
      • pods/portforward
      • pods/proxy
      • services/proxy
    • Example patterns you should see:
    • If missing, plan to add such rules; if level is lower than desired, consider raising to Metadata or higher per your logging policy.
  5. Edit and apply changes, noting operational impact
    • On every control plane node, edit the policy file with your preferred editor, adding or adjusting rules as identified in steps 2–4:
    • Confirm the API server is actually using this file (and where it is referenced) by checking its manifest (static pod):
    • If necessary, adjust the --audit-policy-file=/etc/kubernetes/audit-policy.yaml flag path to match your file location.
    • Any change to /etc/kubernetes/manifests/kube-apiserver.yaml or the audit policy file will cause the kube-apiserver static pod to restart on that control plane node.
  6. Verify the policy is active and producing expected logs
    • On every control plane node, confirm the kube-apiserver pod has restarted recently (after your changes):
    • Generate a test event (for example, reading a Secret and using kubectl exec) from any machine with kubectl access:
    • On the control plane node where audit logs are written, inspect the audit log (path may vary; common example):
    • Verify that the generated events appear at the expected log level (e.g., Metadata) and that sensitive Secret data is not logged in full. Adjust the policy and repeat as necessary.
kubectl cannot modify the audit policy file /etc/kubernetes/audit-policy.yaml or any other host-level control plane configuration; these changes must be made directly on every control plane node. Refer to the Manual Steps section for guidance on reviewing and updating the audit policy on the nodes themselves.

How to run

  1. Save the script as check-audit-policy-key-events.sh.
  2. Edit the CONTROL_PLANE_NODES array to list all your control plane node hostnames or IPs.
  3. Make it executable:
  4. Run from any machine that can SSH to all control plane nodes:

Interpreting the output

Outputs that indicate a problem and require manual review/adjustment of /etc/kubernetes/audit-policy.yaml on the affected control plane node include:
  • [PROBLEM] Policy file not found at /etc/kubernetes/audit-policy.yaml
    → No audit policy configured at the expected path.
  • [PROBLEM] No rule mentioning secrets/configmaps/tokenreviews resources
    → Access to these sensitive resources may not be logged at all.
  • [PROBLEM] Rule with level RequestBody/RequestResponse applies to secrets/configmaps/tokenreviews
    → Audit may be logging sensitive data content instead of metadata only.
  • No lines starting with [INFO] Pod/Deployment modification rule:
    → Modifications to Pods/Deployments may not be distinctly logged.
  • [PROBLEM] No rule mentioning pods/exec|pods/portforward|pods/proxy|services/proxy
    → Use of these subresources may not be logged.
  • In the summary:
    • [PROBLEM] Missing any rule referencing secrets
    • [PROBLEM] Missing any rule referencing pods
    • [PROBLEM] Missing rules for exec/portforward/proxy subresources
      → Key security concerns are not covered and the policy should be revised manually.