Skip to main content

octorules-aws

AWS WAF v2 provider for octorules — manages AWS WAF Web ACL rules, Rule Groups, and IP Sets as YAML.

Installation

pip install octorules-aws

This installs octorules (core) and octorules-aws. The provider is auto-discovered — no class: needed in config.

Configuration

providers:
  aws:
    region: us-east-1
    waf_scope: REGIONAL
  rules:
    directory: ./rules

zones:
  my-web-acl:
    sources:
      - rules

Each zone name maps to an AWS WAF Web ACL name. The provider resolves Web ACL names to IDs at runtime.

Authentication

AWS credentials are resolved via the standard boto3 credential chain — no token is needed in the config file. Common options:

  • Environment variables: AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY
  • Shared credentials file: ~/.aws/credentials
  • IAM role (EC2, ECS, Lambda): automatic

Required IAM permissions:

  • wafv2:GetWebACL, wafv2:UpdateWebACL — for phase rule operations
  • wafv2:ListWebACLs — for zone ID resolution and zone discovery
  • wafv2:GetRuleGroup, wafv2:UpdateRuleGroup, wafv2:ListRuleGroups — for custom rulesets (Rule Groups)
  • wafv2:GetIPSet, wafv2:UpdateIPSet, wafv2:CreateIPSet, wafv2:DeleteIPSet, wafv2:ListIPSets — for lists (IP Sets)

Provider settings

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

Key Default Description
region AWS_DEFAULT_REGION or us-east-1 AWS region
waf_scope AWS_WAF_SCOPE or REGIONAL REGIONAL or CLOUDFRONT
max_retries 2 API retry count
timeout 30 API timeout in seconds
wcu_limit 1500 Web ACL WCU capacity for WA340 lint check. Override for accounts with custom limits (up to 5,000).

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-web-acl.yaml demonstrating every supported phase and key using the nested aws: format. Copy it as a starting point.

Zone files nest all AWS WAF sections under a single aws: block.

Supported features

Feature Status AWS concept
Phase rules (4 phases) Supported Web ACL rules
Custom rulesets Supported Rule Groups
Lists (IP) Supported IP Sets
Lists (regex) Supported Regex Pattern Sets
Web ACL settings Supported DefaultAction, ChallengeConfig, CaptchaConfig, TokenDomains, AssociationConfig, CustomResponseBodies
Page Shield Not supported
Zone discovery (list_zones) Supported Lists Web ACLs
Account-level scopes Not supported
Audit IP extraction (octorules audit) Supported IPSet reference resolution

Phase mapping

octorules phase AWS WAF concept
aws.waf_custom_rules Custom rules (IP match, geo match, byte match, etc.)
aws.waf_rate_rules Rate-based rules
aws.waf_managed_rules Managed rule group references
aws.waf_rule_group_rules Rule group references

All phases require action to be specified explicitly (no default action).

Rule-level metadata: All AWS WAF 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.

Custom rulesets (Rule Groups)

AWS WAF Rule Groups map to octorules custom rulesets. octorules manages the full lifecycle: create, update rules, and delete.

Managing an existing Rule Group

# rules/my-web-acl.yaml
aws:
  custom_rulesets:
    - id: abcd1234-5678-9012-3456-789012345678
      name: My Rule Group
      phase: aws_waf_custom
      rules:
        - ref: block-bad-ips
          Action:
            Block: {}
          Statement:
            IPSetReferenceStatement:
              ARN: arn:aws:wafv2:us-east-1:123456789012:regional/ipset/blocked/efgh5678
          VisibilityConfig:
            SampledRequestsEnabled: true
            CloudWatchMetricsEnabled: true
            MetricName: BlockBadIPs

Creating a new Rule Group

Omit the id field and add capacity to create a new Rule Group:

aws:
  custom_rulesets:
    - name: Block Bad Actors
      capacity: 100
      phase: aws_waf_custom
      rules:
        - ref: block-scanner
          Action:
            Block: {}
          Statement:
            ByteMatchStatement:
              SearchString: "BadBot"
              FieldToMatch:
                SingleHeader:
                  Name: user-agent
              PositionalConstraint: CONTAINS
              TextTransformations:
                - Priority: 0
                  Type: LOWERCASE
          VisibilityConfig:
            SampledRequestsEnabled: true
            CloudWatchMetricsEnabled: true
            MetricName: BlockScanner

capacity is an AWS WAF concept — an immutable budget (1-5000) that limits rule complexity within the Rule Group. It cannot be changed after creation. If you need more capacity, delete and recreate the Rule Group with a higher value.

