Loading...
Loading...
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.
npx skill4agent add google/skills cloud-armor-crs-rule-upgradergcloudgcloudgcloud config set project PROJECT_ID
gcloud billing projects describe PROJECT_ID --format="value(billingEnabled)"gcloud services enable compute.googleapis.com logging.googleapis.comgcloud auth logingcloud auth application-default loginGOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"roles/compute.securityAdminroles/compute.securityViewerroles/logging.viewer--region=us-central1gcloud config set compute/region us-central1--previewgcloud compute security-policies rules delete PREVIEW_PRIORITY --security-policy="POLICY_NAME"gcloud compute security-policies delete TEST_POLICY_NAME# In-Place Upgrade (Report Summary)
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=in-place --format=report
# In-Place Upgrade (Output gcloud commands)
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=in-place --format=gcloud
# Preview Mode Upgrade (Generates preview rules at priority - 5)
python3 scripts/upgrade_policy.py /path/to/policy.json --mode=preview --format=gcloud
# Direct stdin piping from gcloud describe
gcloud compute security-policies describe POLICY_NAME --format=json | \
python3 scripts/upgrade_policy.py - --mode=preview --format=json[!IMPORTANT] Mandatory Agent Response Behaviors: 1. Explain Both Upgrade Modes: Whenever discussing an upgrade (even if the user asks specifically about Preview Mode or In-Place), ALWAYS explain BOTH In-Place Upgrade (direct in-situ rule replacement, immediate enforcement, zero extra quota) and Preview Mode (preview rules deployed at lower numeric priority numbers with, zero risk of blocking traffic, allows telemetry inspection in Cloud Logging before cutover). 2. Handling Policy Audit Inquiries: When asked to audit or inspect a policy (such aspreview = true), if policy JSON is not provided or'ecommerce-waf'cannot reach Google Cloud resources, immediately provide thegcloud describecommand and guide the user through the audit checks: - Check for legacy OWASP 3.0 / 3.3 rulesets (gcloud compute security-policies describe POLICY_NAME --format=json,sqli-stable,xss-stable,rce-stable, ormethodenforcement-stable). - Report in-scope WAF rules versus pass-through custom rules (such as IP allowlistsevaluatePreconfiguredExpr, rate limiting, or default rulesSRC_IPS_V1). - Highlight signature count expansions under CRS 4.22 (for example, RCE expanding from 11/15 to 44 signatures; SQLi expanding to 60 signatures).priority: 2147483647
preconfiguredWafConfiggcloudgcloudgcloud compute security-policies describe POLICY_NAME --project=PROJECT_ID --format="json"gcloud describerulesevaluatePreconfiguredWafevaluatePreconfiguredExprsqli-stablexss-stablerce-stablemethodenforcement-stableSRC_IPS_V1priority: 2147483647| Risk Level | Impact Category | Criteria and Recommended Action |
|---|---|---|
| 🔴 High Risk | Breaking Change | Immediate risk of blocking |
| : : : legitimate production traffic : | ||
| : : : upon cutover. Example: : | ||
: : : | ||
: : : only permits | ||
: : : | ||
: : : | ||
| : : : requests. Requires customer : | ||
| : : : confirmation and API : | ||
| : : : path/signature exemptions. : | ||
| 🟡 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 : | ||
: : : ( | ||
: : : | ||
: : : RCE: | ||
: : : | ||
: : : | ||
: : : | ||
: : : | ||
| : : : 4.22.<br>• **Custom Filter : | ||
| : : : Continuity**: Preserved custom : | ||
| : : : header/cookie/query/IP : | ||
| : : : conditions combined with WAF : | ||
| : : : calls. : | ||
| 🟢 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). : | ||
| ⚪ No Action | Pass-Through | Non-OWASP rules (pure IP |
| : : : allowlist/denylist, rate : | ||
| : : : limiting, default rule). : | ||
| : : : Carried over unchanged. : |
methodenforcementpreview = truePRIORITY - 5preconfiguredWafConfigcurrent_total_rules + in_scope_waf_rulesPRIORITYPREV_PRIORITY99910000sqli-stablesqli-v422-stablerce-stablerce-v422-stablesqli-canarysqli-v422-canarysqli-v33-stablesqli-v422-stablenodejs-v33-stablegeneric-v422-stableevaluatePreconfiguredExpr(ruleset, ['id1', 'id2'])evaluatePreconfiguredWaf('sqli-v422-stable', {'opt_out_rule_ids': ['owasp-crs-v042200-id942120-sqli']})owasp-crs-v030001-idSIGNATURE_ID-GROUPowasp-crs-v042200-idSIGNATURE_ID-GROUPcve-canaryowasp-crs-v030001-id*-cvegoogle-mrs-*v042200981172981173980130949110942110932100932105932106932110932115932150913101913102913110913120preconfiguredWafConfigpreconfiguredWafConfig.exclusions[]targetRuleSettargetRuleIdsv042200targetRuleIds[]targetRuleIds: []targetRuleIdsrequestHeadersToExcluderequestCookiesToExcluderequestQueryParamsToExcluderequestUrisToExcluderequestBodiesToExcludegcloud compute security-policies rules updategcloud compute security-policies rules update PRIORITY \
--security-policy="POLICY_NAME" \
--project=PROJECT_ID \
--expression="UPGRADED_EXPRESSION"ENFORCED_PRIORITYPREV_PRIORITY < PREVIEW_PRIORITY < ENFORCED_PRIORITYrules creategcloud compute security-policies rules create PREVIEW_PRIORITY \
--security-policy="POLICY_NAME" \
--project=PROJECT_ID \
--expression="UPGRADED_EXPRESSION" \
--action="ACTION" \
--preview \
--description="PREVIEW: Upgraded CRS 4.22 Rule for Priority ENFORCED_PRIORITY"gcloud logging read '
resource.type="http_load_balancer" AND
jsonPayload.enforcedSecurityPolicy.name="POLICY_NAME" AND
jsonPayload.previewSecurityPolicy.matchedRulePriority:*
' --project=PROJECT_ID --limit=20evaluatePreconfiguredExprevaluatePreconfiguredExpr981172981173980130949110942110932100932105932106932110932115932150913101913102913110913120opt_out_rule_idstargetRuleIdsPUTPATCHDELETE02147483647PREV_PRIORITY < PREVIEW_PRIORITY < ENFORCED_PRIORITYallowENFORCED_PRIORITYPREVIEW_PRIORITYPREVIEW_PRIORITYpreconfiguredWafConfiggcloud compute security-policies importcve-canarycve-canaryowasp-crs-v030001-id044228-cveid144228-cveid244228-cveid344228-cvev030001evaluatePreconfiguredWaf('cve-canary', ...)v042200preconfiguredWafConfiggcloud