Skip to content

feat(infra): prod WAF managed rule groups — IP reputation blocks, body-inspecting groups count - #949

Merged
athvin merged 1 commit into
mainfrom
issue/921-waf-managed-rules
Nov 9, 2026
Merged

athvin merged 1 commit into
mainfrom
issue/921-waf-managed-rules

Conversation

@athvin

@athvin athvin commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #921

What

Three managed rule groups on er-prod-edge: AWSManagedRulesAmazonIpReputationList in BLOCK at priority 1 (ahead of the rate rules), and AWSManagedRulesCommonRuleSet + AWSManagedRulesKnownBadInputsRuleSet in COUNT at priorities 40/50 (after the rate rules). The header comment's "no managed groups yet" paragraph becomes the decision record for what is there now, including the 931/1500 WCU capacity math.

Why

The reputation list inspects no bodies and its false-positive rate is the lowest of the managed groups; the scanners that found the hostname within minutes of the DNS record are its population, and it sheds them before they spend the rate rules' counts. The body-inspecting groups would reject legitimate traffic blind — this API carries SQL-shaped blocking configuration and arbitrary customer column names — so they count until a week of CountedRequests per rule says what to exclude. Counting AFTER the rate rules makes the counted population exactly the requests that would reach the app.

Proof

terraform validate on envs/prod — Success (1.11.4); terraform fmt clean. No description touched: the WAFv2 character restriction (the 400-at-apply trap from #911) applies to the ACL's description only, which is unchanged; rule names and metric names stay inside the existing [a-z0-9-] style.

Risk & rollback

Risk: the reputation list now BLOCKS — a false positive is a 403 at the edge with no app log, but that list's FP rate is the reason it was chosen to block, and BlockedRequests on its metric plus sampled requests show anything it catches. The two count groups change nothing about request handling. Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: agent · codex session on Athvins-MacBook-Pro · 2026-11-09T01:45:00Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  1. Reputation list in BLOCK at priority 1. 2. The two body-inspecting groups in COUNT at 40/50. 3. Header comment becomes the record. 4. Post-merge: confirm live, leave the tuning half on Prod WAF: add managed rule groups, in COUNT mode first #921.

Discoveries

  • WCU budget: 25 + 700 + 200 + 3 x 2 = 931 of the 1500 default ceiling — no increase needed.
  • The WAFv2 description regex (no section marks, no parens) bites only the ACL-level description; none of the new blocks carries one.

Measurements

Files

  • infra/terraform/envs/prod/edge.tf — three rule blocks + the rewritten WAF header comment.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

terraform plan

1cad304 · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 0 2
dev 0 0 0
prod 0 1 0

Planned with -refresh=false, so this is the config-versus-state diff and
not out-of-band drift. That is a security choice, not a speed one: a refreshing
plan reads secret values, and the plan role is assumable from any PR branch —
which can edit the workflow it runs under. Drift is caught at apply time, which
refreshes fully.

Warning

This plan DESTROYS resources in: core. Merging applies it unattended.
The apply refuses to run unless the merge commit message carries
ALLOW-DESTROY. Retitling is not enough on a single-commit PR — GitHub
uses the commit message there, not the title. Merge with
gh pr merge <n> --squash --subject '<subject> ALLOW-DESTROY'.

core — 0 to add, 0 to change, 2 to DESTROY
data.aws_iam_policy_document.ci_tf_plan_state: Reading...
module.identity_center.data.aws_ssoadmin_instances.this: Reading...
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Reading...
data.aws_iam_policy_document.ci_tf_apply_no_prod_state: Read complete after 0s [id=2395007408]
data.aws_iam_policy_document.ci_tf_plan_state: Read complete after 0s [id=2883378100]
data.aws_iam_policy_document.obs_pod_trust: Reading...
data.aws_iam_policy_document.obs_pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.ci_tf_drift_refresh: Reading...
data.aws_caller_identity.current: Reading...
data.aws_iam_policy_document.ci_tf_drift_refresh: Read complete after 0s [id=2350222434]
data.aws_iam_policy_document.sccache_read: Reading...
module.github_oidc.data.aws_iam_policy_document.trust: Reading...
data.aws_iam_policy_document.sccache_read: Read complete after 0s [id=2701062528]
module.github_oidc.data.aws_iam_policy_document.trust: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.sccache_write: Reading...
data.aws_iam_policy_document.sccache_write: Read complete after 0s [id=786296009]
data.aws_iam_policy_document.cur_delivery: Reading...
data.aws_iam_policy_document.cur_delivery: Read complete after 0s [id=2207400467]
data.aws_iam_policy_document.audit_bucket: Reading...
data.aws_iam_policy_document.sccache_trust_write: Reading...
data.aws_iam_policy_document.ci_tf_drift_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_trust: Reading...
data.aws_iam_policy_document.sccache_trust_write: Read complete after 0s [id=4060172364]
data.aws_iam_policy_document.sccache_trust_read: Reading...
data.aws_iam_policy_document.ci_tf_apply_trust: Read complete after 0s [id=2538345208]
data.aws_iam_policy_document.ci_tf_drift_trust: Read complete after 0s [id=2357770959]
data.aws_iam_policy_document.config_bucket: Reading...
data.aws_iam_policy_document.audit_bucket: Read complete after 0s [id=3031279952]
data.aws_iam_policy_document.ci_tf_plan_trust: Reading...
data.aws_iam_policy_document.ci_tf_plan_trust: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.config_bucket: Read complete after 0s [id=4067691321]
data.aws_iam_policy_document.sccache_trust_read: Read complete after 0s [id=1630650595]
data.aws_iam_policy_document.openobserve: Reading...
data.aws_iam_policy_document.openobserve: Read complete after 0s [id=2662704728]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.github_oidc.data.aws_iam_policy_document.push: Reading...
module.github_oidc.data.aws_iam_policy_document.push: Read complete after 0s [id=2177873069]
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Reading...
data.aws_iam_policy_document.ci_tf_apply_prod_trust: Read complete after 0s [id=3513372776]
module.identity_center.data.aws_ssoadmin_instances.this: Read complete after 0s [id=us-east-2]
module.identity_center.data.aws_identitystore_user.admin: Reading...
module.identity_center.data.aws_identitystore_user.admin: Read complete after 1s [id=b17b2500-e0b1-7046-405b-23c088cf392b]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # cloudflare_r2_bucket.sccache[0] will be destroyed
  # (because index [0] is out of range for count)
  - resource "cloudflare_r2_bucket" "sccache" {
      - account_id    = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
      - creation_date = "2026-11-08T20:59:18.644Z" -> null
      - id            = "er-ci-sccache" -> null
      - jurisdiction  = "default" -> null
      - location      = "ENAM" -> null
      - name          = "er-ci-sccache" -> null
      - storage_class = "Standard" -> null
    }

  # cloudflare_r2_bucket_lifecycle.sccache[0] will be destroyed
  # (because index [0] is out of range for count)
  - resource "cloudflare_r2_bucket_lifecycle" "sccache" {
      - account_id   = "9eefbe6bc92d11b2bb4e962494765a4c" -> null
      - bucket_name  = "er-ci-sccache" -> null
      - jurisdiction = "default" -> null
      - rules        = [
          - {
              - abort_multipart_uploads_transition = {
                  - condition = {
                      - max_age = 86400 -> null
                      - type    = "Age" -> null
                    } -> null
                } -> null
              - conditions                         = {
                    # (1 unchanged attribute hidden)
                } -> null
              - delete_objects_transition          = {
                  - condition = {
                      - max_age = 1209600 -> null
                      - type    = "Age" -> null
                    } -> null
                } -> null
              - enabled                            = true -> null
              - id                                 = "expire-cache-objects" -> null
            },
        ] -> null
    }

Plan: 0 to add, 0 to change, 2 to destroy.

Changes to Outputs:
  - r2_sccache_bucket         = "er-ci-sccache" -> null
  - r2_sccache_endpoint       = "https://9eefbe6bc92d11b2bb4e962494765a4c.r2.cloudflarestorage.com" -> null

Warning: Resource Destruction Considerations

  with cloudflare_r2_bucket_lifecycle.sccache[0],
  on r2.tf line 96, in resource "cloudflare_r2_bucket_lifecycle" "sccache":
  96: resource "cloudflare_r2_bucket_lifecycle" "sccache" {

Applying this resource destruction will remove the resource from the
Terraform state but will not change it in the API. If you would like to
destroy or reset this resource in the API, refer to the documentation for how
to do it manually.
prod — 0 to add, 1 to change
data.aws_iam_policy_document.efs_csi_trust: Reading...
module.network.data.aws_availability_zones.available: Reading...
module.ses.data.aws_region.current: Reading...
data.aws_iam_openid_connect_provider.github: Reading...
data.aws_iam_policy_document.efs_csi_trust: Read complete after 0s [id=819195744]
module.ses.data.aws_region.current: Read complete after 0s [id=us-east-2]
data.aws_caller_identity.current: Reading...
data.aws_iam_policy_document.eso_trust: Reading...
data.aws_iam_policy_document.eso_trust: Read complete after 0s [id=819195744]
module.network.data.aws_region.current: Reading...
data.aws_rds_engine_version.aurora_pg: Reading...
module.network.data.aws_region.current: Read complete after 0s [id=us-east-2]
module.eks.data.aws_iam_policy_document.cluster_trust: Reading...
data.aws_iam_policy_document.pod_trust: Reading...
module.eks.data.aws_iam_policy_document.cluster_trust: Read complete after 0s [id=1029077455]
data.aws_iam_policy_document.pod_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.otel_collector: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Read complete after 0s [id=2851119427]
data.aws_iam_policy_document.otel_collector: Read complete after 0s [id=1193716550]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.lake.data.aws_iam_policy_document.lake_tls_only: Reading...
module.lake.data.aws_iam_policy_document.lake_tls_only: Read complete after 1s [id=3960055703]
data.aws_iam_policy_document.fluent_bit: Reading...
data.aws_iam_policy_document.fluent_bit: Read complete after 0s [id=2978074842]
data.aws_iam_policy_document.eso: Reading...
data.aws_iam_policy_document.eso: Read complete after 0s [id=2178872705]
data.aws_iam_policy_document.lake_access: Reading...
data.aws_iam_policy_document.lake_access: Read complete after 0s [id=3734071059]
data.aws_iam_openid_connect_provider.github: Read complete after 1s [id=arn:aws:iam::797781631727:oidc-provider/token.actions.githubusercontent.com]
module.ses.data.aws_iam_policy_document.send: Reading...
module.ses.data.aws_iam_policy_document.send: Read complete after 0s [id=3767633194]
data.aws_iam_policy_document.ci_deploy_prod_trust: Reading...
data.aws_iam_policy_document.ci_deploy_prod_trust: Read complete after 0s [id=4060172364]
data.aws_rds_engine_version.aurora_pg: Read complete after 1s [id=17.9]
module.network.data.aws_availability_zones.available: Read complete after 1s [id=us-east-2]
data.aws_iam_policy_document.ci_deploy_prod: Reading...
data.aws_iam_policy_document.ci_deploy_prod: Read complete after 0s [id=3634844169]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_wafv2_web_acl.edge will be updated in-place
  ~ resource "aws_wafv2_web_acl" "edge" {
        id                          = "8aff260c-3895-4773-baac-0db11a70e24e"
        name                        = "er-prod-edge"
        tags                        = {
            "Name" = "er-prod-edge"
        }
        # (10 unchanged attributes hidden)

      + rule {
          + name     = "managed-common-ruleset"
          + priority = 40

          + override_action {
              + count {}
            }

          + statement {
              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesCommonRuleSet"
                  + vendor_name = "AWS"
                    # (1 unchanged attribute hidden)
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-edge-common-ruleset"
              + sampled_requests_enabled   = true
            }
        }
      + rule {
          + name     = "managed-ip-reputation"
          + priority = 1

          + override_action {
              + none {}
            }

          + statement {
              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesAmazonIpReputationList"
                  + vendor_name = "AWS"
                    # (1 unchanged attribute hidden)
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-edge-ip-reputation"
              + sampled_requests_enabled   = true
            }
        }
      + rule {
          + name     = "managed-known-bad-inputs"
          + priority = 50

          + override_action {
              + count {}
            }

          + statement {
              + managed_rule_group_statement {
                  + name        = "AWSManagedRulesKnownBadInputsRuleSet"
                  + vendor_name = "AWS"
                    # (1 unchanged attribute hidden)
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-edge-known-bad-inputs"
              + sampled_requests_enabled   = true
            }
        }

        # (5 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

@athvin
athvin marked this pull request as ready for review November 9, 2026 01:23
@athvin
athvin merged commit 6720c1a into main Nov 9, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prod WAF: add managed rule groups, in COUNT mode first

2 participants