How to Enable Audit Logging in PMK Cluster

Problem

  • Enable Audit Logging in PMK Cluster.

The procedures are different depending upon the PMK version and Platform9 Kube versions. Identify the version and follow the procedure the accordingly.

Environment

  • Platform9 Managed Kubernetes v5.5 & Platform9 Kube Version 1.21.3-pmk.183 and Higher
  • Platform9 Edge Cloud v5.3 LTS Patch #12 v-5.3.0-1911578 & Platform9 Kube Version 1.20.15-pmk.2100 and Higher

Procedure

  • For New Clusters, ensure that during cluster creation the API Server Flags parameter is configured with the required Audit logging capability flags.
  • For existing Clusters, the flags can be added later by contacting Platform9 Support team.
  • Platform9 Edge Cloud users who have access to their own management plane can do the same on their own as well.

If Auditing is added on existing clusters, for the changes to be applied, a full stack restart will have to be performed on all the master nodes one after the other.

  • Ensure that the /var/opt/pf9/kube/apiserver-config/audit-policy.yaml file is populated with required resources that need to be audited on each master node part of the cluster. Also, to enable auditing for other resources and different audit levels, check the official documentation at kubernetes.io-audit .
Example audit-policy.yaml
Copy
  • Check if all the required Audit Logging Flags passed to apiServerFlags.
API Call to check Audit Logging Flags passed to apiServerFlags
Copy
Example API Call showing Audit Logging Flags passed to apiServerFlags
Copy
  • Restart the nodelet phases on all master nodes one node at a time, so that new Audit Logging Flags passed to apiServerFlags will get applied. This step is only required if the audit logging is being enabled on existing clusters.
Full PMK Stack Restart
Copy

Running the above commands will drain all pods/containers running on the node.

For multi-master clusters, ensure that the PMK stack restart is performed on one master node at a time else ETCD will lose quorum and the cluster will be unreachable.

  • Check for audit logs.
Example audit.log
Copy

If changes are made at a later point to the audit-policy.yaml, for those to get applied, full stack restart on all the master nodes will need to be performed one node at a time.

Environment

  • Platform9 Managed Kubernetes v5.5 & Platform9 Kube Version 1.21.3-pmk.111 and Below
  • Platform9 Edge Cloud v5.3 LTS Patch #11 v-5.3.0-1806225 & Platform9 Kube Version 1.20.11-pmk.2038 and Below

Note: Below instructions WONT persist post cluster upgrade.

Procedure

  • Create a file/etc/kubernetes/audit-policy.yaml with required content the all the master nodes. Also, to enable auditing for other resources and different audit levels check the document at kubernetes.io-audit
Example /etc/kubernetes/audit-policy.yaml
Copy
  • Edit /opt/pf9/pf9-kube/conf/masterconfig/base/<centos/ubuntu>/master.yamlfile and add below content in the kube-apiserver container section on all master nodes.
Example master.yaml file showing Section with Changes
Copy
  • Edit /opt/pf9/pf9-kube/conf/masterconfig/base/<centos/ubuntu>/master.yaml file again and add below content in the volume section on all master nodes.
Example master.yaml file showing Section with Changes
Copy
  • Restart the PMK stack on all master nodes one node at a time.
Full PMK Stack Restart
Copy

Running the above commands will drain all pods/containers running on the node.

For multi-master clusters, ensure that the PMK stack restart is performed on one master node at a time else ETCD will lose quorum and the cluster will be unreachable.

  • Once the PMK stack is back up, the logs should be created in /var/log/kubernetes/audit directory.

If changes are made at a later point to the audit-policy.yaml, for those to get applied, full stack restart on all the master nodes will need to be performed one node at a time.

Additional Information

https://kubernetes.io/docs/tasks/debug-application-cluster/audit/

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard