Skip to main content

Triage and Remediation

Remediation

Using Console

To remediate the misconfiguration of Load Balancers not having connection draining enabled in Global Backend Services in GCP using GCP console, follow the below steps:
  1. Login to the GCP console and navigate to the Load Balancing page.
  2. Select the Load Balancer that needs to be remediated.
  3. Click on the Edit button to edit the Load Balancer configuration.
  4. Scroll down to the Backend section and click on the Edit button next to the Global Backend Service.
  5. In the Global Backend Service configuration, scroll down to the Connection Draining section.
  6. Enable Connection Draining by checking the box next to it.
  7. Set the Drain Timeout to the desired value (in seconds) for the load balancer to wait before terminating connections.
  8. Click on the Save button to save the changes.
  9. Once the changes are saved, verify that the Load Balancer now has Connection Draining enabled for Global Backend Services.
By following these steps, you can remediate the misconfiguration of Load Balancers not having connection draining enabled in Global Backend Services in GCP using GCP console.

To remediate the misconfiguration “Load Balancers Should Have Connection Draining Enabled In Global Backend Services” for GCP using GCP CLI, follow the below steps:
  1. Open the Cloud Shell in the GCP Console.
  2. Run the following command to list all the global backend services in your project:
  3. Identify the backend service that is associated with the load balancer that needs to be updated. Note down the name of the backend service.
  4. Run the following command to enable connection draining for the identified backend service:
    Replace [BACKEND_SERVICE_NAME] with the name of the backend service identified in step 3 and [TIMEOUT_IN_SECONDS] with the time in seconds that you want to wait for existing connections to drain before terminating them. For example:
    This command sets the connection draining timeout to 300 seconds (5 minutes).
  5. Verify that connection draining is enabled for the backend service by running the following command:
    Replace [BACKEND_SERVICE_NAME] with the name of the backend service identified in step 3. The output should show “connectionDraining: true”.
With these steps, you have successfully remediated the misconfiguration “Load Balancers Should Have Connection Draining Enabled In Global Backend Services” for GCP using GCP CLI.
To remediate the misconfiguration “Load Balancers Should Have Connection Draining Enabled In Global Backend Services” for GCP using python, follow these steps:
  1. Install the google-cloud-load-balancer library using pip by running the following command:
  2. Import the necessary modules in your python script:
  3. Create a client object for the load balancer API:
  4. Get the existing global backend services:
  5. Loop through the backend services and check if connection draining is enabled. If not, enable it:
    In the above code, we are checking if the draining_timeout_sec parameter in the connection_draining field is set to 0. If it is, we create an update request to set it to 300 seconds (5 minutes).
  6. Run the python script to remediate the misconfiguration.
    Note: Replace remediate_load_balancer_connection_draining.py with the name of your python script.
By following the above steps, you should be able to remediate the misconfiguration “Load Balancers Should Have Connection Draining Enabled In Global Backend Services” for GCP using python.
This change does not force replacement of the backend service; Terraform will update it in place.Verification: terraform plan should show an in-place update to google_compute_backend_service.GLOBAL_BACKEND_SERVICE adding or changing the connection_draining.draining_timeout_sec attribute to the desired value.