📋 In This Post
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
| Capability | Who consumes it | What it replaces | What it costs them |
|---|---|---|---|
| A global anycast address, a cache and a WAF in front of their service | Any team shipping an external endpoint | Designing edge protection per team, and a ticket for every rule | Nothing to configure — the load balancer and the policy are platform-owned |
| Evidence the protection cannot be walked around | Security review, audit | "The WAF is in front of it" on an architecture slide | One re-runnable command |
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| Global external Application Load Balancer | The guarded front door | One 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 Armor | The WAF under test | A 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 CDN | Caching, and an honesty check on it | A 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 group | The thing being protected | Identical VMs built from one instance template, which a backend service points at as a unit. Here, one e2-micro serving a page. |
| Health check | Makes the backend eligible for traffic | A probe from Google's infrastructure. Until it passes, the backend service has no healthy backend and the load balancer answers 502. |
| VPC firewall rule | The week's one variable | Decides which source ranges may reach port 80. Everything in the measurement is held constant except this. |
| Terraform & HCP Terraform | Declares it and applies it remotely | Infrastructure 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
- A Cloud Armor policy is created with one preconfigured SQL injection rule at
deny(403)and a default allow beneath it. - 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.
- A health check and a backend service are created; the policy and Cloud CDN both attach to the backend service.
- A URL map, target proxy, reserved global address and forwarding rule complete the load balancer.
- A firewall rule allows port 80 from
0.0.0.0/0, so the second path exists to be measured before it is closed. - The same attack-shaped request goes to the load balancer and to the VM's own address; both responses are recorded.
- 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-osloginandblock-project-ssh-keyscannot be created at all.
Implementation
What was deployed
| What | How many | Its job |
|---|---|---|
| Cloud Armor security policy | 1 | One SQLi rule at deny(403), one default allow |
| Instance template + managed instance group | 1 + 1 | One e2-micro serving a page on port 80, with its own external IP |
| Health check | 1 | Makes the backend eligible for traffic |
| Firewall rule | 1 | The week's one variable — who may reach port 80 directly |
| Backend service | 1 | EXTERNAL_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 rule | 4 | The rest of the load balancer |
| Service enablement | 1 | compute.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
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
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
Step 6 — Is the cache caching?
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.
| Test | Expected result | Actual result | Status |
|---|---|---|---|
| Attack through the load balancer, firewall open | 403 from Cloud Armor | 403 | Pass |
| Ordinary request through the load balancer | 200 | 200 | Pass |
| Same attack straight to the backend | 200 — the bypass | 200 | Pass |
| Attack through the load balancer, firewall narrowed | 403, unchanged | 403 | Pass |
| Ordinary request, firewall narrowed | 200, unchanged | 200 | Pass |
| Same attack straight to the backend, firewall narrowed | no connection | 000 | Pass |
| All three, firewall reopened | back to 403 / 200 / 200 | 403 / 200 / 200 | Pass |
| Cloud CDN serving a cached response | an age header on the second request | no age, no cache-control | Measured — 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/22and35.191.0.0/16is 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.allowedPolicyMemberDomainsblocked a publicallUsersbinding. 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-osloginandblock-project-ssh-keysbecause the organization's policies refuse to create it otherwise.
Cost
| Item | Rate, read 28 November | This 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 million | a handful |
| Load balancer data processing | $0.008 / GiB | negligible |
| Backend VM | e2-micro, us-central1 | free tier |
| Cloud CDN | cache 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_STATICdoes 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
- Cloud Armor security policy overview — what a backend policy attaches to, and what it therefore does not see
- External Application Load Balancer overview — the GFE and health-check source ranges
- Health check concepts — probe ranges and the implied deny that makes a backend unhealthy
- Cloud CDN caching overview — what each cache mode makes eligible
- week-15-global-load-balancing — Terraform, the measurement script, the raw results and the lab guide
Comments