Skip to main content

octorules-google

Google Cloud Armor provider for octorules — manages Cloud Armor security policy rules as YAML.

Installation

pip install octorules-google

This installs octorules (core), octorules-google, and cel-python for CEL expression validation in the linter. The provider is auto-discovered — no class: needed in config.

Configuration

providers:
  google:
    project: my-gcp-project
  rules:
    directory: ./rules

zones:
  my-security-policy:
    sources:
      - rules

Each zone name maps to a Cloud Armor security policy name. The provider resolves policy names at runtime.

Authentication

Authentication uses Application Default Credentials — no token is needed in the config file. Common options:

  • gcloud auth application-default login — for local development
  • Service account key: set GOOGLE_APPLICATION_CREDENTIALS to the JSON key path
  • Workload Identity (GKE, Cloud Run): automatic

Required IAM permissions:

  • compute.securityPolicies.get, compute.securityPolicies.update — for rule operations
  • compute.securityPolicies.list — for zone discovery
  • compute.securityPolicies.addRule, compute.securityPolicies.removeRule — for rule changes

Provider settings

All settings below go under the provider section (e.g. providers.google).

Key Default Description
project GCLOUD_PROJECT env var GCP project ID (required)
timeout 30 API timeout in seconds

Safety thresholds are configured under safety: (framework-owned, not forwarded to the provider):

Key Default Description
safety.delete_threshold 30.0 Max % of rules that can be deleted
safety.update_threshold 30.0 Max % of rules that can be updated
safety.min_existing 3 Min rules before thresholds apply

Examples

The examples/ directory contains a working single-provider config.yaml plus rules/my-security-policy.yaml demonstrating every supported phase and key. Copy it as a starting point.

Supported features

Feature Status Notes
Phase rules (4 phases) Supported Security policy rules
Policy settings Supported Adaptive protection, DDoS config, default rule action
Automatic tier detection Supported Detects standard, plus, or enterprise from policy config (no manual setting needed)
Custom rulesets Not supported —
Lists Not supported Use inline IP ranges in match config
Page Shield Not supported —
Zone discovery (list_zones) Supported Lists security policies
Account-level scopes Not supported —
Audit IP extraction (octorules audit) Supported src_ip_ranges + inIpRange() CEL

Phase mapping

octorules phase Cloud Armor concept
google.custom_rules Custom rules (IP match, geo match, CEL expressions)
google.rate_rules Rate-limiting rules (throttle / rate_based_ban)
google.preconfigured_rules Preconfigured WAF rules (OWASP ModSecurity, etc.)
google.redirect_rules Redirect rules (302 response)

Rules are identified by their integer priority (mapped to ref in octorules). All phases require action to be specified explicitly (no default action).

Rule format

Cloud Armor rules nest under a single google: block. The ref field maps to the rule's integer priority:

# rules/my-security-policy.yaml
google:
  custom_rules:
    - ref: "1000"
      description: "Block known bad IPs"
      action: deny(403)
      match:
        versioned_expr: SRC_IPS_V1
        config:
          src_ip_ranges:
            - "1.2.3.4/32"
            - "5.6.7.0/24"

    - ref: "2000"
      description: "Rate limit API endpoints"
      action: throttle
      match:
        expr:
          expression: "request.path.startsWith('/api/')"
      rate_limit_options:
        conform_action: allow
        exceed_action: deny-429
        rate_limit_threshold:
          count: 100
          interval_sec: 60

  preconfigured_rules:
    - ref: "3000"
      description: "OWASP SQL injection protection"
      action: deny(403)
      match:
        expr:
          expression: "evaluatePreconfiguredWaf('sqli-v33-stable')"

  policy_settings:
    ddosProtectionConfig:
      ddosProtection: ADVANCED

CEL expressions

Cloud Armor uses CEL (Common Expression Language) for advanced match expressions. Examples:

# IP-based matching
match:
  expr:
    expression: "inIpRange(origin.ip, '10.0.0.0/8')"

# Header matching
match:
  expr:
    expression: "request.headers['user-agent'].contains('BadBot')"

# Geo-based matching
match:
  expr:
    expression: "origin.region_code == 'US'"

Rule-level metadata: All Cloud Armor rules support the octorules: key for per-rule metadata — ignored: true to skip a rule during plan/sync, and included/excluded to restrict rules to specific providers. See octorules core docs for syntax and examples.

Linting

88 Cloud Armor-specific lint rules (GA prefix) covering structure, expressions, actions, rate limiting, redirects, sub-structure validation, and cross-rule analysis:

Prefix Category Rules
GA001-GA027 Structure 8
GA100-GA113 Priority / cross-rule / expression style 11
GA200-GA201 Action 2
GA300-GA329 Match / expression / CEL / CIDR 27
GA400-GA433 Rate limit / redirect / action parameters 31
GA500-GA503 Description / cross-rule checks 4
GA526 Match (continued) 1
GA600-GA603 Best practice 4
octorules lint --config config.yaml

Lint rules are registered automatically when octorules-google is installed. CEL expression validation uses cel-python. See docs/lint.md for the full rule reference with examples.

Known limitations

  • Non-atomic updates: Cloud Armor does not support atomic bulk rule replacement. put_phase_rules patches existing rules in place, adds new rules, then removes stale rules — so the policy never has fewer rules than intended. Each API call is retried for transient errors with exponential backoff. If an operation fails after retries, partial progress is logged and the next sync will reconcile.
  • Policy creation/deletion: octorules-google manages rules within existing security policies. Creating or deleting policies (and attaching them to backend services) should be done via gcloud or Terraform.
  • Policy creation is out of scope, policy settings are not. Policy-level settings (adaptive_protection_config, advanced_options_config, ddos_protection_config, default_rule_action, recaptcha_options_config) are managed under google: policy_settings: in the zone file. Anything above that level — creating or deleting the policy itself — belongs to gcloud or Terraform.

Note: Per-rule rate limiting fields (enforceOnKey, enforceOnKeyConfigs, banDurationSec), header actions (headerAction), and CEL functions like evaluateThreatIntelligence() are already supported — they pass through as-is in the rule dict.

Development

git clone git@github.com:doctena-org/octorules-google.git
cd octorules-google
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install

License

octorules-google is licensed under the Apache License 2.0.

Metadata

Release files for octorules-google 0.13.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for octorules-google 0.13.1
File Size Uploaded Provenance
octorules_google-0.13.1.tar.gz 89.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for octorules-google 0.13.1
File Interpreter ABI Platform
octorules_google-0.13.1-py3-none-any.whl Python 3 none any Details

Total release size: 139.1 kB

Release files / octorules_google-0.13.1.tar.gz

Download URL octorules_google-0.13.1.tar.gz
Size 89.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1108a358ffc78c2acaa1691e0f9dcd62a56084560855f99b89360c56a2f5377a
BLAKE2b-256 checksum
How to use checksums
8f5a3b2b85b22036b5b9fb9bb43e24884c016b4cbf362e586f4ce20a40e0e24f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / octorules_google-0.13.1-py3-none-any.whl

Download URL octorules_google-0.13.1-py3-none-any.whl
Size 50.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ac6ac33d36eb97926ef7297379a155885c0b0950db8fd98162e7c1cba57aead
BLAKE2b-256 checksum
How to use checksums
b12ea4e948647cb613b11311e54dd1fb0ebd4def75ce8af2a2891e330a786ae7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Security for octorules-google 0.13.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for octorules_google-0.13.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page