Home› Blog› Week 15 — A WAF Guards One Door. The Backend Has T…
GCP Weekly Lab GCP Terraform

A WAF guards one door. The backend has two.

The same request, sent two ways in the same second. One is refused with 403. The other is served with 200.

Verified against current vendor documentation on 29 November 2026. Pricing, limits and API behaviour were checked against the official docs on that date. Cloud services change fast — if you are reading this much later, treat the specifics as a starting point and re-check the linked sources.
GCP Platform Engineering Lab · Week 15 of 58

Lab Overview

A security review goes well. There is a web application firewall in front of the service, it blocks SQL injection, and someone has a screenshot of the rule. The box gets ticked. Nobody asks what else can reach the machine the firewall is protecting — and on a cloud VM with a public address, the answer is everyone.

The problem. Cloud Armor is attached to a backend service. It inspects requests that arrive through the load balancer. A request that arrives any other way is not inspected, not logged, and not refused — not because the WAF is weak, but because the WAF is not there.

The objective. Build the protected architecture properly — a global external Application Load Balancer, a Cloud Armor policy with a preconfigured SQL injection rule, Cloud CDN — then send one identical request down both paths and record what each one returns.

Expected outcome. 403 through the load balancer and 200 around it, with nothing else different. If the direct request is already failing, there is no bypass to close and the lab has measured nothing.

Deployment method. Terraform on HCP Terraform agents with no stored credentials; the workspace mints an OIDC token per run and exchanges it for a short-lived Google token. Built in Week 02.

What this gives app teams

CapabilityWho consumes itWhat it replacesWhat it costs them
A global anycast address, a cache and a WAF in front of their serviceAny team shipping an external endpointDesigning edge protection per team, and a ticket for every ruleNothing to configure — the load balancer and the policy are platform-owned
Evidence the protection cannot be walked aroundSecurity review, audit"The WAF is in front of it" on an architecture slideOne re-runnable command

Cloud Services and Concepts

ServicePurpose hereWhat it is
Global external Application Load BalancerThe guarded front doorOne anycast IP address announced from Google's edge worldwide. Requests land at the nearest Google Front End, which applies policy and then forwards to a backend. Built from four objects rather than one: a forwarding rule, a target proxy, a URL map and a backend service.
Cloud ArmorThe WAF under testA security policy of ordered rules evaluated at the Google Front End, before a request reaches your backend. Rules can match on IP ranges, or on preconfigured expressions that encode the OWASP rulesets for injection, scripting and similar attacks.
Cloud CDNCaching, and an honesty check on itA cache at Google's edge, turned on with one flag on the backend service. The cache mode decides what is eligible; the response headers are where you find out whether anything was.
Managed instance groupThe thing being protectedIdentical VMs built from one instance template, which a backend service points at as a unit. Here, one e2-micro serving a page.
Health checkMakes the backend eligible for trafficA probe from Google's infrastructure. Until it passes, the backend service has no healthy backend and the load balancer answers 502.
VPC firewall ruleThe week's one variableDecides which source ranges may reach port 80. Everything in the measurement is held constant except this.
Terraform & HCP TerraformDeclares it and applies it remotelyInfrastructure as code, run on hosted agents that authenticate per run through Workload Identity Federation, so no key is stored.

Where a WAF actually sits

Cloud Armor is not a property of a machine or of a network. It is attached to a backend service — the load balancer object naming which instance group serves traffic. Google's overview says a backend policy applies to "instance groups" or the NEG types the load balancer supports, and that Cloud Armor "also protects serverless NEGs when traffic is routed through a load balancer."

That last clause does a great deal of work and is easy to read past. Traffic routed through the load balancer is protected. Traffic reaching the backend any other way was never in scope — and a VM with an external IP address is another way.

Architecture and Workflow

Cloud Armor in front of a global external Application Load Balancer, which forwards through a firewall rule to a backend VM inside the hub VPC. A second arrow runs from anyone on the internet straight to the backend VM's own external IP, bypassing both Cloud Armor and the load balancer entirely.
Two paths to one machine. The upper one passes the WAF; the lower one does not exist on the architecture diagram anybody draws.
  1. A Cloud Armor policy is created with one preconfigured SQL injection rule at deny(403) and a default allow beneath it.
  2. A one-instance managed instance group serves a page on port 80, keeping an external IP on purpose — that address is the subject of the week.
  3. A health check and a backend service are created; the policy and Cloud CDN both attach to the backend service.
  4. A URL map, target proxy, reserved global address and forwarding rule complete the load balancer.
  5. A firewall rule allows port 80 from 0.0.0.0/0, so the second path exists to be measured before it is closed.
  6. The same attack-shaped request goes to the load balancer and to the VM's own address; both responses are recorded.
  7. The rule is narrowed to Google's load balancer and health-check ranges, both requests repeat, and the rule is widened again.

Design decisions worth stating

The backend is a VM, and that was the second choice. The pattern every example shows is Cloud Run behind a serverless network endpoint group, and an organization policy from Week 03 refuses the public binding it requires. Weakening that control to make a lab work is the wrong trade — the full story is in Troubleshooting.

One rule, at its loosest sensitivity. The policy uses a single rule ID from sqli-v33-stable rather than the whole ruleset. It matches obvious injection and leaves ordinary traffic alone, which is what makes a single curl a fair test rather than a lucky one — the normal request has to come back 200 for the blocked one to mean anything.

HTTP, not HTTPS. A managed certificate needs DNS validation on a real domain, and the only one available serves a live site. Cloud Armor's position relative to the backend is identical on either port, so the finding is unaffected — a stated gap, not an oversight.

Prerequisites

  • A project with Compute Engine enabled (Week 01).
  • Keyless CI through Workload Identity Federation (Week 02). No permissions were added this week; Week 13's grants already covered the load balancer, the policy and the instance group.
  • A VPC and a regional subnet (Week 04). This week creates no network.
  • Awareness of Week 03's org policies — they rule out the Cloud Run design, and a VM without enable-oslogin and block-project-ssh-keys cannot be created at all.

Implementation

What was deployed

WhatHow manyIts job
Cloud Armor security policy1One SQLi rule at deny(403), one default allow
Instance template + managed instance group1 + 1One e2-micro serving a page on port 80, with its own external IP
Health check1Makes the backend eligible for traffic
Firewall rule1The week's one variable — who may reach port 80 directly
Backend service1EXTERNAL_MANAGED — the global ALB rather than the classic one; the policy and the CDN both attach here
URL map, target HTTP proxy, global address, forwarding rule4The rest of the load balancer
Service enablement1compute.googleapis.com

Eleven resources.

Step 1 — The policy, before anything it protects

resource "google_compute_security_policy" "waf" {
  name = "wk15-waf"

  rule {
    action   = "deny(403)"
    priority = 1000
    match {
      expr {
        expression = "evaluatePreconfiguredExpr('sqli-v33-stable', ['owasp-crs-v030301-id942421-sqli'])"
      }
    }
  }

  rule {
    action   = "allow"
    priority = 2147483647
    match {
      versioned_expr = "SRC_IPS_V1"
      config { src_ip_ranges = ["*"] }
    }
  }
}

The second rule is the default, at the lowest possible priority. Excluding a rule ID from the preconfigured expression is how sensitivity is tuned; here it narrows the match to one obvious signature.

Step 2 — The backend service, where the policy actually attaches

resource "google_compute_backend_service" "app" {
  name                  = "wk15-backend"
  load_balancing_scheme = "EXTERNAL_MANAGED"
  security_policy       = google_compute_security_policy.waf.id

  enable_cdn = true
  cdn_policy {
    cache_mode = "CACHE_ALL_STATIC"
    cache_key_policy {
      include_host         = true
      include_protocol     = true
      include_query_string = true
    }
  }

  health_checks = [google_compute_health_check.app.id]
  port_name     = "http"

  backend {
    group          = google_compute_instance_group_manager.app.instance_group
    balancing_mode = "UTILIZATION"
  }
}

security_policy is one line on this object, and it is the entire scope of the protection.

Step 3 — Deploy it

HCP Terraform run list for the gcp-week-15 workspace, showing the applied run that created the stack along with the earlier runs that errored
Eleven resources, applied. The earlier errored runs are the Cloud Run design failing on an org policy — in Troubleshooting below.

Validation: the load balancer answers 502 for the first few minutes. That is the health check not having passed yet, not a misconfiguration. Wait for a 200 before measuring anything.

Step 4 — The WAF works on the path it guards

Terminal output showing the three measurements with the firewall open: through the load balancer the attack returns 403, a normal request returns 200, and the direct request returns 200
403 for the attack, 200 for ordinary traffic. The WAF is doing its job on the path it can see.

Validation: both numbers are needed. A policy that returned 403 to everything would also produce a 403 here and would be broken, not protective.

Step 5 — The same request, sent around it

Terminal output showing the identical SQL injection request returning 403 when sent to the load balancer address and 200 when sent to the backend VM's own external IP address
Identical request, two addresses, same second. 403 where Cloud Armor sits; 200 where it does not.

Step 6 — Is the cache caching?

Response headers from two identical requests through the load balancer, showing HTTP 200, content-type text/html and via 1.1 google, with no age header and no cache-control header on either response
No age, no cache-control. Cloud CDN is enabled on this backend service and is caching nothing — correctly.

Validation: the figure plan asked whether the cache was "on and measurable, not asserted". The answer was no, and the slot was kept rather than quietly retired.

Validation and Evidence

The experiment

One request — /?id=1' OR '1'='1 — sent three ways, with the firewall rule's source ranges as the only variable. The script aborts before changing anything unless the load balancer returns 403 and the direct request returns 200, so a broken deployment cannot be written up as a finding, and it widens the rule again in a trap on every exit path.

Terminal output after narrowing the firewall rule to Google's load balancer ranges: through the load balancer the attack still returns 403 and a normal request still returns 200, while the direct request now returns 000
One rule narrowed. Both load-balanced paths unchanged; the direct one no longer opens a connection.
TestExpected resultActual resultStatus
Attack through the load balancer, firewall open403 from Cloud Armor403Pass
Ordinary request through the load balancer200200Pass
Same attack straight to the backend200 — the bypass200Pass
Attack through the load balancer, firewall narrowed403, unchanged403Pass
Ordinary request, firewall narrowed200, unchanged200Pass
Same attack straight to the backend, firewall narrowedno connection000Pass
All three, firewall reopenedback to 403 / 200 / 200403 / 200 / 200Pass
Cloud CDN serving a cached responsean age header on the second requestno age, no cache-controlMeasured — and the answer was no

What the status codes prove. 403 is Cloud Armor refusing a request it inspected; 200 is the backend serving it; 000 is curl reporting a connection that never opened. Rows one and three are the same request in the same second, and the only difference is the address it was sent to. The raw measurement and the script's full output are committed.

Two honest limits. There is no separate resource-existence validation script this week; the measurement script carries the assertions that matter, but a reader reproducing the lab gets less than the previous week offered. And the firewall narrowing demonstrates the fix rather than being it — see Security.

Security and Cost

