Triage and Remediation
Remediation
Using Console
Using Console
To remediate SSL certificate expiry misconfiguration in GCP using GCP console, please follow the below steps:
- Open the GCP Console and navigate to the Cloud Monitoring page.
- Click on the “Uptime Checks” tab on the left-hand side of the page.
- Click on the “Create Uptime Check” button.
- 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
- Click on the “Save” button to create the uptime check.
Using CLI
Using CLI
To remediate the misconfiguration of not monitoring SSL certificate expiry in GCP using GCP CLI, you can follow the below steps:
- Open the Cloud Shell in the GCP Console.
-
Run the following command to list all the SSL certificates in the project:
- Identify the SSL certificate that needs to be monitored for expiry.
-
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.
-
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.
-
Verify that the alert policy is created by running the following command:
This command lists all the alert policies in the project.
Using Python
Using Python
To remediate SSL certificate expiry issue for GCP using Python, follow the steps below: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.
- Install the required Python libraries:
- Authenticate to GCP using Application Default Credentials (ADC) by running the following command:
- Create a Python script to check the SSL certificate expiry date. Here’s an example:
- Replace the placeholders with your own values in the script:
- Replace
your-project-id
with your GCP project ID. - Replace
www.example.com
and443
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.
- Save the script as a
.py
file and run it using the following command: