GCP Introduction
GCP Pricing
GCP Threats
GCP Misconfigurations
- Getting Started with GCP Audit
- CloudSql Audit
- Cloud Tasks Monitoring
- Dataflow Monitoring
- Function Monitoring
- Monitoring Compliance
- PubSubLite Monitoring
- Spanner Monitoring
- NoSQL Monitoring
- Compute Audit
- IAM Audit
- BigQuery Monitoring
- CDN Monitoring
- DNS Monitoring
- KMS Monitoring
- Kubernetes Audit
- Load Balancer Monitoring
- Log Monitoring
- Storage Audit
- Pub/Sub Monitoring
- VPC Audit
- IAM Deep Dive
GCP Threats
Load Balancer Global Urlmaps Should Accept Https Connections
More Info:
Load Balancer global url maps should be configured to block HTTP connection and allow only HTTPS connections.
Risk Level
High
Address
Security
Compliance Standards
GDPR, PCIDSS, NIST
Triage and Remediation
Remediation
To remediate the misconfiguration of Load Balancer Global Urlmaps should accept HTTPS connections in GCP, you can follow the below steps:
- Login to your GCP console and select the project where the misconfiguration exists.
- Go to the Navigation menu and select Networking -> Network services -> Load balancing.
- Select the Load balancer where the misconfiguration exists.
- Click on the Edit button at the top of the page.
- In the Edit Load Balancer page, scroll down to the Backend configuration section.
- Click on the Backend services link.
- Select the backend service where the misconfiguration exists.
- In the Backend service page, scroll down to the Backend configuration section.
- Click on the Edit button next to the backend configuration.
- In the Edit backend configuration page, scroll down to the Protocol section.
- Select the HTTPS option from the dropdown list.
- Click on the Save button to save the changes.
Once the above steps are completed, the Load Balancer Global Urlmaps will accept HTTPS connections.
To remediate the misconfiguration “Load Balancer Global Urlmaps Should Accept Https Connections” in GCP using GCP CLI, follow the below steps:
-
Open the Cloud Shell in the GCP Console.
-
Run the following command to get the list of all the URL maps in the project:
gcloud compute url-maps list
-
Identify the URL map that needs to be modified and note down its name.
-
Run the following command to update the URL map to accept HTTPS connections:
gcloud compute url-maps update [URL_MAP_NAME] --default-service [SERVICE_NAME] --ssl-certificates [SSL_CERTIFICATE_NAME]
Replace [URL_MAP_NAME] with the name of the URL map that needs to be modified, [SERVICE_NAME] with the name of the default service associated with the URL map, and [SSL_CERTIFICATE_NAME] with the name of the SSL certificate to be used for HTTPS connections.
-
After running the above command, the URL map will be updated to accept HTTPS connections. You can verify the changes by running the following command:
gcloud compute url-maps describe [URL_MAP_NAME]
This command will display the updated configuration of the URL map.
Note: Before running the above commands, make sure you have the necessary permissions to modify the URL maps in the project.
To remediate the misconfiguration of Load Balancer Global Urlmaps not accepting HTTPS connections in GCP using Python, follow the steps below:
- Import the necessary libraries:
from google.cloud import compute_v1
from google.protobuf.json_format import MessageToDict
- Authenticate to the GCP project:
compute_client = compute_v1.ComputeClient()
project = "your-project-id"
- Get the list of URL maps:
urlmaps = compute_client.url_maps().list(project=project).execute()
- Loop through the URL maps and check if HTTPS is enabled:
for urlmap in urlmaps.get("items", []):
urlmap_name = urlmap["name"]
urlmap = compute_client.url_maps().get(project=project, urlMap=urlmap_name).execute()
urlmap_dict = MessageToDict(urlmap, preserving_proto_field_name=True)
if urlmap_dict.get("hostRules"):
for host_rule in urlmap_dict["hostRules"]:
if host_rule.get("pathMatcher"):
path_matcher = host_rule["pathMatcher"]
if path_matcher.get("defaultService"):
default_service = path_matcher["defaultService"]
if default_service.startswith("https://"):
print(f"HTTPS is enabled for URL map {urlmap_name}")
else:
print(f"HTTPS is not enabled for URL map {urlmap_name}")
else:
print(f"No default service found for path matcher in URL map {urlmap_name}")
else:
print(f"No path matcher found for host rule in URL map {urlmap_name}")
else:
print(f"No host rules found in URL map {urlmap_name}")
- If HTTPS is not enabled, update the URL map to accept HTTPS connections:
urlmap_name = "your-url-map-name"
urlmap = compute_client.url_maps().get(project=project, urlMap=urlmap_name).execute()
urlmap_dict = MessageToDict(urlmap, preserving_proto_field_name=True)
if urlmap_dict.get("hostRules"):
for host_rule in urlmap_dict["hostRules"]:
if host_rule.get("pathMatcher"):
path_matcher = host_rule["pathMatcher"]
if path_matcher.get("defaultService"):
default_service = path_matcher["defaultService"]
if default_service.startswith("http://"):
path_matcher["defaultService"] = default_service.replace("http://", "https://")
urlmap_body = {"hostRules": urlmap_dict["hostRules"]}
compute_client.url_maps().patch(project=project, urlMap=urlmap_name, body=urlmap_body).execute()
print(f"HTTPS enabled for URL map {urlmap_name}")
else:
print(f"HTTPS already enabled for URL map {urlmap_name}")
else:
print(f"No default service found for path matcher in URL map {urlmap_name}")
else:
print(f"No path matcher found for host rule in URL map {urlmap_name}")
else:
print(f"No host rules found in URL map {urlmap_name}")
Note: Replace “your-project-id” and “your-url-map-name” with the actual project ID and URL map name in the code. Also, make sure you have the necessary permissions to update the URL map.