{"data":{"slug":"github-google-skills-skills-cloud-cloud-armor-crs-rule-upgrader-a26d80f4c582","title":"Cloud Armor CRS Rule Upgrader","summary":"Upgrade Cloud Armor security policies to the latest OWASP Core Rule Set (CRS) versions with in-place or preview mode options. The deliverable is a set of upgraded rules in JSON format, ready for deployment or testing.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-armor-crs-rule-upgrader-a26d80f4c582","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-cloud-armor-crs-rule-upgrader-a26d80f4c582","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-armor-crs-rule-upgrader-a26d80f4c582.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-cloud-armor-crs-rule-upgrader-a26d80f4c582\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any upgrade, ensure the Google Cloud SDK is installed, the project is selected, and the Compute Engine and Cloud Logging APIs are enabled. Additionally, review and follow the instructions in [Usage Attribution](references\/attribution.md) before running any `gcloud`, REST API, or MCP commands.","instructions":"---\nname: cloud-armor-crs-rule-upgrader\nmetadata:\n  category: Security\n  version: \"1.0.1\"\ndescription: >-\n  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.\n---\n\n# Cloud Armor OWASP Rule Upgrader (CRS 3.0\/3.3 -> 4.22)\n\n<!-- disableFinding(LINE_OVER_80) -->\n\nThis skill guides Network Security Agents and Google Cloud practitioners through\nauditing, assessing, and upgrading Google Cloud Armor security policies from\nlegacy OWASP Core Rule Set (CRS) 3.0 or 3.3 to OWASP CRS 4.22.\n\n## Usage Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read and follow the instructions in\n[Usage Attribution](references\/attribution.md).\n\n--------------------------------------------------------------------------------\n\n## Prerequisites and Environment Setup\n\nBefore auditing or modifying Google Cloud Armor security policies, ensure the\nfollowing prerequisites are met:\n\n1.  **Google Cloud SDK**: Install or update the\n    [Google Cloud CLI (`gcloud`)](https:\/\/docs.cloud.google.com\/sdk\/docs\/install-sdk).\n2.  **Project Selection and Active Billing**: Select your target Google Cloud\n    project and verify that an active billing account is attached:\n\n    ```bash\n    gcloud config set project PROJECT_ID\n    gcloud billing projects describe PROJECT_ID --format=\"value(billingEnabled)\"\n    ```\n\n3.  **API Enablement**: Enable the Compute Engine API (for Cloud Armor security\n    policies) and Cloud Logging API (for preview mode telemetry):\n\n    ```bash\n    gcloud services enable compute.googleapis.com logging.googleapis.com\n    ```\n\n4.  **Authentication**:\n    -   **Interactive CLI**: `gcloud auth login`\n    -   **Application Default Credentials (ADC)**: `gcloud auth\n        application-default login`\n    -   **Service Accounts**: Set\n        `GOOGLE_APPLICATION_CREDENTIALS=\"\/path\/to\/service-account-key.json\"`.\n5.  **Required IAM Roles**:\n    -   `roles\/compute.securityAdmin`: Required to create, update, delete, or\n        import Cloud Armor security policies and rules (use\n        `roles\/compute.securityViewer` for read-only policy audits).\n    -   `roles\/logging.viewer`: Required to inspect HTTP load balancer preview\n        telemetry in Cloud Logging.\n6.  **Scope and Regional Availability**:\n    -   Cloud Armor security policies can be **Global** (default for global\n        external Application Load Balancers) or **Regional** (for regional\n        external Application Load Balancers, for example, `--region=us-central1`;\n        set a default region via `gcloud config set compute\/region us-central1`).\n        See [Google Cloud Locations](https:\/\/cloud.google.com\/about\/locations)\n        for regional availability.\n7.  **Pricing and Resource Cleanup**:\n    -   Cloud Armor incurs charges per security policy, per rule, and per\n        million requests depending on your tier (Standard vs. Enterprise); check\n        [Google Cloud Armor Pricing](https:\/\/cloud.google.com\/armor\/pricing)\n        for current rates.\n    -   **Teardown \/ Cleanup**: Always delete temporary `--preview` rules\n        (`gcloud compute security-policies rules delete PREVIEW_PRIORITY\n        --security-policy=\"POLICY_NAME\"`) or standalone test policies (`gcloud\n        compute security-policies delete TEST_POLICY_NAME`) after cutover to\n        avoid leaving orphan rules that consume policy quota or incur recurring\n        rule charges.\n\n--------------------------------------------------------------------------------\n\n## Quick Start and CLI Helper\n\nFor automated, deterministic parsing, signature remapping, and preview-mode\npriority allocation, invoke the bundled standalone Python CLI:\n\n```bash\n# In-Place Upgrade (Report Summary)\npython3 scripts\/upgrade_policy.py \/path\/to\/policy.json --mode=in-place --format=report\n\n# In-Place Upgrade (Output gcloud commands)\npython3 scripts\/upgrade_policy.py \/path\/to\/policy.json --mode=in-place --format=gcloud\n\n# Preview Mode Upgrade (Generates preview rules at priority - 5)\npython3 scripts\/upgrade_policy.py \/path\/to\/policy.json --mode=preview --format=gcloud\n\n# Direct stdin piping from gcloud describe\ngcloud compute security-policies describe POLICY_NAME --format=json | \\\n  python3 scripts\/upgrade_policy.py - --mode=preview --format=json\n```\n\nSee [gcloud_recipes.md](references\/gcloud_recipes.md) for full command\nworkflows.\n\n## Core Upgrade Workflow for Network Security Agent\n\n> [!IMPORTANT] **Mandatory Agent Response Behaviors**: 1. **Explain Both Upgrade\n> Modes**: Whenever discussing an upgrade (even if the user asks specifically\n> about Preview Mode or In-Place), ALWAYS explain BOTH **In-Place Upgrade**\n> (direct in-situ rule replacement, immediate enforcement, zero extra quota) and\n> **Preview Mode** (preview rules deployed at lower numeric priority numbers\n> with `preview = true`, zero risk of blocking traffic, allows telemetry\n> inspection in Cloud Logging before cutover). 2. **Handling Policy Audit\n> Inquiries**: When asked to audit or inspect a policy (such as\n> `'ecommerce-waf'`), if policy JSON is not provided or `gcloud describe` cannot\n> reach Google Cloud resources, immediately provide the `gcloud compute\n> security-policies describe POLICY_NAME --format=json` command and guide the\n> user through the audit checks: - Check for legacy OWASP 3.0 \/ 3.3 rulesets\n> (`sqli-stable`, `xss-stable`, `rce-stable`, `methodenforcement-stable`, or\n> `evaluatePreconfiguredExpr`). - Report in-scope WAF rules versus pass-through\n> custom rules (such as IP allowlists `SRC_IPS_V1`, rate limiting, or default\n> rules `priority: 2147483647`). - Highlight signature count expansions under\n> CRS 4.22 (for example, RCE expanding from 11\/15 to 44 signatures; SQLi\n> expanding to 60 signatures).\n\nWhen interacting with a customer to upgrade a Cloud Armor security policy,\nexecute this 5-step workflow:\n\n1.  **Discover and Fetch**: Identify the target security policy and fetch its\n    JSON definition.\n2.  **Audit and Classify Risk**: Inspect rules, signature count expansions, and\n    operational risk levels.\n3.  **Confirm Mode and Method Risk**: Align with the customer on Preview Mode\n    versus In-Place Upgrade, method enforcement risk, and quota or priority\n    constraints.\n4.  **Transform Rules**: Translate ruleset names, CEL expressions, signature\n    IDs, and `preconfiguredWafConfig` exclusions to CRS 4.22.\n5.  **Execute and Verify**: Apply the upgrade via `gcloud` and verify telemetry\n    in Cloud Logging.\n\n### Step 1: Policy Discovery and Ingestion\n\n1.  Identify the target security policy name and Google Cloud project.\n2.  Fetch the current policy definition via `gcloud`:\n\n    ```bash\n    gcloud compute security-policies describe POLICY_NAME --project=PROJECT_ID --format=\"json\"\n    ```\n\n    *If policy JSON is not provided or executing in conversational mode, provide\n    the `gcloud describe` command and outline the audit criteria below.*\n\n3.  Inspect the `rules` list:\n\n    -   Identify in-scope WAF rules: calls to `evaluatePreconfiguredWaf` or\n        `evaluatePreconfiguredExpr` using legacy 3.0 \/ 3.3 rulesets\n        (`sqli-stable`, `xss-stable`, `rce-stable`, `methodenforcement-stable`,\n        etc.).\n    -   Identify out-of-scope rules: pass-through custom rules (such as pure IP\n        allowlists `SRC_IPS_V1`, rate limiting, header matches without WAF\n        calls, or default rules `priority: 2147483647`). Pass these through\n        unchanged.\n    -   Highlight signature coverage expansions (for example, RCE expanding from\n        11\/15 to 44 signatures; SQLi expanding to 60 signatures in CRS 4.22).\n\n### Step 2: Audit and Risk Classification\n\nEvaluate each in-scope rule against standard operational risk categories:\n\n<!-- mdformat off -->\n\n| Risk Level | Impact Category | Criteria and Recommended Action |\n| :--- | :--- | :--- |\n| \ud83d\udd34 **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. |\n| \ud83d\udfe1 **Medium Risk** | **Attention Required** | Behavioral shifts that should be validated in Preview Mode before enforcement:<br>\u2022 **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>\u2022 **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>\u2022 **Custom Filter Continuity**: Preserved custom header\/cookie\/query\/IP conditions combined with WAF calls. |\n| \ud83d\udfe2 **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). |\n| \u26aa **No Action** | **Pass-Through** | Non-OWASP rules (pure IP allowlist\/denylist, rate limiting, default rule). Carried over unchanged. |\n\n<!-- mdformat on -->\n\n### Step 3: Upgrade Mode Selection and User Alignment\n\nEngage the customer with findings before applying changes:\n\n1.  **Report Findings**: State how many WAF rules will be upgraded, signature\n    coverage expansions, and any deprecated signatures being retired.\n2.  **Method Enforcement Warning**: If `methodenforcement` is present, warn: >\n    *\"Notice: Method Enforcement in CRS 4.22 permits only GET, HEAD, POST, and\n    OPTIONS. If your application handles REST API updates (PUT, PATCH, DELETE),\n    these methods will be blocked with HTTP 403. Would you like to add an\n    exemption for API paths or opt out of rule id911100?\"*\n3.  **Explain Differences Between Modes**:\n    -   **Preview Mode (Recommended)**: Keeps existing legacy rules actively\n        enforcing while deploying corresponding upgraded CRS 4.22 preview rules\n        with `preview = true` at a lower numeric priority number (higher\n        evaluation priority, for example, `PRIORITY - 5`). Traffic is evaluated\n        first by preview rules and logged to Cloud Logging without blocking,\n        ensuring zero risk of downtime or false positives prior to cutover.\n        Requires sufficient quota under the 200-rule limit.\n    -   **In-Place Upgrade**: Directly modifies the CEL expressions and\n        `preconfiguredWafConfig` on existing rule priority numbers in-situ.\n        Immediate enforcement with zero additional rule overhead, but carries\n        cutover risk if new signatures or method enforcement block valid\n        traffic.\n4.  **Quota Guardrail (200 Rules)**:\n    -   Calculate projected rule count: `current_total_rules +\n        in_scope_waf_rules`.\n    -   If projected count > 200, alert the customer: > *\"Cloud Armor enforces a\n        maximum limit of 200 rules per security policy. Deploying in Preview\n        Mode would require PROJECTED_COUNT rules. The upgrade cannot proceed\n        in Preview Mode. We must either perform an In-Place Upgrade or\n        consolidate rules.\"*\n5.  **Priority Spacing Guardrail (Preview Mode)**:\n    -   If an in-scope WAF rule at `PRIORITY` immediately follows another rule\n        at `PREV_PRIORITY` with no free integer priority slot between them\n        (for example, `999` and `1000`, or a WAF rule at priority `0`), alert\n        the customer: > *\"Rule PRIORITY cannot be deployed in Preview Mode\n        because the preceding rule at priority PREV_PRIORITY leaves no open\n        priority number between PREV_PRIORITY and PRIORITY (and placing the\n        preview rule above PREV_PRIORITY would change evaluation order). To use\n        Preview Mode, please readjust your rule priorities to leave at least one\n        open priority slot before PRIORITY, or choose an In-Place Upgrade.\"*\n    -   **Do NOT automatically re-number existing customer rules**: Because rule\n        priorities act as primary identifiers in Cloud Armor and are often tied\n        to Terraform\/IaC resources and SIEM alerting filters, never silently\n        shift existing customer rule priorities to make room. If the customer\n        explicitly asks you to readjust their rule priorities for them, first\n        warn them about potential Terraform\/IaC state drift and confirm the\n        exact new priority numbers before executing any priority changes.\n\n### Step 4: Rule Transformation Logic\n\n#### A. Ruleset Name Translation\n\nTranslate legacy ruleset names according to the mapping table in\n[ruleset_mappings.md](references\/ruleset_mappings.md):\n\n-   Stable: `sqli-stable` to `sqli-v422-stable`, `rce-stable` to\n    `rce-v422-stable`\n-   Canary: `sqli-canary` to `sqli-v422-canary`\n-   3.3 Stable: `sqli-v33-stable` to `sqli-v422-stable`, `nodejs-v33-stable`\n    to `generic-v422-stable`\n\n#### B. CEL Opt-Out and Opt-In Translation\n\n-   Legacy `evaluatePreconfiguredExpr(ruleset, ['id1', 'id2'])` is strictly an\n    **opt-out (disabled)** list.\n-   Convert to native 4.22 syntax:\n\n    ```cel\n    evaluatePreconfiguredWaf('sqli-v422-stable', {'opt_out_rule_ids': ['owasp-crs-v042200-id942120-sqli']})\n    ```\n-   Remap signature IDs: `owasp-crs-v030001-idSIGNATURE_ID-GROUP` to\n    `owasp-crs-v042200-idSIGNATURE_ID-GROUP`. *(Exception: Standalone CVE\n    signatures such as `cve-canary` signatures `owasp-crs-v030001-id*-cve` and\n    `google-mrs-*` retain their original IDs and must not be remapped to\n    `v042200` or dropped).*\n-   Drop all 15 deprecated CRS 3.0\/3.3 signature numbers (`981172`, `981173`,\n    `980130`, `949110`; SQLi: `942110`; RCE: `932100`, `932105`, `932106`,\n    `932110`, `932115`, `932150`; Scanner Detection: `913101`, `913102`,\n    `913110`, `913120`).\n\n#### C. Fine-Tuning (`preconfiguredWafConfig`)\n\nFor rules with structured `preconfiguredWafConfig.exclusions[]`:\n\n-   Update `targetRuleSet` to the CRS 4.22 equivalent.\n-   Remap `targetRuleIds` to `v042200` and drop deprecated IDs. **Warning**: If\n    an exclusion's `targetRuleIds` list becomes empty (`[]`) after dropping\n    retired IDs, remove the entire exclusion entry rather than leaving\n    `targetRuleIds: []` (otherwise an empty `targetRuleIds` list exempts the\n    entire ruleset).\n-   Carry over all field exclusions (`requestHeadersToExclude`,\n    `requestCookiesToExclude`, `requestQueryParamsToExclude`,\n    `requestUrisToExclude`, `requestBodiesToExclude`) and match operators\n    without modification.\n-   Details in [fine_tuning_and_cel.md](references\/fine_tuning_and_cel.md).\n\n### Step 5: Execution Delivery and Verification\n\n#### Delivering In-Place Upgrade\n\nExecute `gcloud compute security-policies rules update`:\n\n```bash\ngcloud compute security-policies rules update PRIORITY \\\n  --security-policy=\"POLICY_NAME\" \\\n  --project=PROJECT_ID \\\n  --expression=\"UPGRADED_EXPRESSION\"\n```\n\n#### Delivering Preview Mode Upgrade\n\nDeploy preview rules at a numeric priority strictly between the immediately\npreceding rule and `ENFORCED_PRIORITY` (`PREV_PRIORITY < PREVIEW_PRIORITY <\nENFORCED_PRIORITY`) using `rules create`:\n\n```bash\ngcloud compute security-policies rules create PREVIEW_PRIORITY \\\n  --security-policy=\"POLICY_NAME\" \\\n  --project=PROJECT_ID \\\n  --expression=\"UPGRADED_EXPRESSION\" \\\n  --action=\"ACTION\" \\\n  --preview \\\n  --description=\"PREVIEW: Upgraded CRS 4.22 Rule for Priority ENFORCED_PRIORITY\"\n```\n\n#### Telemetry Verification in Cloud Logging\n\nInstruct the customer to inspect preview logs before cutover:\n\n```bash\ngcloud logging read '\n  resource.type=\"http_load_balancer\" AND\n  jsonPayload.enforcedSecurityPolicy.name=\"POLICY_NAME\" AND\n  jsonPayload.previewSecurityPolicy.matchedRulePriority:*\n' --project=PROJECT_ID --limit=20\n```\n\n--------------------------------------------------------------------------------\n\n## Critical Gotchas and Domain Rules\n\n1.  **`evaluatePreconfiguredExpr` is NEVER Opt-In**: The array in legacy\n    `evaluatePreconfiguredExpr` was strictly an exclusion (opt-out) list.\n    Treating it as opt-in would inadvertently disable all other signatures in\n    that ruleset!\n2.  **Never Re-introduce Deprecated Signatures**: All 15 retired CRS 3.0\/3.3\n    signature numbers (`981172`, `981173`, `980130`, `949110`; SQLi: `942110`;\n    RCE: `932100`, `932105`, `932106`, `932110`, `932115`, `932150`; Scanner\n    Detection: `913101`, `913102`, `913110`, `913120`) were removed in CRS 4.22.\n    Keeping them in `opt_out_rule_ids` or `targetRuleIds` causes Cloud Armor API\n    schema rejections.\n3.  **Method Enforcement Defaults**: CRS 4.22 Method Enforcement blocks `PUT`,\n    `PATCH`, and `DELETE`. Never perform a silent in-place upgrade of method\n    enforcement without user confirmation.\n4.  **Preview Rule Priorities and Cutover Safety**: Cloud Armor evaluates rules\n    in ascending priority order (`0` to `2147483647`). A preview rule must\n    evaluate *before* the enforcing rule it previews, but *after* any preceding\n    rule (`PREV_PRIORITY < PREVIEW_PRIORITY < ENFORCED_PRIORITY`) so it never\n    crosses intervening `allow` or custom rules. During cutover to full\n    enforcement, update the original `ENFORCED_PRIORITY` rule in-place to CRS\n    4.22 and delete `PREVIEW_PRIORITY` rather than promoting `PREVIEW_PRIORITY`\n    in place.\n5.  **Atomic Import for Structured Exclusions**: When a policy contains complex\n    `preconfiguredWafConfig` blocks, prefer exporting the policy JSON,\n    transforming it, and applying it via `gcloud compute security-policies\n    import` to ensure atomic updates.\n6.  **Preserve Standalone CVE Signatures (`cve-canary`)**: `cve-canary` is an\n    out-of-band rule for specific vulnerabilities (for example, Log4j\n    CVE-2021-44228 \/ CVE-2021-45046, React RCE CVE-2025-55182). Its signature\n    IDs (`owasp-crs-v030001-id044228-cve`, `id144228-cve`, `id244228-cve`,\n    `id344228-cve`) are valid and retain the `v030001` prefix. Only upgrade the\n    syntax to `evaluatePreconfiguredWaf('cve-canary', ...)`; never rewrite them\n    to `v042200` or drop them as deprecated.\n\n--------------------------------------------------------------------------------\n\n## References and Resources\n\n-   [ruleset_mappings.md](references\/ruleset_mappings.md): Full CRS 3.0 \/ 3.3 to\n    4.22 ruleset mapping, sensitivity levels, and signature counts.\n-   [fine_tuning_and_cel.md](references\/fine_tuning_and_cel.md): CEL syntax\n    options, structured `preconfiguredWafConfig` exclusions, and method\n    enforcement mitigations.\n-   [gcloud_recipes.md](references\/gcloud_recipes.md): Copy-pasteable `gcloud`\n    recipes for audit, preview mode, and Cloud Logging queries.\n-   [upgrade_policy.py](scripts\/upgrade_policy.py): Deterministic CLI helper\n    script.\n-   [contributing.md](references\/contributing.md): Domain and code invariants\n    for maintaining this skill.\n","use_cases":["Upgrade legacy OWASP 3.0\/3.3 rulesets to the latest CRS 4.22 or newer versions.","Audit and classify in-scope WAF rules versus pass-through custom rules.","Generate preview rules for testing before cutover."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/cloud-armor-crs-rule-upgrader\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T12:42:54.000000Z","updated_at":"2026-11-17T05:10:16.000000Z","seo_title":"Cloud Armor CRS Rule Upgrader","seo_description":"Upgrade Cloud Armor security policies to the latest OWASP Core Rule Set (CRS) versions with in-place or preview mode options.","seo_keywords":["Cloud Armor CRS upgrade","OWASP Core Rule Set upgrade","Cloud Armor rule migration","Security policy upgrade","Preview mode upgrade"]}}