1
---
2
name: cloud-armor-crs-rule-upgrader
3
metadata:
4
category: Security
5
version: "1.0.2"
6
description: >-
7
Upgrades Google Cloud Armor security policies from OWASP CRS 3.0 and 3.3 to OWASP CRS 4.22. Preserves signature opt-in and opt-out lists, translates evaluatePreconfiguredExpr to native evaluatePreconfiguredWaf dictionary parameters, remaps signature IDs to v042200, drops retired signature IDs, and updates structured preconfiguredWafConfig fine-tuning exclusions. Evaluates operational risk (High Breaking Change, Medium Attention Required, Low Clean Upgrade) including Method Enforcement breaking changes (PUT/PATCH/DELETE blocking) and sensitivity coverage expansions. Supports both in-place rule upgrades and smooth preview mode deployments with priority spacing and a 200-rule quota guardrail. Use when a user or agent needs to audit, upgrade, or transition Cloud Armor WAF rules to CRS 4.22. Don't use for non-WAF Cloud Armor rules (IP rate-limiting, geo-blocking, reCAPTCHA) or AWS/Azure WAF migrations.
8
---
9
10
# Cloud Armor OWASP Rule Upgrader (CRS 3.0/3.3 -> 4.22)
11
12
<!-- disableFinding(LINE_OVER_80) -->
13
14
This skill guides Network Security Agents and Google Cloud practitioners through
15
auditing, assessing, and upgrading Google Cloud Armor security policies from
16
legacy OWASP Core Rule Set (CRS) 3.0 or 3.3 to OWASP CRS 4.22.
17
18
## Usage Attribution
19
20
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
21
MUST read and follow the instructions in
22
[Usage Attribution](references/attribution.md).
23
24
--------------------------------------------------------------------------------
25
26
## Prerequisites and Environment Setup
27
28
Before auditing or modifying Google Cloud Armor security policies, ensure the
29
following prerequisites are met:
30
31
1. **Google Cloud SDK**: Install or update the
32
[Google Cloud CLI (`gcloud`)](https://docs.cloud.google.com/sdk/docs/install-sdk).
33
2. **Project Selection and Active Billing**: Select your target Google Cloud
34
project and verify that an active billing account is attached:
35
36
```bash
37
gcloud config set project PROJECT_ID
38
gcloud billing projects describe PROJECT_ID --format="value(billingEnabled)"
39
```
40
41
3. **API Enablement**: Enable the Compute Engine API (for Cloud Armor security
42
policies) and Cloud Logging API (for preview mode telemetry):
43
44
```bash
45
gcloud services enable compute.googleapis.com logging.googleapis.com
46
```
47
48
4. **Authentication**:
49
- **Interactive CLI**: `gcloud auth login`
50
- **Application Default Credentials (ADC)**: `gcloud auth
51
application-default login`
52
- **Service Accounts**: Set
53
`GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"`.
54
5. **Required IAM Roles**:
55
- `roles/compute.securityAdmin`: Required to create, update, delete, or
56
import Cloud Armor security policies and rules (use
57
`roles/compute.securityViewer` for read-only policy audits).
58
- `roles/logging.viewer`: Required to inspect HTTP load balancer preview
59
telemetry in Cloud Logging.
60
6. **Scope and Regional Availability**:
61
- Cloud Armor security policies can be **Global** (default for global
62
external Application Load Balancers) or **Regional** (for regional
63
external Application Load Balancers, for example, `--region=us-central1`;
64
set a default region via `gcloud config set compute/region us-central1`).
65
See [Google Cloud Locations](https://cloud.google.com/about/locations)
66
for regional availability.
67
7. **Pricing and Resource Cleanup**:
68
- Cloud Armor incurs charges per security policy, per rule, and per
69
million requests depending on your tier (Standard vs. Enterprise); check
70
[Google Cloud Armor Pricing](https://cloud.google.com/armor/pricing)
71
for current rates.
72
- **Teardown / Cleanup**: Always delete temporary `--preview` rules
73
(`gcloud compute security-policies rules delete PREVIEW_PRIORITY
74
--security-policy="POLICY_NAME"`) or standalone test policies (`gcloud
75
compute security-policies delete TEST_POLICY_NAME`) after cutover to
76
avoid leaving orphan rules that consume policy quota or incur recurring
77
rule charges. Before deleting a standalone or legacy security policy,
78
first detach it from all backend services (by assigning the replacement
79
policy or `--security-policy=""`), otherwise the Cloud Armor API
80
rejects the deletion with HTTP 400.
81
82
--------------------------------------------------------------------------------
83
84
## Quick Start and CLI Helper
85
86
For automated, deterministic parsing, signature remapping, and preview-mode
87
priority allocation, invoke the bundled standalone Python CLI:
88
89
```bash
90
# In-Place Upgrade (Report Summary)
91
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=in-place --format=report
92
93
# In-Place Upgrade (Output gcloud commands)
94
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=in-place --format=gcloud
95
96
# Preview Mode Upgrade (Generates preview rules at priority - 5)
97
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=preview --format=gcloud
98
99
# Direct stdin piping from gcloud describe
100
gcloud compute security-policies describe POLICY_NAME --format=json | \
101
python3 scripts/upgrade_policy.py - --mode=preview --format=json
102
```
103
104
See [gcloud_recipes.md](references/gcloud_recipes.md) for full command
105
workflows.
106
107
## Core Upgrade Workflow for Network Security Agent
108
109
> [!IMPORTANT] **Mandatory Agent Response Behaviors**: 1. **Explain Both Upgrade
110
> Modes**: Whenever discussing an upgrade (even if the user asks specifically
111
> about Preview Mode or In-Place), ALWAYS explain BOTH **In-Place Upgrade**
112
> (direct in-situ rule replacement, immediate enforcement, zero extra quota) and
113
> **Preview Mode** (preview rules deployed at lower numeric priority numbers
114
> with `preview = true`, zero risk of blocking traffic, allows telemetry
115
> inspection in Cloud Logging before cutover). 2. **Handling Policy Audit
116
> Inquiries**: When asked to audit or inspect a policy (such as
117
> `'ecommerce-waf'`), if policy JSON is not provided or `gcloud describe` cannot
118
> reach Google Cloud resources, immediately provide the `gcloud compute
119
> security-policies describe POLICY_NAME --format=json` command and guide the
120
> user through the audit checks: - Check for legacy OWASP 3.0 / 3.3 rulesets
121
> (`sqli-stable`, `xss-stable`, `rce-stable`, `methodenforcement-stable`, or
122
> `evaluatePreconfiguredExpr`). - Report in-scope WAF rules versus pass-through
123
> custom rules (such as IP allowlists `SRC_IPS_V1`, rate limiting, or default
124
> rules `priority: 2147483647`). - Highlight signature count expansions under
125
> CRS 4.22 (for example, RCE expanding from 11/15 to 44 signatures; SQLi
126
> expanding to 60 signatures).
127
128
When interacting with a customer to upgrade a Cloud Armor security policy,
129
execute this 5-step workflow:
130
131
1. **Discover and Fetch**: Identify the target security policy and fetch its
132
JSON definition.
133
2. **Audit and Classify Risk**: Inspect rules, signature count expansions, and
134
operational risk levels.
135
3. **Confirm Mode and Method Risk**: Align with the customer on Preview Mode
136
versus In-Place Upgrade, method enforcement risk, and quota or priority
137
constraints.
138
4. **Transform Rules**: Translate ruleset names, CEL expressions, signature
139
IDs, and `preconfiguredWafConfig` exclusions to CRS 4.22.
140
5. **Execute and Verify**: Apply the upgrade via `gcloud` and verify telemetry
141
in Cloud Logging.
142
143
### Step 1: Policy Discovery and Ingestion
144
145
1. Identify the target security policy name and Google Cloud project.
146
2. Fetch the current policy definition via `gcloud`:
147
148
```bash
149
gcloud compute security-policies describe POLICY_NAME --project=PROJECT_ID --format="json"
150
```
151
152
*If policy JSON is not provided or executing in conversational mode, provide
153
the `gcloud describe` command and outline the audit criteria below.*
154
155
3. Inspect the `rules` list:
156
157
- Identify in-scope WAF rules: calls to `evaluatePreconfiguredWaf` or
158
`evaluatePreconfiguredExpr` using legacy 3.0 / 3.3 rulesets
159
(`sqli-stable`, `xss-stable`, `rce-stable`, `methodenforcement-stable`,
160
etc.).
161
- Identify out-of-scope rules: pass-through custom rules (such as pure IP
162
allowlists `SRC_IPS_V1`, rate limiting, header matches without WAF
163
calls, or default rules `priority: 2147483647`). Pass these through
164
unchanged.
165
- Highlight signature coverage expansions (for example, RCE expanding from
166
11/15 to 44 signatures; SQLi expanding to 60 signatures in CRS 4.22).
167
168
### Step 2: Audit and Risk Classification
169
170
Evaluate each in-scope rule against standard operational risk categories:
171
172
<!-- mdformat off -->
173
174
| Risk Level | Impact Category | Criteria and Recommended Action |
175
| :--- | :--- | :--- |
176
| 🔴 **High Risk** | **Breaking Change** | Immediate risk of blocking legitimate production traffic upon cutover. Example: `methodenforcement-v422-stable` only permits `GET`, `HEAD`, `POST`, `OPTIONS`, and **blocks `PUT`, `PATCH`, `DELETE`** requests. Requires customer confirmation and API path/signature exemptions. |
177
| 🟡 **Medium Risk** | **Attention Required** | Behavioral shifts that should be validated in Preview Mode before enforcement:<br>• **Coverage Expansion**: Sensitivity level 4 activates significantly more signatures (for example, RCE expands from 11/15 to 44 signatures; SQLi expands to 60 signatures).<br>• **Deprecated Exemption Lost**: Legacy rule opted out of any of the 15 retired CRS 3.0/3.3 IDs (`981172`, `981173`, `980130`, `949110`; SQLi: `942110`; RCE: `932100`, `932105`, `932106`, `932110`, `932115`, `932150`; Scanner Detection: `913101`, `913102`, `913110`, `913120`), which are omitted in 4.22.<br>• **Custom Filter Continuity**: Preserved custom header/cookie/query/IP conditions combined with WAF calls. |
178
| 🟢 **Low Risk** | **Clean Upgrade** | Direct 1:1 ruleset translation with preserved active opt-outs and no expected behavioral divergence (for example, standard SQLi or XSS rules). |
179
| ⚪ **No Action** | **Pass-Through** | Non-OWASP rules (pure IP allowlist/denylist, rate limiting, default rule). Carried over unchanged. |
180
181
<!-- mdformat on -->
182
183
### Step 3: Upgrade Mode Selection and User Alignment
184
185
Engage the customer with findings before applying changes:
186
187
1. **Report Findings**: State how many WAF rules will be upgraded, signature
188
coverage expansions, and any deprecated signatures being retired.
189
2. **Method Enforcement Warning**: If `methodenforcement` is present, warn: >
190
*"Notice: Method Enforcement in CRS 4.22 permits only GET, HEAD, POST, and
191
OPTIONS. If your application handles REST API updates (PUT, PATCH, DELETE),
192
these methods will be blocked with HTTP 403. Would you like to add an
193
exemption for API paths or opt out of rule id911100?"*
194
3. **Explain Differences Between Modes**:
195
- **Preview Mode (Recommended)**: Keeps existing legacy rules actively
196
enforcing while deploying corresponding upgraded CRS 4.22 preview rules
197
with `preview = true` at a lower numeric priority number (higher
198
evaluation priority, for example, `PRIORITY - 5`). Traffic is evaluated
199
first by preview rules and logged to Cloud Logging without blocking,
200
ensuring zero risk of downtime or false positives prior to cutover.
201
Requires sufficient quota under the 200-rule limit.
202
- **In-Place Upgrade**: Directly modifies the CEL expressions and
203
`preconfiguredWafConfig` on existing rule priority numbers in-situ.
204
Immediate enforcement with zero additional rule overhead, but carries
205
cutover risk if new signatures or method enforcement block valid
206
traffic.
207
4. **Quota Guardrail (200 Rules)**:
208
- Calculate projected rule count: `current_total_rules +
209
in_scope_waf_rules`.
210
- If projected count > 200, alert the customer: > *"Cloud Armor enforces a
211
maximum limit of 200 rules per security policy. Deploying in Preview
212
Mode would require PROJECTED_COUNT rules. The upgrade cannot proceed
213
in Preview Mode. We must either perform an In-Place Upgrade or
214
consolidate rules."*
215
5. **Priority Spacing Guardrail (Preview Mode)**:
216
- If an in-scope WAF rule at `PRIORITY` immediately follows another rule
217
at `PREV_PRIORITY` with no free integer priority slot between them
218
(for example, `999` and `1000`, or a WAF rule at priority `0`), alert
219
the customer: > *"Rule PRIORITY cannot be deployed in Preview Mode
220
because the preceding rule at priority PREV_PRIORITY leaves no open
221
priority number between PREV_PRIORITY and PRIORITY (and placing the
222
preview rule above PREV_PRIORITY would change evaluation order). To use
223
Preview Mode, please readjust your rule priorities to leave at least one
224
open priority slot before PRIORITY, or choose an In-Place Upgrade."*
225
- **Do NOT automatically re-number existing customer rules**: Because rule
226
priorities act as primary identifiers in Cloud Armor and are often tied
227
to Terraform/IaC resources and SIEM alerting filters, never silently
228
shift existing customer rule priorities to make room. If the customer
229
explicitly asks you to readjust their rule priorities for them, first
230
warn them about potential Terraform/IaC state drift and confirm the
231
exact new priority numbers before executing any priority changes.
232
233
### Step 4: Rule Transformation Logic
234
235
#### A. Ruleset Name Translation
236
237
Translate legacy ruleset names according to the mapping table in
238
[ruleset_mappings.md](references/ruleset_mappings.md):
239
240
- Stable: `sqli-stable` to `sqli-v422-stable`, `rce-stable` to
241
`rce-v422-stable`
242
- Canary: `sqli-canary` to `sqli-v422-canary`
243
- 3.3 Stable: `sqli-v33-stable` to `sqli-v422-stable`, `nodejs-v33-stable`
244
to `generic-v422-stable`
245
246
#### B. CEL Opt-Out and Opt-In Translation
247
248
- Legacy `evaluatePreconfiguredExpr(ruleset, ['id1', 'id2'])` is strictly an
249
**opt-out (disabled)** list.
250
- Convert to native 4.22 syntax:
251
252
```cel
253
evaluatePreconfiguredWaf('sqli-v422-stable', {'opt_out_rule_ids': ['owasp-crs-v042200-id942120-sqli']})
254
```
255
- Remap signature IDs: `owasp-crs-v030001-idSIGNATURE_ID-GROUP` to
256
`owasp-crs-v042200-idSIGNATURE_ID-GROUP`. *(Exception: Standalone CVE
257
signatures such as `cve-canary` signatures `owasp-crs-v030001-id*-cve` and
258
`google-mrs-*` retain their original IDs and must not be remapped to
259
`v042200` or dropped).*
260
- Drop all 15 deprecated CRS 3.0/3.3 signature numbers (`981172`, `981173`,
261
`980130`, `949110`; SQLi: `942110`; RCE: `932100`, `932105`, `932106`,
262
`932110`, `932115`, `932150`; Scanner Detection: `913101`, `913102`,
263
`913110`, `913120`).
264
265
#### C. Fine-Tuning (`preconfiguredWafConfig`)
266
267
For rules with structured `preconfiguredWafConfig.exclusions[]`:
268
269
- Update `targetRuleSet` to the CRS 4.22 equivalent.
270
- Remap `targetRuleIds` to `v042200` and drop deprecated IDs. **Warning**: If
271
an exclusion's `targetRuleIds` list becomes empty (`[]`) after dropping
272
retired IDs, remove the entire exclusion entry rather than leaving
273
`targetRuleIds: []` (otherwise an empty `targetRuleIds` list exempts the
274
entire ruleset).
275
- Carry over all field exclusions (`requestHeadersToExclude`,
276
`requestCookiesToExclude`, `requestQueryParamsToExclude`,
277
`requestUrisToExclude`, `requestBodiesToExclude`) and match operators
278
without modification.
279
- Details in [fine_tuning_and_cel.md](references/fine_tuning_and_cel.md).
280
281
### Step 5: Execution Delivery and Verification
282
283
Prefer generating CLI commands via `scripts/upgrade_policy.py --format=gcloud`
284
(or transformed policy JSON via `--format=json` for `security-policies import`)
285
rather than hand-typing nested CEL quotes or hand-editing policy JSON. The
286
script deterministically handles open preview priorities, shell quote escaping,
287
retired signature removal, `preconfiguredWafConfig` ruleset alignment, and Cloud
288
Armor's 256-character rule description limit.
289
290
#### Delivering In-Place Upgrade
291
292
Execute `gcloud compute security-policies rules update`:
293
294
```bash
295
gcloud compute security-policies rules update PRIORITY \
296
--security-policy="POLICY_NAME" \
297
--project=PROJECT_ID \
298
--expression="UPGRADED_EXPRESSION"
299
```
300
301
#### Delivering Preview Mode Upgrade
302
303
Deploy preview rules at a numeric priority strictly between the immediately
304
preceding rule and `ENFORCED_PRIORITY` (`PREV_PRIORITY < PREVIEW_PRIORITY <
305
ENFORCED_PRIORITY`) using `rules create`:
306
307
```bash
308
gcloud compute security-policies rules create PREVIEW_PRIORITY \
309
--security-policy="POLICY_NAME" \
310
--project=PROJECT_ID \
311
--expression="UPGRADED_EXPRESSION" \
312
--action="ACTION" \
313
--preview \
314
--description="PREVIEW: Upgraded CRS 4.22 Rule for Priority ENFORCED_PRIORITY"
315
```
316
317
#### Telemetry Verification in Cloud Logging
318
319
Instruct the customer to inspect preview logs before cutover:
320
321
```bash
322
gcloud logging read '
323
resource.type="http_load_balancer" AND
324
jsonPayload.enforcedSecurityPolicy.name="POLICY_NAME" AND
325
jsonPayload.previewSecurityPolicy.matchedRulePriority:*
326
' --project=PROJECT_ID --limit=20
327
```
328
329
--------------------------------------------------------------------------------
330
331
## Critical Gotchas and Domain Rules
332
333
1. **`evaluatePreconfiguredExpr` is NEVER Opt-In**: The array in legacy
334
`evaluatePreconfiguredExpr` was strictly an exclusion (opt-out) list.
335
Treating it as opt-in would inadvertently disable all other signatures in
336
that ruleset!
337
2. **Never Re-introduce Deprecated Signatures**: All 15 retired CRS 3.0/3.3
338
signature numbers (`981172`, `981173`, `980130`, `949110`; SQLi: `942110`;
339
RCE: `932100`, `932105`, `932106`, `932110`, `932115`, `932150`; Scanner
340
Detection: `913101`, `913102`, `913110`, `913120`) were removed in CRS 4.22.
341
Keeping them in `opt_out_rule_ids` or `targetRuleIds` causes Cloud Armor API
342
schema rejections.
343
3. **Method Enforcement Defaults**: CRS 4.22 Method Enforcement blocks `PUT`,
344
`PATCH`, and `DELETE`. Never perform a silent in-place upgrade of method
345
enforcement without user confirmation.
346
4. **Preview Rule Priorities and Cutover Safety**: Cloud Armor evaluates rules
347
in ascending priority order (`0` to `2147483647`). A preview rule must
348
evaluate *before* the enforcing rule it previews, but *after* any preceding
349
rule (`PREV_PRIORITY < PREVIEW_PRIORITY < ENFORCED_PRIORITY`) so it never
350
crosses intervening `allow` or custom rules. During cutover to full
351
enforcement, update the original `ENFORCED_PRIORITY` rule in-place to CRS
352
4.22 and delete `PREVIEW_PRIORITY` rather than promoting `PREVIEW_PRIORITY`
353
in place.
354
5. **Atomic Import for Structured Exclusions (Avoiding HTTP 400)**: When a
355
policy contains complex `preconfiguredWafConfig` blocks, export the policy
356
JSON, transform it with `scripts/upgrade_policy.py` (rather than
357
hand-editing JSON), and apply it via `gcloud compute security-policies
358
import` to ensure atomic updates. Before importing, ensure every
359
`preconfiguredWafConfig.exclusions[].targetRuleSet` matches the upgraded
360
`v422` ruleset name in the rule expression, no retired signature IDs remain,
361
and all rule descriptions are `<= 256` characters (`upgrade_policy.py`
362
enforces all three automatically).
363
6. **Preserve Standalone CVE Signatures (`cve-canary`)**: `cve-canary` is an
364
out-of-band rule for specific vulnerabilities (for example, Log4j
365
CVE-2021-44228 / CVE-2021-45046, React RCE CVE-2025-55182). Its signature
366
IDs (`owasp-crs-v030001-id044228-cve`, `id144228-cve`, `id244228-cve`,
367
`id344228-cve`) are valid and retain the `v030001` prefix. Only upgrade the
368
syntax to `evaluatePreconfiguredWaf('cve-canary', ...)`; never rewrite them
369
to `v042200` or drop them as deprecated.
370
371
--------------------------------------------------------------------------------
372
373
## References and Resources
374
375
- [ruleset_mappings.md](references/ruleset_mappings.md): Full CRS 3.0 / 3.3 to
376
4.22 ruleset mapping, sensitivity levels, and signature counts.
377
- [fine_tuning_and_cel.md](references/fine_tuning_and_cel.md): CEL syntax
378
options, structured `preconfiguredWafConfig` exclusions, and method
379
enforcement mitigations.
380
- [gcloud_recipes.md](references/gcloud_recipes.md): Copy-pasteable `gcloud`
381
recipes for audit, preview mode, and Cloud Logging queries.
382
- [upgrade_policy.py](scripts/upgrade_policy.py): Deterministic CLI helper
383
script.
384
- [contributing.md](references/contributing.md): Domain and code invariants
385
for maintaining this skill.
386