Skip to content

Commit 8f24d8b

Browse files
authored
Update Cloudflare worker bouncer docs for metrics (#651)
1 parent 0115636 commit 8f24d8b

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

crowdsec-docs/unversioned/bouncers/cloudflare-workers.mdx

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ sudo systemctl start crowdsec-cloudflare-worker-bouncer # the Remediation Compon
115115

116116
#### From source
117117

118-
:warning: requires go >= 1.20
118+
:warning: requires go >= 1.23
119119

120120
```bash
121121
git clone https://github.com/crowdsecurity/cs-cloudflare-worker-bouncer
@@ -137,7 +137,15 @@ The Remediation Component does the following:
137137
1. Create a Cloudflare Worker and a Worker KV per configured account.
138138
2. Create a Worker Route(s) per configured zone. Any request matching the route would be handled by the worker.
139139
3. For every matching incoming request, the worker checks whether it's IP, Country and AS have a decision against. It checks for this in it's KV store. If found it performs the corresponding remediation.
140-
4. The Remediation Component also periodically updates the KV store with the latest decisions from CrowdSec.
140+
4. The Remediation Component also periodically updates the KV store with the latest decisions from CrowdSec.
141+
142+
If your Cloudflare token has permission on D1, the remediation component will also automatically create a database to track:
143+
- Number of requests processed
144+
- Number of requests blocked
145+
146+
Those metrics are exposed through the prometheus endpoint and automatically sent to crowdsec for visualisation with `cscli`.
147+
148+
Metrics are stored in a D1 database to allow for easy retrieval by the remediation component. If your token does not have access to D1, a warning will be logged and metrics will be disabled.
141149

142150
## Configuration
143151

@@ -171,6 +179,13 @@ cloudflare_config:
171179
mode: managed # Supported Modes "managed"|"invisible"|"non-interactive"
172180
token: <CLOUDFLARE_ACCOUNT_TOKEN>
173181
account_name: [email protected]
182+
worker:
183+
log_only: false # If true, allow all requests, but still keep track of what would have been blocked in the metrics
184+
script_name: ""
185+
logpush: null
186+
tags: []
187+
compatibility_date: ""
188+
compatibility_flags: []
174189

175190
log_level: info
176191
log_media: "stdout"
@@ -193,7 +208,7 @@ For obtaining the `token`:
193208

194209
1. Sign in as a user who has access to the desired account.
195210

196-
Then click [this link](https://dash.cloudflare.com/profile/api-tokens?permissionGroupKeys=%5B%7B%22key%22%3A%22account_settings%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22challenge_widgets%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22user_details%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22workers_kv_storage%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22workers_routes%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22workers_scripts%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22zone%22%2C%22type%22%3A%22read%22%7D%2C%20%7B%22key%22%3A%20%22dns%22%2C%20%22type%22%3A%22read%22%7D%5D&name=) and create the token.
211+
Then click [this link](https://dash.cloudflare.com/profile/api-tokens?permissionGroupKeys=%5B%7B%22key%22%3A%22account_settings%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22challenge_widgets%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22user_details%22%2C%22type%22%3A%22read%22%7D%2C%7B%22key%22%3A%22workers_kv_storage%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22workers_routes%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22workers_scripts%22%2C%22type%22%3A%22edit%22%7D%2C%7B%22key%22%3A%22zone%22%2C%22type%22%3A%22read%22%7D%2C%20%7B%22key%22%3A%20%22dns%22%2C%20%22type%22%3A%22read%22%7D%2C%20%7B%22key%22%3A%22d1%22%2C%20%22type%22%3A%22edit%22%7D%5D&name=) and create the token.
197212

198213
Alternatively, you can go to [Tokens](https://dash.cloudflare.com/profile/api-tokens) and create the token.
199214

@@ -205,6 +220,7 @@ The Remediation Component requires the following permissions to function:
205220
| Account | Workers KV Storage | Edit |
206221
| Account | Workers Scripts | Edit |
207222
| Account | Account Settings | Read |
223+
| Account | D1 | Edit |
208224
| User | User Details | Read |
209225
| Zone | DNS | Read |
210226
| Zone | Workers Routes | Edit |
@@ -463,6 +479,41 @@ Cloudflare account token.
463479

464480
Account name.
465481

482+
#### `worker.log_only`
483+
> bool
484+
485+
If true, allow all requests but keep track of what would have been blocked in the metrics.
486+
487+
Defaults to `false`
488+
489+
#### `worker.script_name`
490+
> string
491+
492+
Name to use for the worker script.
493+
494+
Default to `crowdsec-cloudflare-worker-bouncer`.
495+
496+
#### `worker.logpush`
497+
> bool
498+
499+
Enable logpush for the worker.
500+
501+
Default to no value.
502+
503+
#### `worker.compatibility_date`
504+
> string
505+
506+
See https://developers.cloudflare.com/workers/configuration/compatibility-dates/.
507+
508+
Default to no value
509+
510+
#### `worker.compatibility_flags`
511+
> list of strings
512+
513+
See https://developers.cloudflare.com/workers/configuration/compatibility-flags/.
514+
515+
Default to no value.
516+
466517
#### `ban_template_path`
467518
> string
468519

0 commit comments

Comments
 (0)