Skip to content

fix(infra): WAFv2 rejects § in a web ACL description, so prod has no WAF - #913

Merged
athvin merged 1 commit into
mainfrom
fix/pr-911-waf-description
Nov 8, 2026
Merged

athvin merged 1 commit into
mainfrom
fix/pr-911-waf-description

Conversation

@athvin

@athvin athvin commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

One string. WAFv2 rejects § and parentheses in a web ACL description, so #911's web ACL and its ALB association were the only two resources that failed to apply.

Why

Prod is currently serving with no WAF. #911's apply (prod) got through the certificate, the ALB, both listeners, the www redirect rule and both Cloudflare records, then failed on CreateWebACL:

ValidationException: 1 validation error detected: Value 'Rate limits on the three
unauthenticated write paths (§4.1).' at 'description' failed to satisfy constraint:
Member must satisfy regular expression pattern:
^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$

That pattern admits neither the § this repo uses throughout nor the brackets that usually go with it. Neither earlier tier can catch it: validate does not know the provider's server-side rules and plan never submits the string, so the apply is the first thing that sees it — in the one environment where a half-finished apply matters.

Proof

Checked the new value against WAF's own regex, with the old value as a control, so the check is known to discriminate rather than just pass:

new: 'Rate limits on the three unauthenticated write paths - see infrastructure.md 4.1'  -> matches: True
old: 'Rate limits on the three unauthenticated write paths (§4.1).'                      -> matches: False

bash scripts/ci/tf-validate-all.sh — 5/5 Success!. terraform fmt -check -recursive clean.

Risk & rollback

Risk: low, and it reduces live risk — it creates the two resources that were meant to exist. The plan should be 2 to add, 0 to change, 0 to destroy. Rollback: git revert, which returns prod to the current unprotected state, so the revert is worse than the change.

Post-merge ledger

Closed by: agent · session a7f03c6d-206a-4ae3-a5c3-1c2f74052399 on Mac · 2026-11-08T21:20:00Z

Specific to this change

  • apply (prod) created the web ACL and the association — verified from AWS, not from a conclusion: aws wafv2 list-web-acls --scope REGIONAL → er-prod-edge 8aff260c-3895-4773-baac-0db11a70e24e, and get-web-acl-for-resource on the ALB ARN → er-prod-edge. The association is the half that makes it real; an unassociated ACL would list identically.
  • the three rate rules are present with the intended limits and windows — aws wafv2 get-web-acl:
    rate-login 100/300s /api/auth/login; rate-password-reset 20/300s /api/auth/password-reset; rate-invites 50/300s /api/invites. The API returns SearchString base64-encoded, decoded above — reading it raw would look like a wrong path.
  • the WAF actually blocks — 60 POSTs to /api/auth/login → 60× 403, with 5 GETs to / from the same address at the same moment → 5× 503. The control is what makes it meaningful. Worth recording that the FIRST flood of 130 returned zero blocks: a rate rule needs a warm-up, and get-rate-based-statement-managed-keys showed the address already tracked, which is how lag was distinguished from a non-matching rule. Memory: waf-rate-rule-needs-warmup.
  • feat(infra): prod edge — internet-facing ALB behind AWS WAF, DNS in Terraform #911's own ledger is reconciled with this — its WAF boxes point here and at fix(ci): a job-level env: shadows $GITHUB_ENV, so the prod Cloudflare token never applied #919, since its own apply could not satisfy them.
Context — plan, discoveries, measurements, files

Discoveries

  • The repo's house style collides with a provider constraint. § appears in nearly every comment and description in infra/terraform/, and AWS accepts it in EC2 security-group descriptions (those applied fine in the same run) but not in WAFv2's. So this is not a rule that generalises across the file — which is exactly why the fix carries the regex in a comment at the field rather than a note elsewhere.
  • The apply is partially-ordered, not atomic, and this is the first time that has mattered here. 16 of 18 resources were created; the two that failed are the two that provide the protection. Worth remembering when reading a failed prod apply: the question is not "did it fail" but "what did it leave standing".

Measurements

$ dig +short dupezero.com
18.226.193.19                      # Cloudflare apex flattening -> the ALB

$ dig +short www.dupezero.com
er-prod-edge-1880635913.us-east-2.elb.amazonaws.com.
18.226.193.19

$ aws acm describe-certificate --certificate-arn ...ba5706bb...
Status: ISSUED | dupezero.com: SUCCESS | www.dupezero.com: SUCCESS

$ aws wafv2 list-web-acls --scope REGIONAL --query 'WebACLs[].Name'
(empty)                            # the gap this PR closes

Files

  • infra/terraform/envs/prod/edge.tf — the web ACL description, plus the comment stating the constraint

#911's `apply (prod)` failed on the last two resources. Everything before them
applied — the certificate (ISSUED, both domains SUCCESS), the ALB, both
listeners, the www redirect rule, and both Cloudflare records — so
`dupezero.com` resolves today with NO web ACL in front of it.

