Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration “Ensure Stackdriver Kubernetes Logging And Monitoring Is Enabled” for GCP using GCP console, follow the below steps:
  1. Login to the GCP console with valid credentials.
  2. Navigate to the Google Kubernetes Engine (GKE) cluster for which you want to enable Stackdriver Kubernetes Logging and Monitoring.
  3. Click on the “Edit” button at the top of the page.
  4. Scroll down to the “Stackdriver” section and click on it.
  5. Under the “Stackdriver Logging” section, toggle the switch to “Enabled”.
  6. Under the “Stackdriver Monitoring” section, toggle the switch to “Enabled”.
  7. Click on the “Save” button at the bottom of the page.
Once the above steps are completed, Stackdriver Kubernetes Logging and Monitoring will be enabled for the GKE cluster. You can then view logs and metrics for your Kubernetes cluster in the Stackdriver Logging and Monitoring UI.

To remediate the misconfiguration of Stackdriver Kubernetes Logging and Monitoring not being enabled on GCP using GCP CLI, follow the below steps:
  1. Install and configure the Google Cloud SDK (CLI) on your local machine.
  2. Open the terminal or command prompt and authenticate to your GCP account using the following command:
  1. Set the default project for the CLI to the project where the Kubernetes cluster is deployed using the following command:
  1. Enable the Stackdriver Kubernetes Logging and Monitoring API for the project using the following command:
  1. Verify that the Stackdriver Kubernetes Logging and Monitoring API is enabled by running the following command:
  1. If the API is enabled, you should see the following services listed:
  1. Once the API is enabled, you can configure the Kubernetes cluster to send logs and metrics to Stackdriver by following the official GCP documentation:
https://cloud.google.com/kubernetes-engine/docs/how-to/logginghttps://cloud.google.com/monitoring/kubernetes-engine/
To remediate the misconfiguration “Ensure Stackdriver Kubernetes Logging And Monitoring Is Enabled” for GCP using Python, you can follow these steps:
  1. Install the google-cloud-monitoring and google-cloud-logging Python libraries using pip.
  1. Create a service account with the necessary permissions to enable Stackdriver Kubernetes logging and monitoring.
  2. Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of the service account key file.
  1. Use the google-cloud-monitoring and google-cloud-logging libraries to enable Stackdriver Kubernetes logging and monitoring.
Note: Replace project_id with your GCP project ID.
  1. Verify that Stackdriver Kubernetes logging and monitoring is enabled by checking the Stackdriver Metrics Explorer and Logs Viewer in the GCP Console.
That’s it! You have now remediated the misconfiguration “Ensure Stackdriver Kubernetes Logging And Monitoring Is Enabled” for GCP using Python.
Substitute:
  • GKE_CLUSTER_NAME with your cluster’s name.
  • GKE_CLUSTER_LOCATION with your cluster’s region or zone (for example, us-central1 or us-central1-a).
This change updates the existing cluster in place and does not normally force replacement; terraform plan should show an in‑place update to the google_container_cluster.GKE_CLUSTER resource with changes only to logging_config and monitoring_config.