Skip to content

fix(cloudflare): Key the webhook rate limit on each client - #6050

Merged
dan-petty merged 2 commits into
mainfrom
fix/5035-webhook-limit-per-client
Nov 16, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/5035-webhook-limit-per-client

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The Traefik limit of the webhook route keyed its bucket on the request host. Each delivery comes through the Cloudflare tunnel with that host, so all senders shared one bucket of 60 requests a minute. When Cloudflare Access admits Everyone on the path (owner decision 2 of 2026-11-12), any sender could use up the bucket of GitHub. The Middleware now keys on Cf-Connecting-Ip, which the Cloudflare edge writes. A client cannot set it past the edge, and a gate check keeps the Traefik Service ClusterIP.

Onboard row 7 now accepts a hook that sends more events than the Service takes, and a test holds each consumer event to the hook events. The HMAC check, the 413 cap and the alerts do not change.

After the merge, owner step O3: in Cloudflare Access, set the Bypass policy of hooks.<domain>/webhooks/github to include Everyone, on that path only.

Closes #5035

Change: openspec/changes/archive/2026-11-16-5035-webhook-limit-per-client/

@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/cloudflare Cloudflare tunnels, Access and DNS labels Nov 16, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Evidence, the owner step and the proof

What keys the bucket

  • Before: the live Middleware has sourceCriterion.requestHost: true (kubectl get middleware -n devops roadmap-service-rate-limit -o jsonpath='{.spec}'). Traefik v3.7.17 (kube-system) then keys on request.host (GetSourceExtractor in pkg/middlewares/extractor.go). Each delivery has the host hooks.<domain>, so all senders share one bucket. The remote address is not the key; it is a cloudflared pod for each request.
  • After: sourceCriterion.requestHeaderName: Cf-Connecting-Ip. Traefik keys on the value of that header. A request with no header (only a pod of the cluster can send one) goes into one shared bucket with the key "".

Can a client spoof Cf-Connecting-Ip?

  • No path from outside the cluster gets past the Cloudflare edge. The tunnel route of *.<domain> sends each request to http://traefik.kube-system.svc.cluster.local:80 with no origin request settings (devops cloudflare tunnel routes --json). The Traefik Service is ClusterIP with no host port, and the new gate check holds this.
  • The edge writes the header: "CF-Connecting-IP provides the client IP address connecting to Cloudflare to the origin web server" (Cloudflare HTTP headers). A transform rule cannot change it. The exceptions do not apply here: a Worker on the same zone, and Pseudo IPv4 "Overwrite" (that still gives one value for each client).
  • A pod of the cluster can reach Traefik and set any value, because no NetworkPolicy limits ingress to Traefik. The HMAC check still refuses its deliveries.
  • Residual: a client with many IPv6 addresses gets more buckets of its own. It cannot use the bucket of GitHub. Traefik applies ipv6Subnet only to an ipStrategy, not to a header.

Tests that fail on the base

uv run devops ci fail-to-pass --base origin/main:

  • tests/roadmap/test_roadmap_onboard.py::test_onboard_row_7_is_present_for_a_hook_that_also_sends_other_events
  • tests/roadmap/test_roadmap_onboard.py::test_the_service_step_and_the_webhook_row_name_the_same_events
  • gate case k8s roadmap_service.check_each_webhook_ingress_names_the_rate_limit_that_the_devops_stack_renders: 1 of 172 cases fails on the base, 0 on the head
  • tests/server/test_server_service.py does not collect on the base (service_consumers is new).

The checks that stay have tests already: the 401 before the body read and the 413 cap (test_the_route_reads_the_body_only_of_a_signed_delivery_within_the_cap), and the alerts (tests/fixtures/prometheus_rules/roadmap_service_webhooks_tests.yaml).

