Business Challenge
#108 took the first feature that hangs off the backend service. This is the second, and it answers a different question: not whether to store a response, but whether to let the request through. Cloud Armor security policies enable you to allow, deny, rate-limit, or redirect requests to your backend services at the Google Cloud edge, as close as possible to the source of incoming traffic.
A policy is a list: Cloud Armor security policies are collections of Cloud Armor rules that are applied to requests destined for a protected resource in the order configured by the policy, and each rule consists of a match condition and an action to take when that condition is met. Everything that goes wrong here goes wrong in the ordering.
Almost always the sensitivity level, which defaults to the most aggressive setting available. Each preconfigured WAF rule has a sensitivity level that corresponds to a OWASP CRS paranoia level. A lower sensitivity level indicates a higher confidence signature, which is less likely to generate a false positive. A higher sensitivity level increases security, but also increases the risk of generating a false positive. By default, Cloud Armor runs at sensitivity level 4 and evaluates all signatures in a rule set once enabled.
Four is the top of the range — you can select a sensitivity between 0 and 4, though sensitivity level 0 means that no rules are enabled — so enabling a rule set with no tuning opts you into every signature it has, including the low-confidence ones.
Correct approachFollow Google's own recommendation rather than the default: start with sensitivity level 1 in preview mode to understand how rules affect your application. Then raise it deliberately. Selecting a level is cumulative — when you select a sensitivity level for your preconfigured WAF rule, you opt in signatures at the sensitivity levels less than or equal to the selected sensitivity level — so level 1 is a floor you build on, not a compromise you are stuck with.
If the allow rule for that range has a lower priority number than the WAF rule, the request never reaches the WAF. Google documents this with two near-identical example policies, and the second is described plainly: the policy allows IP 9.9.9.1 without scanning against XSS attacks. The only difference between the two is which rule number the allowlist entry got.
This is correct first-match behaviour, not a bug. But an allowlist written for convenience becomes a documented bypass of every scanning rule beneath it, and nothing in the policy flags the interaction.
Correct approachPut scanning rules above allowlists unless you have decided, explicitly, that a given source is exempt from inspection. Leave room to change your mind: priority numbers can have gaps. These gaps let you add or remove rules in the future without affecting the rest of the rules. A policy numbered 1, 2, 3 has nowhere to insert a rule; one numbered 100, 200, 300 does.
Because the threshold is per backend, not per policy. Cloud Armor applies the rate limiting threshold to each associated backend. For example, if you have two backend services and you configure a rate limiting rule with a threshold of 1,000 requests per minute, then each backend service can receive 1,000 requests per minute before Cloud Armor applies the rule action.
A second version of the same surprise lives in the key types. Naming a header to rate limit by looks precise, but the key value is truncated to the first 128 bytes of the header value. The key type defaults to ALL if no such header is present — so a request missing that header is counted against one shared bucket rather than its own, which is the opposite of what per-client limiting was for.
Correct approachDivide your intended ceiling by the number of backends the policy is attached to, and prefer keys that cannot silently degrade. Note also one door that only opens one way: when you configure a rule with a rate-based ban action, you can't change it to a throttle action later. However, when you configure a rule with a throttle action, you can change it to a rate-based ban action later. Start with throttle.
Architecture
Five policy types, one ordering rule, and one documented exception to it.
Five policy types, distinguished by what they can attach to
Each security policy is made up of a set of rules that can be configured on attributes from Layer 3 through Layer 7, but the type decides which attributes and which resources. Backend policies carry the type flag CLOUD_ARMOR and cover backend services behind the Application and proxy Network Load Balancers from #104 to #106. Edge policies are CLOUD_ARMOR_EDGE, and they hold one capability nothing else does: only edge security policies can be applied to backend buckets.
Network edge policies are CLOUD_ARMOR_NETWORK, for passthrough Network Load Balancers, protocol forwarding and VMs with public addresses. They are the only security policy type to support byte offset filtering, and they have a prerequisite: to configure network edge security policies, you must first configure advanced network DDoS protection in the region where you intend to create the policies. A regional backend variant and an internal service type for Cloud Service Mesh fairshare complete the set.
The types are not interchangeable and you cannot stack two of a kind. A backend service can have two service-level security policies associated with it at the same time, but it can't have two backend security policies or two edge security policies at the same time, and you cannot set an edge security policy as a backend policy. Two layers, one of each — which is the intended design rather than a limitation.
One asymmetry in the lifecycle is worth knowing before an incident makes you discover it. If a Cloud Armor security policy is associated with any backend service, it can't be deleted. A backend service can be deleted regardless of whether it has an associated security policy. The dependency is enforced in exactly one direction.
Edge policies run before the cache, and before IAP
This is where #108 and #109 interlock. Edge security policies are deployed and enforced near the outermost perimeter of Google's network, upstream of where the Cloud CDN cache resides, and the consequence is stated directly: when edge security policies and backend security policies are attached to the same backend service, backend security policies are enforced only for cache miss requests that have passed edge security policies.
So a cache hit is filtered by the edge policy and by nothing else. If your geographic blocking lives in a backend policy and your content is cached, the block is applied to the requests that miss the cache and skipped for the ones that hit it.
The same ordering reaches past caching. Edge security policies are evaluated and enforced before Identity-Aware Proxy (IAP). A request blocked by an edge security policy is denied before IAP evaluates the identity of the requestor. That is useful when you want unwanted traffic rejected before it costs you an authentication round trip, and a trap when you expected an identity check to be the first thing that happened.
Edge policies pay for their position with a narrower match surface: they support filtering based on only origin.asn, origin.ip, origin.region_code, request.headers, request.method, request.path, request.query, and request.scheme. No body filtering, no WAF, no managed rules.
Priority, the default rule, and the fingerprint
Rule evaluation order is determined by rule priority, from the lowest number to the highest number. The rule with the lowest numeric value assigned has the highest logical priority. The range is wide and the top of it is taken: you cannot configure two or more rules with the same priority. The priority for each rule must be set to a number from 0 to 2147483646 inclusive. The priority value 2147483647, also known as INT-MAX, is reserved for the default rule.
That default rule is the policy's failure mode, and it is already set to the safe answer. The default rule is automatically assigned a priority of 2147483647 (INT-MAX), and it is always present in the security policy. You can't delete the default rule, but you can modify it. The default action for the default rule is deny, but you can change the action to allow. A new policy therefore denies everything it does not explicitly permit, which is the right default and the reason a half-written policy fails closed rather than open.
Updating a policy uses optimistic concurrency control, which is unusual enough in networking to be worth naming. When you update a security policy, you must specify the current fingerprint, which you get when you export or describe the policy, and the fingerprint protects you from overriding another user's update. If the fingerprint that you provide is out of date, it means that the security policy was updated since you last retrieved the fingerprint. Two people editing the same firewall cannot silently overwrite each other.
The exception: header and body are two phases
Priority orders rules within a phase, and there are two phases. For requests containing bodies, Cloud Armor receives the request's header before the body (payload). Because Cloud Armor receives the header information first, it evaluates rules that match against the header, but it doesn't match any preconfigured rules on the body.
From which follows the sentence that governs this whole post: it's possible that lower priority rules that allow a request's header are matched before higher priority rules that block the request's body. And the result: it is possible that the HTTP header portion of the request is sent to the target backend service, but the body containing potentially malicious content is blocked. Half a request arrives.
The phase split also changes what two actions mean. Note that redirect actions and inserting custom header actions work only during the header processing phase. The redirect action, if matched during the following body processing phase, is translated to a deny action. The custom request header action, if matched during the body processing phase, doesn't take effect. A rule written to send a client to a reCAPTCHA challenge denies them instead, if what matched was in the body.
Which rules are even capable of reaching phase two is a short list: only preconfigured WAF rules (evaluatePreconfiguredWaf()) and custom rules that reference request.body or request.params are evaluated against the request body. All other expressions are evaluated only against the request header.
What the WAF can and cannot see
Google Cloud Armor preconfigured WAF rules are complex web application firewall (WAF) rules with dozens of signatures that are compiled from open source industry standards. Each signature corresponds to an attack detection rule in the ruleset. Google offers these rules as is. They come from a named upstream: these rules are based on the OWASP ModSecurity Core Rule Set (CRS), such as OWASP Core Rule Set 4.22. We recommend using version 4.22 for the most up-to-date protection against modern threats. Older sets remain available with a caveat — while support for CRS 3.3 and 3.0 is ongoing, we recommend avoiding older versions, especially CRS version 3.0, whenever your workloads allow for version 4.22. Rule sets move between versions too: the nodejs rule set in v3.3 was reclassified as generic in v4.22.
Inspection has a hard edge. Cloud Armor preconfigured WAF rules can inspect up to 64 kB of the request body, and Google is candid about what sits beyond it: the remainder of the request body might contain payloads that would match a WAF rule signature, which your application might accept. Encoding matters as much as size — for other content types and encoding types, including multipart/form-data, Cloud Armor doesn't decode the data, but applies the preconfigured rules to raw data, so a signature looking for a decoded string will not find it in an undecoded upload.
Tuning is the other half of making a WAF usable, and it runs three ways: opt signature IDs out, or to opt in rule signatures, the sensitivity level must be 0 and you list the few you want, or exclude specific request fields. The exclusions are narrower than they sound — only the value of the specified request headers are excluded from inspection. The name is still inspected — and they are bounded: the default tuning exclusion limit is 100 for service-level backend policies (both global and regional). This limit applies per target and controls the maximum number of exclusions you can configure, within a security policy rule. A target is the combination of a rule set and a rule ID.
Two restrictions on tuning deserve a note. When you have a request field exclusion attached to a WAF rule, you can't use the allow action, and inheritance removes the option entirely: you can tune preconfigured WAF rules in hierarchical security policies that you own. If your service inherits a hierarchical security policy, you cannot tune its rules.
Why This Architecture Holds Up
Stand a new Cloud Armor policy up and three separate defaults conspire to make it look like nothing happened. The first is logging: request logging for new backend service resources is disabled by default. To log Cloud Armor requests, you must enable HTTP(S) logging for each backend service protected by a security policy. A working policy and a policy doing nothing produce the same empty log view.
The second is how much gets logged once you do enable it. Cloud Armor logs are generated based on the first (highest priority) rule that matches an incoming request, whether or not the security policy is in preview mode. This means that logs aren't generated for non-matching rules, nor for matching rules at lower priorities. One line per request, from one rule. You cannot see what a rule further down would have done, which is exactly the question you want answered when tuning.
Preview mode is the answer to that, and it carries its own two surprises. If a request triggers a preview, Cloud Armor continues to evaluate other rules until finding a match. Both the matched and preview rule are available in the logs — so a previewed rule does not stop evaluation, and you get to compare. But you are charged the normal per-request fee for rules in preview mode. Preview is a safety mechanism, not a free one.
Google's own suggested arrangement uses all of this together: maintain canary rulesets in preview mode with a higher priority, and keep stable rulesets in enforced mode with a lower priority. This approach lets you validate rule changes before they affect your production traffic. The canary sits above the stable rule so it sees every request, observes, and does not act.
Three protocols where enforcement is less complete than it looks
WebSockets get inspected once. Cloud Armor can block a WebSocket channel from being established, but subsequent transactions in the channel don't conform to the HTTP protocol, and Cloud Armor doesn't evaluate any messages after the first request. A WAF in front of a WebSocket application is filtering the handshake and nothing else.
gRPC gets enforced but reported confusingly: you might see that the load balancer still reports 200 OK HTTP status code responses in its logs and metrics. This doesn't mean that Cloud Armor isn't working as intended.
And the proxy Network Load Balancers from #106 enforce at a different granularity. Cloud Armor enforces the security policy rule deny action only on new connection requests. The deny action terminates the TCP connection. In addition, if you provide a status code with your deny action, the status code is ignored. Rate limiting there is similarly reduced: only the key types ALL and IP are supported. If you attempt to use the key type HTTP-HEADER or HTTP-COOKIE with TCP/SSL load balancers, the key type is interpreted as ALL, and likewise XFF-IP is interpreted as IP. The configuration is accepted and quietly means something else.
One more thing that is honest rather than reassuring, and belongs in any geographic-blocking design. Cloud Armor uses our own IP geolocation database to identify the request geography location, and updates roll out gradually, so it's possible to see requests from the same client IP address being handled inconsistently during a rollout when the geolocation mapping for the client IP address has changed. A geography rule is a strong default and a weak guarantee.
Key Architecture Decisions
| Situation | Decision | Because |
|---|---|---|
| Enabling a preconfigured WAF rule set | Set sensitivity 1 and preview it first | The default is level 4, which evaluates every signature in the set. |
| Protecting a backend bucket | Edge policy — there is no choice | Only edge security policies can be applied to backend buckets. |
| Cached content behind a backend policy | Move the filtering to an edge policy | Backend policies only see cache misses that passed the edge. |
| Allowlisting a partner IP range | Put it below the scanning rules | An allow above the WAF means that source is never scanned. |
| Numbering a new policy's rules | Leave gaps — 100, 200, 300 | Priorities are unique and gaps are what let you insert later. |
| Redirecting bots to a challenge | Match on headers, not on the body | A redirect matched in the body phase becomes a deny. |
| Rate limiting across several backends | Divide the threshold by the backend count | The threshold applies to each associated backend separately. |
| First rate limiting rule | Throttle, never rate-based ban | Throttle converts to ban later; ban does not convert back. |
| Rate limiting by a custom header | Confirm the header is always present | Absent, the key type falls back to ALL — one shared bucket. |
| Policy deployed and logs are empty | Enable HTTP(S) logging per backend service | Request logging is off by default for new backend services. |
| Validating a new rule set version | Canary in preview above stable enforced | Google's documented pattern; preview does not stop evaluation. |
| WAF in front of a WebSocket app | Treat it as handshake-only protection | No messages after the first request are evaluated. |
| Uploads over multipart/form-data | Validate in the application too | Cloud Armor applies the rules to raw, undecoded data. |
| Editing a policy from automation | Read the fingerprint, then write | A stale fingerprint is rejected rather than applied. |
The one to look at today
Export one security policy and read it in priority order, asking a single question at each rule: does anything above this allow traffic that this rule was meant to inspect? That is the bypass in Google's second worked example, and it is invisible in a console that lists rules without explaining their interaction. While you have the export open, check two more things: whether any evaluatePreconfiguredWaf call specifies a sensitivity at all — if not, it is running at 4 — and whether the backend services behind the policy have HTTP(S) logging enabled, because without it you have no evidence either way.
Closing Thought
Seven posts of load balancing have had the same shape. A number that reads like a limit is a weight. Three modes that read like levels of aggressiveness are answers about delegation. And now a priority field, which is the most explicit ordering promise in the whole product, holds only within a phase boundary the configuration never mentions.
The pattern is not that Google's documentation hides these things — every sentence quoted here is on a public page, and the two-phase exception has a worked example. It is that the configuration surface presents each setting as if it were the whole story, and the behaviour lives one page over. A security policy is a list of rules in an order; whether that order is the order you wrote depends on something you cannot see in the list.
#110 closes the networking block with Network Intelligence Center and connectivity tests — the tooling that answers "can this reach that, and if not, which of the last twenty posts is the reason", by evaluating the configuration rather than sending a packet.
Official Google Cloud Reference
- Cloud Armor overview
- Security policy overview
- Preconfigured WAF rules overview
- Tune preconfigured WAF rules
- Rate limiting overview
- Managed rules overview
- Create security policy rules
- Bot management overview
- Adaptive Protection overview
- Hierarchical security policies overview
- Use request logging
- Cloud Armor best practices
Comments