Audit logging policy controller

The audit logging policy verifies whether audit logging is enabled for key services in your cluster.

Audit logging policy controller can be used to verify the compliance of audit logging policy rules for certain key services. The audit logging policy controller is enabled by default, and runs on the hub cluster or any managed cluster.

Audit logging policy

In IBM Cloud PakĀ® for Multicloud Management, each service runs as a container. The audit logging policy contains the list of containers for which audit logging compliance needs to be checked. The policy can include any service that runs in your cluster. You can configure the logging level for each service.

Following is a sample audit policy definition:

apiVersion: audit.policies.ibm.com/v1alpha1
kind: AuditPolicy # Verify if audit is enabled
metadata:
  name: iam-audit-policy-example
  label:
    category: "System-Integrity"
spec:
  severity: low
  namespaceSelector:
    include: ["default", "kube-*"]
    exclude: ["kube-public"]
  clusterAuditPolicy:
    auditPolicyRules:
      "kubernetes": ignore
      "platform-api": validate
      "helmapi": validate
      "platform-identity-manager": validate
      "platform-identity-provider": validate
      "vulnerability-advisor": validate
  remediationAction: inform # enforce or inform
  disabled: false

Note: kubernetes is the container name of the Kubernetes API server.

Audit logging policy elements

In the namespaceSelector.include section, you can specify the namespaces that the controller must watch. Use the namespaceSelector.exclude section to specify the namespaces that the controller must ignore.

In the auditPolicyRules section, you must add the container names of the services for which logging compliance must be checked. Add "<container-name>": [validate|ignore] for each container. You can set the following logging level by using the remediationAction parameter:

Note: For Kubernetes API server, the controller checks the audit-policy-file flag to verify compliance.

Creating an audit logging policy

You can create a YAML file for your audit logging policy or create an audit logging policy from the console.

Creating a YAML file for an audit logging policy

Complete the following steps to create an audit logging policy from the command-line interface (CLI):

  1. Create a YAML file with the audit logging policy definition. See Audit policy.

  2. Apply the policy by running the following command:

    kubectl apply -f <audit-logging-policy-file-name>  --namespace=<mcm_namespace>
    
  3. Verify and list the policy by running the following command:

    kubectl get <audit-logging-policy-file-name> --namespace=<mcm_namespace>
    

Create an audit logging policy from the console

  1. Log in to your cluster from the console.
  2. From the navigation menu, click Govern risk.
  3. Click Create.
  4. Edit the audit policy definition in the Create policy window. See Audit policy.

  5. Click Create.

An audit logging policy is created.

Getting the container names

To get the container names, run the following command. You need kubectl to run the command. For more information about installing kubectl, see Installing the Kubernetes CLI (kubectl).

  kubectl get pods -n <namespace> -o json | jq '.items[].spec.containers[].name' | grep -v null | sort | uniq

Following is a sample output from the kube-system namespace:

"catalog-ui"
"grafeas"
"hcm-ui"
"hcm-ui-api"
"helmapi"
"helm-repo"
"image-manager"
"platform-api"
"platform-auth-service"
"platform-header"
"platform-identity-manager"
"platform-identity-provider"
"platform-ui