Security

  • The real fix is not the firewall rule. It is not giving the backend an external address in the first place. A VM behind a load balancer needs no public IP, and without one the second door does not exist to be closed. The firewall narrowing is how this lab makes the point visible and reversible; it is not the production design.
  • Narrowing to 130.211.0.0/22 and 35.191.0.0/16 is what "only reachable through the load balancer" means in practice. Those are the ranges Google Front Ends and IPv4 health checks arrive from. Without ingress rules allowing them, "the implied deny ingress firewall action blocks traffic, causing your backends to be unhealthy."
  • An organization policy refused the vendor's reference architecture, and that was the right outcome. iam.allowedPolicyMemberDomains blocked a public allUsers binding. The design changed; the control did not.
  • One rule is not a WAF configuration. Production runs the full preconfigured rulesets in preview mode first and tunes from the request logs. Nothing here consumes Cloud Armor's logs, and nothing here rate-limits.
  • No service account keys, and the VM carries enable-oslogin and block-project-ssh-keys because the organization's policies refuse to create it otherwise.

Cost

ItemRate, read 28 NovemberThis run
Global forwarding rule$0.025 / hour, first five~25 minutes
Cloud Armor policy$0.006849 / hour (~$5 / month)~25 minutes
Cloud Armor rules$0.001370 / hour each (~$1 / month)2 rules
Cloud Armor requests$0.75 per milliona handful
Load balancer data processing$0.008 / GiBnegligible
Backend VMe2-micro, us-central1free tier
Cloud CDNcache fill and egress$0 — nothing was cached

Measured cost: not yet read. Those are rate card figures, not a bill. The billing export is read the day after teardown, because Week 13's returned two different totals forty minutes apart on the day of the deploy. This section is updated with the actual charge when it posts. A rate card multiplied by a stopwatch is an estimate, not a measurement.

Troubleshooting and Lessons

An org policy refused the architecture everyone draws

Problem: the Cloud Run backend failed with Error 400: One or more users named in the policy do not belong to a permitted customer, perhaps due to an organization policy.
Root cause: a serverless NEG needs allUsers as a Cloud Run invoker so the load balancer's own requests are served. iam.allowedPolicyMemberDomains, set org-wide in Week 03, refuses any principal outside the customer's domain — including allUsers.
Resolution: move the backend to a managed instance group.
Lesson: this failure is worse than it looks, because the obvious workaround destroys the experiment. Leave the service requiring authentication and both paths return 403 — the lab would appear to pass while measuring nothing. A control that blocks a design is visible; a control that quietly makes your test tautological is not.

The cache that was on and caching nothing

Problem: Cloud CDN enabled, two identical requests, no age header on either.
Root cause: CACHE_ALL_STATIC covers static media and web assets. HTML and JSON "are not cached by default for successful responses", and the backend serves text/html with no Cache-Control.
Resolution: none needed — the behaviour is correct. Caching HTML requires the origin to say so explicitly, and doing that carelessly is how user-specific pages end up served to other users.
Lesson: a feature flag reports what you configured, never what happened. The response headers are the only place the difference shows up, and they cost one curl -I to read.

Cleanup and Key Takeaways

Cleanup

terraform destroy removes all eleven resources with no manual step. The VPC and subnet belong to Week 04 and are deliberately left alone. Verified afterwards by sweeping Cloud Asset Inventory across the organization for fifteen billable resource types and finding none — a sweep that fails loudly when it cannot see, rather than reporting good news while blind.

Key takeaways

  • A WAF protects a path, not a resource. Cloud Armor is attached to a backend service and inspects what arrives through the load balancer. Everything else reaches the backend uninspected.
  • The architecture diagram is not the attack surface. Nobody draws the arrow that goes straight to the VM's own address, and that is exactly the arrow that was served 200.
  • Closing it is one rule or no public IP — and the second is the real answer. A backend behind a load balancer does not need an external address at all.
  • Enabling a cache is not caching. CACHE_ALL_STATIC does not cache HTML, and only the response headers will tell you.
  • A guardrail that blocks your design may be protecting your measurement too. Working around the org policy here would have produced a lab that passed every check and proved nothing.

References

Comments

How was your experience?
Your feedback helps improve this site.
PoorExcellent