Owner step O3 (after the merge)

  1. After Argo CD syncs devops, confirm the key: kubectl get middleware -n devops roadmap-service-rate-limit -o jsonpath='{.spec.rateLimit.sourceCriterion}' gives {"requestHeaderName":"Cf-Connecting-Ip"}.
  2. In Cloudflare Zero Trust, open Access > Applications > GitHub Webhooks - Roadmap Service (path hooks.<domain>/webhooks/github). Edit the policy gh-hooks-public-ips: Action Bypass, Include Everyone, in place of the 6 IP ranges. Keep the application on that one path. Write down the time of the change.

Proof after O3

  1. On the repository hook (Settings > Webhooks > the hook > Recent Deliveries), redeliver one delivery that got 403. It must get 200 or 202.
  2. After the next 100 deliveries, this gives 0 (put the change time in place of <time>): uv run devops gh api 'repos/dan-petty/devops-cli/hooks/692250036/deliveries?per_page=100' --jq '[.[]|select(.status_code==403 and .delivered_at > "<time>")]|length'
  3. Comment the delivery ID, its status and the change time on fix(cloudflare): find the edge rule that answers 403 for the webhook route #5035.

The Traefik limit of the webhook route keyed on the request host, so every
sender shared one bucket of 60 a minute. Key it on Cf-Connecting-Ip, which the
Cloudflare edge sets, so another sender cannot use up the bucket of GitHub
before the Access Bypass of owner step O3. Onboard row 7 accepts a hook that
sends more events than the Service takes, and a test holds the consumer events
to the hook events.

Closes #5035
@dan-petty
dan-petty force-pushed the fix/5035-webhook-limit-per-client branch from d0837a8 to 091d9af Compare November 16, 2026 21:50
@dan-petty

Copy link
Copy Markdown
Owner Author

Check results

Head commit: 091d9af754c77c70e6bfd56e198cff592c0a3355

Check Conclusion Link
Tests & Coverage success run
devops-cli success run
zizmor success run
trivy-config success run
Plan Check skipped run
CodeQL success run
Tests on Main skipped run
Dependency Freshness skipped run
Test Job Duration skipped run
Analyze (actions) success run
Analyze (python) success run
Fail-to-Pass Check success run
Tests & Coverage (shard 3 of 4) success run
Design Tokens success run
Changed-Test Independence success run
Tests & Coverage (shard 4 of 4) success run
Static Analysis success run
Image Pins success run
Service Image success run
Tests & Coverage (shard 2 of 4) success run
MCP Server Image success run
Tests & Coverage (shard 1 of 4) success run
Docs Site Build success run
Runner Image success run
Semantic PR title success run

Fail-to-pass run: https://github.com/dan-petty/devops-cli/actions/runs/43964161558/job/133639063146

Skipped check: Plan Check
Skipped check: Tests on Main
Skipped check: Dependency Freshness
Skipped check: Test Job Duration

@dan-petty
dan-petty marked this pull request as ready for review November 16, 2026 22:01
@dan-petty
dan-petty merged commit 9cc974b into main Nov 16, 2026
25 checks passed
@dan-petty
dan-petty deleted the fix/5035-webhook-limit-per-client branch November 16, 2026 22:02
dan-petty-release Bot added a commit that referenced this pull request Nov 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.169.2](v0.169.1...v0.169.2)
(2026-11-17)


### Bug Fixes

* **cloudflare:** Key the webhook rate limit on each client
([#6050](#6050))
([9cc974b](9cc974b))
* **deps:** give a Helm chart update the fix prefix
([#6057](#6057))
([9b69d07](9b69d07)),
closes [#6054](#6054)
* **deps:** give SearXNG its own Renovate branch behind approval
([#6052](#6052))
([515a968](515a968))
* **deps:** update helm charts (patch)
([#6046](#6046))
([ebc1e68](ebc1e68))
* **k8s:** Roll the MCP server with no gap
([#6070](#6070))
([00c730b](00c730b))
* **k8s:** State the NVMe rule and cover CNPG claims
([#6062](#6062))
([e04435a](e04435a))
* **security:** renew the kubectl Trivy ignores of the MCP image
([#6088](#6088))
([73ca153](73ca153))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/cloudflare Cloudflare tunnels, Access and DNS type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cloudflare): find the edge rule that answers 403 for the webhook route

1 participant