How it works:

  • The name field is the identity key. Rule Groups are matched between YAML and AWS by name.
  • The presence of a custom_rulesets: key means ALL Rule Groups are managed — Rule Groups in AWS not in YAML are planned for deletion.
  • If the custom_rulesets: key is absent, Rule Groups are ignored entirely.
  • id is optional: present for existing Rule Groups, absent for new ones.
  • After creation, use octorules dump to export the assigned id back to YAML.

Lists (IP Sets & Regex Pattern Sets)

AWS WAF IP Sets and Regex Pattern Sets map to octorules lists. Add a lists section under aws::

# rules/my-web-acl.yaml
aws:
  lists:
    - name: blocked-ips
      kind: ip
      description: "Known bad IPs"
      items:
        - ip: "1.2.3.4/32"
        - ip: "10.0.0.0/8"

    - name: bad-ua-patterns
      kind: regex
      description: "Bad user-agent patterns"
      items:
        - pattern: "BadBot.*"
        - pattern: "EvilCrawler/\\d+"

IP lists (kind: ip) map to AWS WAF IP Sets. Regex lists (kind: regex) map to AWS WAF Regex Pattern Sets and are referenced via RegexPatternSetReferenceStatement.

Note: ASN, hostname, and redirect list kinds are not available for AWS WAF.

Linting

96 AWS-specific lint rules (WA prefix) covering structure, actions, statements, and cross-rule analysis:

Prefix Category Rules
WA001–WA003, WA010, WA020–WA024, WA154 Structure 10
WA025 Style 1
WA100–WA102 Priority 3
WA004–WA005, WA200–WA201, WA350–WA357 Action 12
WA400–WA402, WA500–WA501 Visibility 5
WA156–WA157, WA159–WA161, WA300–WA325, WA328, WA330–WA332, WA334–WA339, WA341–WA348 Statement 49
WA158, WA162–WA167, WA326–WA327, WA340, WA520, WA603 Cross-rule 12
WA600–WA602 Best practice 3
octorules lint --config config.yaml

Lint rules are registered automatically when octorules-aws is installed. See docs/lint.md for the full rule reference with examples.

Note: WA500 checks for duplicate MetricName within a single phase. WA501 checks across phases — AWS WAF requires MetricName to be unique across all rules in a Web ACL.

Known limitations

  • Web ACL creation/deletion: octorules-aws manages rules and Rule Groups within existing Web ACLs. Creating or deleting Web ACLs must be done via the AWS console, CLI, or Terraform.
  • Concurrent updates: Rule updates use AWS WAF optimistic locking (LockToken). Stale lock errors are retried automatically (up to 3 attempts with linear backoff). If the same Web ACL is updated by multiple writers targeting the same phase simultaneously, the last writer wins.
  • Rule Group capacity is immutable: AWS WAF sets Rule Group capacity at creation time. To change capacity, delete and recreate the Rule Group with the new value.

Development

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

License

octorules-aws is licensed under the Apache License 2.0.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

octorules_aws-0.12.0.tar.gz (96.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

octorules_aws-0.12.0-py3-none-any.whl (54.6 kB view details)

Uploaded Python 3

File details

Details for the file octorules_aws-0.12.0.tar.gz.

File metadata

  • Download URL: octorules_aws-0.12.0.tar.gz
  • Upload date:
  • Size: 96.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for octorules_aws-0.12.0.tar.gz
Algorithm Hash digest
SHA256 8d7e104041dcdfa4d354c24b59e2b7f9c03e0ab6557518a451451f61065af2ef
MD5 606f57a6ead17a5045b4d64aee2fada7
BLAKE2b-256 0759d5caecfaaae541913d84f8940dd100bbd9767adf4da3a854cfdf7c5dd6ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for octorules_aws-0.12.0.tar.gz:

Publisher: release.yaml on doctena-org/octorules-aws

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file octorules_aws-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: octorules_aws-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 54.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for octorules_aws-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c71a552a64e23e2903171c28a84eecac7f372574eb7cbba5d324e73cda8aa710
MD5 6a348b0e7b08579bb6b9dec4cbffd910
BLAKE2b-256 707d139ccfd581ff48f2ab5090444b7a3af4699063e2ffe2acf48c9816d8b1e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for octorules_aws-0.12.0-py3-none-any.whl:

Publisher: release.yaml on doctena-org/octorules-aws

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.14.0

2 files

0.13.0

2 files

This release

0.12.0 This release

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.9

2 files

0.7.8

2 files

0.7.7

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

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