Skip to main content

More Info:

Ensure Cloud Monitoring monitors SSL certificate expiry.

Risk Level

Medium

Address

Security

Compliance Standards

  • GDPR
  • HITRUST CSF
  • NIST CSF
  • Reserve Bank of India (RBI) Cyber Security Framework
  • SOC2

Triage and Remediation

Remediation

Using Console

To remediate SSL certificate expiry misconfiguration in GCP using GCP console, please follow the below steps:
  1. Open the GCP Console and navigate to the Cloud Monitoring page.
  2. Click on the “Uptime Checks” tab on the left-hand side of the page.
  3. Click on the “Create Uptime Check” button.
  4. In the “Create Uptime Check” page, provide the following details:
    • Check Type: HTTPS
    • Hostname: The hostname of the website that needs to be monitored
    • Path: The path to the SSL certificate on the website
    • Check Frequency: The frequency at which the check needs to be performed
    • Timeout: The maximum time allowed for the check to complete
    • Content Match: The content to match on the website to ensure that the SSL certificate is valid
  5. Click on the “Save” button to create the uptime check.
Once the uptime check is created, it will monitor the SSL certificate expiry and notify you if the certificate is about to expire. You can configure notification channels to receive notifications via email, SMS, or other channels.

To remediate the misconfiguration of not monitoring SSL certificate expiry in GCP using GCP CLI, you can follow the below steps:
  1. Open the Cloud Shell in the GCP Console.
  2. Run the following command to list all the SSL certificates in the project:
  3. Identify the SSL certificate that needs to be monitored for expiry.
  4. Run the following command to create a health check that monitors the SSL certificate expiry:
    Replace the placeholders with the following values:
    • [HEALTH_CHECK_NAME]: A name for the health check.
    • [PORT]: The port number of the SSL certificate.
    • [REQUEST_PATH]: The request path for the health check.
    • [CHECK_INTERVAL]: The interval at which the health check should run, in seconds.
    • [TIMEOUT]: The maximum time allowed for the health check to complete, in seconds.
    • [UNHEALTHY_THRESHOLD]: The number of consecutive failed health checks required to mark the instance as unhealthy.
    • [HEALTHY_THRESHOLD]: The number of consecutive successful health checks required to mark the instance as healthy.
    • [SSL_CERTIFICATE_NAME]: The name of the SSL certificate to be monitored.
  5. Run the following command to create an alert policy that notifies when the SSL certificate is about to expire:
    Replace the placeholders with the following values:
    • [POLICY_NAME]: A name for the alert policy.
    • [SSL_CERTIFICATE_NAME]: The name of the SSL certificate to be monitored.
    • [COMPARISON_OPERATOR]: The comparison operator for the threshold value. For example, > or <.
    • [THRESHOLD_VALUE]: The threshold value for the SSL certificate expiry time, in seconds.
    • [NOTIFICATION_CHANNELS]: A comma-separated list of notification channels to receive alerts.
  6. Verify that the alert policy is created by running the following command:
    This command lists all the alert policies in the project.
With these steps, you have successfully remediated the misconfiguration of not monitoring SSL certificate expiry in GCP using GCP CLI.
To remediate SSL certificate expiry issue for GCP using Python, follow the steps below:
  1. Install the required Python libraries:
  1. Authenticate to GCP using Application Default Credentials (ADC) by running the following command:
  1. Create a Python script to check the SSL certificate expiry date. Here’s an example:
  1. Replace the placeholders with your own values in the script:
  • Replace your-project-id with your GCP project ID.
  • Replace www.example.com and 443 with your SSL certificate’s hostname and port number.
  • Replace example.com SSL Certificate with a name for your SSL certificate.
  • Replace path/to/your/adc.json with the path to your ADC file.
  • Replace 30 with the number of days before expiration to trigger an alert.
  • Replace your-alert-policy-name with the name of your alerting policy.
  1. Save the script as a .py file and run it using the following command:
This will check the SSL certificate expiration date, create a metric descriptor for it, write the metric data to Cloud Monitoring, and trigger an alert if the SSL certificate is expiring soon.
This change does not force replacement of any existing load balancers or certificates; it only adds an alerting policy in Cloud Monitoring.To verify, terraform plan should show + create for google_monitoring_alert_policy.ssl_certificate_expiry with the metric filter loadbalancing.googleapis.com/https/certificate_expiration_age and the configured threshold_value.

Additional Reading: