Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
To remediate missing VPC Network Logging (VPC Flow Logs) in GCP using the Console, enable flow logs on each subnet:
-
Sign in and go to VPC networks
- Go to:
https://console.cloud.google.com/ - Make sure you’re in the correct project.
- In the left menu, go to VPC network → VPC networks.
- Go to:
-
Select the VPC network
- Click the name of the VPC network where you want logging enabled.
- You’ll see a list of Subnets for that VPC.
-
Edit each subnet to enable flow logs
- For each subnet that should have logging:
- Click the three dots (⋮) at the end of the subnet row and choose Edit subnet (or click the subnet name, then click Edit).
- Find the Flow logs setting.
- Set Flow logs to On.
- (Optional but recommended) Configure:
- Aggregation interval (e.g., 5 min for more detail, or 30 min for less cost).
- Sampling (e.g., 0.5 or 1.0 for security-focused environments).
- Metadata (e.g., “Include all metadata” for richer logs; adjust if you have privacy or cost constraints).
- Filter (e.g., “All” for all traffic, or more restrictive if you have a specific policy).
- For each subnet that should have logging:
-
Choose the destination (if prompted)
- By default, VPC Flow Logs are exported to Cloud Logging.
- If needed, set up sinks later (Logging → Logs Router) to send logs to:
- Cloud Storage (archival),
- BigQuery (analytics),
- Pub/Sub (streaming to SIEM or other tools).
-
Save the changes
- Click Save at the bottom of the Edit subnet page.
- Repeat for every subnet that must have VPC Flow Logs enabled.
-
Verify logs are arriving
- Go to Logging → Logs Explorer.
- In the query builder, set:
- Resource type:
gce_subnetwork - Or use a simple query like:
- Resource type:
- Run the query and confirm you see new flow log entries.
Using CLI
Using CLI
Below are step‑by‑step GCP CLI instructions to enable VPC Network Logging, covering both:
Note the If blank/false, logs are not enabled.Common
Identify the rule(s) you want to log.(Optional) Log only denied or only allowed traffic:(Note: exact logging options flags may vary; in many environments
List log names that contain firewall logs:View recent VPC flow log entries:View recent firewall log entries:
If you share your
- VPC Flow Logs (subnet-level)
- Firewall Rule Logging (rule-level)
1. Prerequisites
2. Enable VPC Flow Logs on a Subnet
VPC Flow Logs are configured per subnet.2.1. List existing subnets
NAME, REGION, and NETWORK of the subnet you want to fix.2.2. Check current flow log status for a subnet
2.3. Enable flow logs for the subnet
Basic enablement (default logging config):2.4. (Optional) Tune flow log sampling & aggregation
Example: sample 0.5, aggregation interval 5 min, metadata with filter:--aggregation-interval values:INTERVAL_5_SECINTERVAL_30_SECINTERVAL_1_MININTERVAL_5_MININTERVAL_10_MININTERVAL_15_MIN
3. Enable Logging for Firewall Rules
Firewall logging is configured per firewall rule.3.1. List firewall rules
3.2. Check logging status of a firewall rule
3.3. Enable logging for a firewall rule
Log both allowed and denied traffic:--enable-logging is sufficient, and log routing is handled via Cloud Logging sinks.)4. Verify Logs Are Being Generated
4.1. In Cloud Logging (via CLI)
List log names that contain VPC flow logs:If you share your
PROJECT_ID, subnet name, and region, I can give you the exact commands filled in.Using Python
Using Python
For GCP “VPC Network Logging” you typically mean VPC Flow Logs on subnetworks (and optionally firewall rule logging). Below is how to enable VPC Flow Logs on one or more subnetworks using Python.
Run that for each region where your VPC has subnetworks.
If you tell me your exact project/region/VPC/subnet naming pattern or whether this should be part of a CI/CD script, I can tailor the code further (e.g., idempotent check, environment‑based config).
1. Prerequisites
- A GCP project and VPC subnet(s) already created.
- Permissions:
compute.subnetworks.update- Often via roles like
roles/compute.networkAdmin.
- Local setup:
- Authentication (any one):
gcloud auth application-default login(for local/dev)- Or run in a service account context with proper roles.
2. Enable VPC Flow Logs on a Subnetwork (Python)
This uses thecompute.subnetworks.patch method and sets enableFlowLogs: true.3. Enable Flow Logs on All Subnets in a VPC Network (Python)
If you want to turn on logs for every subnetwork in a given VPC network:4. (Optional) Firewall Rule Logging via Python
If your “VPC Network Logging” requirement also includes firewall rule logging:If you tell me your exact project/region/VPC/subnet naming pattern or whether this should be part of a CI/CD script, I can tailor the code further (e.g., idempotent check, environment‑based config).
Using Terraform
Using Terraform
log_config on an existing subnetwork is an in‑place update and does not force replacement of the subnetwork.For an already‑managed subnetwork, just add or adjust the log_config block in its existing google_compute_subnetwork resource.Verification: terraform plan should show an update to the google_compute_subnetwork with log_config being added or modified, and no -/+ replacement for the subnetwork.