WAFv2 validates `description` against

  ^[\w+=:#@/\-,\.][\w+=:#@/\-,\.\s]+[\w+=:#@/\-,\.]$

which admits neither the `§` this repository uses everywhere nor the brackets
that usually accompany it. `CreateWebACL` returns a 400 `ValidationException`
quoting the regex and naming nothing else.

The constraint is invisible to both earlier tiers: `terraform validate` does not
know the provider's server-side rules, and `plan` does not submit the string.
So the first thing that can catch it is the apply — in the one environment where
a half-finished apply matters.

The comment now states the rule at the field, with the regex, because every
other description in this file reaches for `§` and the next one added would
reintroduce it.

Verified the fix against WAF's own pattern, with the old value as a control:
the new description matches, the old one does not.

No ticket: this is a defect in #555's change rather than new scope, and #555 is
closed by the pull request that introduced it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@athvin athvin added the no-ticket deliberately not tied to a board ticket; exempts the pull request contract label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

terraform plan

a108c6e · run log and full plans

env add change destroy
state-backend (plan only) 0 0 0
core 0 0 0
dev 0 0 0
prod 2 0 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.

prod — 2 to add, 0 to change
data.aws_rds_engine_version.aurora_pg: Reading...
data.aws_iam_policy_document.pod_trust: Reading...
data.aws_iam_policy_document.eso_trust: Reading...
module.network.data.aws_region.current: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Reading...
module.network.data.aws_availability_zones.available: Reading...
module.eks.data.aws_iam_policy_document.node_trust: Read complete after 0s [id=2851119427]
module.network.data.aws_region.current: Read complete after 0s [id=us-east-2]
data.aws_iam_policy_document.eso_trust: Read complete after 0s [id=819195744]
data.aws_iam_policy_document.pod_trust: Read complete after 0s [id=819195744]
data.aws_caller_identity.current: Reading...
module.eks.data.aws_iam_policy_document.cluster_trust: Reading...
data.aws_iam_policy_document.efs_csi_trust: Reading...
data.aws_iam_policy_document.efs_csi_trust: Read complete after 0s [id=819195744]
module.eks.data.aws_iam_policy_document.cluster_trust: Read complete after 0s [id=1029077455]
data.aws_caller_identity.current: Read complete after 0s [id=797781631727]
module.lake.data.aws_iam_policy_document.lake_tls_only: Reading...
data.aws_iam_policy_document.eso: Reading...
data.aws_iam_policy_document.eso: Read complete after 0s [id=2178872705]
module.lake.data.aws_iam_policy_document.lake_tls_only: Read complete after 0s [id=3960055703]
data.aws_iam_policy_document.lake_access: Reading...
data.aws_iam_policy_document.lake_access: Read complete after 0s [id=3734071059]
module.network.data.aws_availability_zones.available: Read complete after 0s [id=us-east-2]
data.aws_rds_engine_version.aurora_pg: Read complete after 0s [id=17.9]

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

Terraform will perform the following actions:

  # aws_wafv2_web_acl.edge will be created
  + resource "aws_wafv2_web_acl" "edge" {
      + application_integration_url = (known after apply)
      + arn                         = (known after apply)
      + capacity                    = (known after apply)
      + description                 = "Rate limits on the three unauthenticated write paths - see infrastructure.md 4.1"
      + id                          = (known after apply)
      + lock_token                  = (known after apply)
      + name                        = "er-prod-edge"
      + name_prefix                 = (known after apply)
      + region                      = "us-east-2"
      + scope                       = "REGIONAL"
      + tags                        = {
          + "Name" = "er-prod-edge"
        }
      + tags_all                    = {
          + "Environment" = "prod"
          + "ManagedBy"   = "terraform"
          + "Name"        = "er-prod-edge"
          + "Project"     = "entity-resolution"
        }

      + default_action {
          + allow {
            }
        }

      + rule {
          + name     = "rate-invites"
          + priority = 30

          + action {
              + block {
                }
            }

          + statement {
              + rate_based_statement {
                  + aggregate_key_type    = "IP"
                  + evaluation_window_sec = 300
                  + limit                 = 50

                  + scope_down_statement {
                      + byte_match_statement {
                          + positional_constraint = "STARTS_WITH"
                          + search_string         = "/api/invites"

                          + field_to_match {
                              + uri_path {}
                            }

                          + text_transformation {
                              + priority = 0
                              + type     = "LOWERCASE"
                            }
                        }
                    }
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-rate-invites"
              + sampled_requests_enabled   = true
            }
        }
      + rule {
          + name     = "rate-login"
          + priority = 10

          + action {
              + block {
                }
            }

          + statement {
              + rate_based_statement {
                  + aggregate_key_type    = "IP"
                  + evaluation_window_sec = 300
                  + limit                 = 100

                  + scope_down_statement {
                      + byte_match_statement {
                          + positional_constraint = "STARTS_WITH"
                          + search_string         = "/api/auth/login"

                          + field_to_match {
                              + uri_path {}
                            }

                          + text_transformation {
                              + priority = 0
                              + type     = "LOWERCASE"
                            }
                        }
                    }
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-rate-login"
              + sampled_requests_enabled   = true
            }
        }
      + rule {
          + name     = "rate-password-reset"
          + priority = 20

          + action {
              + block {
                }
            }

          + statement {
              + rate_based_statement {
                  + aggregate_key_type    = "IP"
                  + evaluation_window_sec = 300
                  + limit                 = 20

                  + scope_down_statement {
                      + byte_match_statement {
                          + positional_constraint = "STARTS_WITH"
                          + search_string         = "/api/auth/password-reset"

                          + field_to_match {
                              + uri_path {}
                            }

                          + text_transformation {
                              + priority = 0
                              + type     = "LOWERCASE"
                            }
                        }
                    }
                }
            }

          + visibility_config {
              + cloudwatch_metrics_enabled = true
              + metric_name                = "er-prod-rate-password-reset"
              + sampled_requests_enabled   = true
            }
        }

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

  # aws_wafv2_web_acl_association.edge will be created
  + resource "aws_wafv2_web_acl_association" "edge" {
      + id           = (known after apply)
      + region       = "us-east-2"
      + resource_arn = "arn:aws:elasticloadbalancing:us-east-2:797781631727:loadbalancer/app/er-prod-edge/6505998c524f769a"
      + web_acl_arn  = (known after apply)
    }

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

Changes to Outputs:
  + edge_web_acl_arn       = (known after apply)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-ticket deliberately not tied to a board ticket; exempts the pull request contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants