Cloud Monitoring Should Monitor Dropped Packets Count For
More Info:
Ensure Cloud Monitoring monitors dropped packets count for firewall.
Risk Level
Medium
Address
Performance Efficiency, Reliability, Security
Compliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Using Console
To remediate the misconfiguration of not monitoring dropped packets count for firewall in GCP using GCP console, please follow the below steps:
- Login to the GCP console.
- Select the project in which the firewall is configured.
- Navigate to the VPC Network page from the left-hand side menu.
- Click on the Firewall rules tab.
- Click on the Edit button (pencil icon) next to the firewall rule you want to modify.
- Scroll down to the Logs section and select the checkbox for "Log dropped packets."
- Click on the Save button to save the changes.
By enabling logging for dropped packets, you can monitor and analyze the traffic that is being blocked by your firewall. This can help you identify potential security threats and take appropriate actions to mitigate them.
Using CLI
To remediate the misconfiguration of dropped packets count for firewall in GCP using GCP CLI, follow the below steps:
-
Open the GCP Cloud Shell.
-
Run the following command to list all the firewall rules in your project:
gcloud compute firewall-rules list -
Identify the firewall rule that needs to be modified.
-
Run the following command to update the firewall rule and enable logging for dropped packets:
gcloud compute firewall-rules update [FIREWALL_RULE_NAME] --enable-logging --log-config="metadata:include-all-scopes=true"Replace
[FIREWALL_RULE_NAME]with the name of the firewall rule that needs to be modified. -
Verify that the logging is enabled for the firewall rule by running the following command:
gcloud compute firewall-rules describe [FIREWALL_RULE_NAME]Replace
[FIREWALL_RULE_NAME]with the name of the firewall rule that was modified. -
Check the logs in the Logging section of the GCP Console to ensure that the dropped packets count is being monitored.
By following these steps, you can remediate the misconfiguration of dropped packets count for firewall in GCP using GCP CLI.
Using Python
To remediate the misconfiguration of not monitoring the dropped packet count for Firewall in GCP using Python, follow the below steps:
-
Install the required libraries:
pip install google-cloud-monitoring google-auth google-auth-oauthlib google-auth-httplib2 -
Authenticate with GCP:
from google.oauth2 import service_accountcredentials = service_account.Credentials.from_service_account_file('<path_to_service_account_file>') -
Import the necessary libraries:
from google.cloud import monitoring_v3from google.api_core.exceptions import AlreadyExists -
Set the project ID and the client:
project_id = '<your_project_id>'client = monitoring_v3.MetricServiceClient(credentials=credentials) -
Define the metric descriptor:
descriptor = monitoring_v3.types.MetricDescriptor()descriptor.type = 'custom.googleapis.com/firewall/dropped_packets'descriptor.metric_kind = monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGEdescriptor.value_type = monitoring_v3.enums.MetricDescriptor.ValueType.INT64descriptor.description = 'Dropped Packets Count for Firewall'descriptor.unit = '1' -
Create the metric descriptor:
try:client.create_metric_descriptor(project_id, descriptor)except AlreadyExists:pass -
Define the time series data:
series = monitoring_v3.types.TimeSeries()series.metric.type = 'custom.googleapis.com/firewall/dropped_packets'series.resource.type = 'global'series.resource.labels['project_id'] = project_idseries.points.add(value=10) -
Write the time series data:
client.create_time_series(project_id, [series])
With these steps, the misconfiguration of not monitoring the dropped packet count for Firewall in GCP can be remediated using Python.
Using Terraform
resource "google_monitoring_alert_policy" "firewall_dropped_packets" {
project = "GCP_PROJECT_ID" # Replace with your project ID
display_name = "Firewall dropped packets alert"
combiner = "OR"
conditions {
display_name = "Firewall dropped packets count too high"
condition_threshold {
filter = "metric.type=\"compute.googleapis.com/firewall/dropped_packets_count\""
comparison = "COMPARISON_GT"
threshold_value = DROPPED_PACKETS_THRESHOLD # Replace with a numeric threshold (e.g., 0 or 100)
duration = "60s" # How long the condition must hold before alerting
trigger {
count = 1
}
aggregations {
alignment_period = "60s"
per_series_aligner = "ALIGN_DELTA"
cross_series_reducer = "REDUCE_SUM"
group_by_fields = ["metric.label.\"firewall_name\""]
}
}
}
notification_channels = [
"NOTIFICATION_CHANNEL_ID_1", # Replace with existing google_monitoring_notification_channel IDs
"NOTIFICATION_CHANNEL_ID_2"
]
user_labels = {
environment = "ENVIRONMENT_TAG" # e.g., "prod"
}
}
This does not force replacement of other resources; only this alert policy will be created/updated.
Verification with terraform plan should show a new google_monitoring_alert_policy.firewall_dropped_packets to be created (or updated) with metric.type = "compute.googleapis.com/firewall/dropped_packets_count" and the configured threshold_value.