Skip to content

Commit a00f893

Browse files
feat(fastly): Update bouncer doc
1 parent 0f50f8f commit a00f893

File tree

1 file changed

+269
-41
lines changed

1 file changed

+269
-41
lines changed

crowdsec-docs/unversioned/bouncers/fastly.mdx

Lines changed: 269 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ id: fastly
33
title: Fastly
44
---
55

6-
import Tabs from '@theme/Tabs';
7-
import TabItem from '@theme/TabItem';
86
import useBaseUrl from '@docusaurus/useBaseUrl';
97
import RemediationSupportBadges from '@site/src/components/remediation-support-badge';
108

@@ -26,53 +24,59 @@ import RemediationSupportBadges from '@site/src/components/remediation-support-b
2624
<RemediationSupportBadges
2725
/>
2826

29-
# cs-fastly-bouncer
27+
# Fastly bouncer
3028

31-
A Remediation Component that syncs the decisions made by CrowdSec with Fastly's VCL. Manages multi account, multi service setup. Supports IP, Country and AS scoped decisions.
32-
To learn how to setup crowdsec to consume fastly logs see [this](/u/user_guides/consuming_fastly_logs)
29+
A Remediation Component that syncs the decisions made by CrowdSec with Fastly's VCL. Manages multi account, multi service setup. Supports IP, Range, Country and AS scoped decisions.
30+
To learn how to set up crowdsec to consume Fastly logs see [this](/u/user_guides/consuming_fastly_logs)
3331

3432

35-
# Installation:
33+
## Installation
3634

37-
## Using pip
35+
### Using pip
3836

3937
Make sure you have python3.8+ installed. Now in a virtual environment run the following:
4038

4139
```bash
4240
pip install crowdsec-fastly-bouncer
43-
crowdsec-fastly-bouncer -g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2> > config.yaml # generate config
41+
crowdsec-fastly-bouncer -g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2> -o config.yaml # generate config
4442
vim config.yaml # Set crowdsec LAPI key, url, recaptcha keys, logging etc
4543
crowdsec-fastly-bouncer -c config.yaml # Run it !
4644
```
4745

48-
See how to obtain fastly account tokens [here](https://docs.fastly.com/en/guides/using-api-tokens). The tokens must have write access for the configured services.
46+
For more details on the config file, see the [Settings](#settings) section below.
4947

50-
**Note:** If your bouncer is not installed on the same machine than LAPI, don't forget to set the `lapi_url` and `lapi_key` in the configuration file /etc/crowdsec/bouncers/crowdsec-fastly-bouncer.yaml
48+
See how to get Fastly account tokens [here](https://docs.fastly.com/en/guides/using-api-tokens). The tokens must have write access for the configured services.
5149

52-
**Note:** For captcha to work you must provide the `recaptcha_site_key` and `recaptcha_secret_key` for each service. Learn how [here](http://www.google.com/recaptcha/admin)
50+
Practically, you can create a Personal token with a Global API access scope, Engineer Role and Automation type.
5351

52+
**Note:** If your bouncer is not installed on the same machine as LAPI, remember to set the `lapi_url` and `lapi_key` in the configuration file /etc/crowdsec/bouncers/crowdsec-fastly-bouncer.yaml
5453

55-
## Using Docker
54+
**Note:** For captcha to work, you must provide the `recaptcha_site_key` and `recaptcha_secret_key` for each service. Learn how [here](http://www.google.com/recaptcha/admin)
5655

57-
Make sure you have docker or podman installed. In this guide we will use docker, but podman would work as a drop in replacement too.
5856

59-
### Initial Setup
57+
### Using Docker
58+
59+
Make sure you have docker or podman installed. In this guide, we will use docker, but podman would work as a drop-in replacement too.
60+
61+
#### Initial Setup
6062

6163
```bash
6264
docker run crowdsecurity/fastly-bouncer \
63-
-g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2> > cfg.yaml # auto-generate fastly config for provided comma separated tokens
65+
-g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2> -o cfg.yaml # auto-generate fastly config for provided comma separated tokens
6466
vi cfg.yaml # review config and set `crowdsec_lapi_key`
6567
touch fastly-cache.json
6668
```
6769

70+
For more details on the config file, see the [Settings](#settings) section below.
71+
6872
The `lapi_key` can be obtained by running the following:
6973
```bash
7074
sudo cscli -oraw bouncers add fastlybouncer # -oraw flag can discarded for human friendly output.
7175
```
7276

7377
The `lapi_url` must be accessible from the container.
7478

75-
### Run the component
79+
#### Run the component
7680

7781
```bash
7882
docker run \
@@ -81,62 +85,286 @@ The `lapi_url` must be accessible from the container.
8185
crowdsecurity/fastly-bouncer
8286
```
8387

84-
## Activate the new configuration:
88+
## Usage
89+
90+
### Activate the new configuration
91+
92+
If you have set `activate: false` for your services in the config file, the bouncer will create a new version of the service with the CrowdSec configuration but will not activate it. This is useful for testing and validation before going live.
93+
94+
In this case, after starting the component, go to the Fastly web UI and, for each configured service, review the version created by the bouncer. If everything looks good, you can activate the new configuration.
95+
96+
### Version workflow
97+
98+
When the bouncer starts for the first time (i.e., when there is no local cache file), it will clone the active version of each configured service (or the version specified in `reference_version` if provided) to create a new draft version. It will then apply the CrowdSec configuration to this draft version.
99+
100+
The bouncer will then automatically activate the new version if `activate: true` is set in the config file.
101+
102+
103+
### Maximum items and ACL capacity
104+
105+
Bouncer will use the `max_items` parameter in the config file to determine how many decisions can be stored across all ACLs for a service and a decision type (ban or captcha).
106+
107+
As each ACL can hold a maximum of 1000 items, it will also determine how many ACLs are needed to accommodate the `max_items` limit.
108+
109+
For example, if `max_items` is set to 5000, the bouncer will create up to 10 ACLs in Fastly (5 for `ban`, 5 for `captcha`, each with possibly 1000 items).
110+
111+
112+
## Settings
113+
114+
The bouncer configuration is defined in a YAML file that controls all aspects of the bouncer's behavior. Below is a detailed description of each configuration parameter.
115+
116+
### Root Configuration Parameters
85117

86-
After starting the component, go in the fastly web UI. For each configured service review the version created by the bouncer. If everything looks good, you can activate the new configration !
118+
#### `bouncer_version`
119+
- **Type**: String
120+
- **Default**: Current version of the bouncer
121+
- **Description**: Version identifier for the bouncer configuration. This is automatically set and should match the installed bouncer version.
122+
- **Example**: `bouncer_version: 0.0.2`
123+
124+
#### `cache_path`
125+
- **Type**: String
126+
- **Default**: `/var/lib/crowdsec/crowdsec-fastly-bouncer/cache/fastly-cache.json`
127+
- **Description**: Path to the cache file where the bouncer stores the current state of Fastly services and ACLs. This allows the bouncer to resume operations without recreating infrastructure after restarts.
128+
- **Example**: `cache_path: ./dev/cache/fastly-cache.json`
87129

88-
# Configuration:
130+
#### `log_level`
131+
- **Type**: String
132+
- **Options**: `debug`, `info`, `warning`, `error`
133+
- **Default**: `info`
134+
- **Description**: Sets the logging verbosity level. Use `debug` for troubleshooting, `info` for normal operations.
135+
- **Example**: `log_level: info`
136+
137+
#### `log_mode`
138+
- **Type**: String
139+
- **Options**: `stdout`, `stderr`, `file`
140+
- **Default**: `stdout`
141+
- **Description**: Determines where log messages are output. When set to `file`, logs are written to the path specified in `log_file`.
142+
- **Example**: `log_mode: stdout`
143+
144+
#### `log_file`
145+
- **Type**: String
146+
- **Default**: `/var/log/crowdsec-fastly-bouncer.log`
147+
- **Description**: File path for log output when `log_mode` is set to `file`. Ensure the bouncer has write permissions to this location.
148+
- **Example**: `log_file: ./dev/log/crowdsec-fastly-bouncer.log`
149+
150+
#### `update_frequency`
151+
- **Type**: Integer (seconds)
152+
- **Default**: `10`
153+
- **Description**: How often (in seconds) the bouncer polls the CrowdSec LAPI for new decisions and updates Fastly ACLs accordingly.
154+
- **Example**: `update_frequency: 30`
155+
156+
### CrowdSec Configuration
157+
158+
The `crowdsec_config` section configures the connection and filtering for the CrowdSec Local API (LAPI).
159+
160+
#### `lapi_key`
161+
- **Type**: String (required)
162+
- **Description**: API key for authenticating with the CrowdSec LAPI. This key is generated when registering the bouncer with CrowdSec.
163+
- **Example**: `lapi_key: '1234'`
164+
165+
#### `lapi_url`
166+
- **Type**: String
167+
- **Default**: `http://localhost:8080/`
168+
- **Description**: URL of the CrowdSec LAPI endpoint.
169+
- **Example**: `lapi_url: http://localhost:8080/`
170+
171+
#### `include_scenarios_containing`
172+
- **Type**: List of strings
173+
- **Default**: `[]` (empty list - include all scenarios)
174+
- **Description**: Only process decisions from scenarios whose names contain any of these strings. Useful for filtering specific types of attacks.
175+
- **Example**:
176+
```yaml
177+
include_scenarios_containing:
178+
- "ssh"
179+
- "http"
180+
```
181+
182+
#### `exclude_scenarios_containing`
183+
- **Type**: List of strings
184+
- **Default**: `[]` (empty list - exclude no scenarios)
185+
- **Description**: Exclude decisions from scenarios whose names contain any of these strings. Takes precedence over `include_scenarios_containing`.
186+
- **Example**:
187+
```yaml
188+
exclude_scenarios_containing:
189+
- "whitelist"
190+
```
191+
192+
#### `only_include_decisions_from`
193+
- **Type**: List of strings
194+
- **Default**: `["crowdsec", "cscli"]`
195+
- **Description**: Only process decisions that originate from these sources. Common sources include `crowdsec` (automatic detection), `cscli` (manual decisions), and `CAPI` (Community API). Let it empty to include decisions from all sources.
196+
- **Example**:
197+
```yaml
198+
only_include_decisions_from:
199+
- crowdsec
200+
- cscli
201+
- CAPI
202+
```
203+
204+
#### `insecure_skip_verify`
205+
- **Type**: Boolean
206+
- **Default**: `false`
207+
- **Description**: Skip TLS certificate verification when connecting to LAPI. Only use for testing or when using self-signed certificates.
208+
- **Example**: `insecure_skip_verify: false`
209+
210+
#### `key_path`
211+
- **Type**: String
212+
- **Default**: `""` (empty)
213+
- **Description**: Path to client TLS key file for mutual TLS authentication with LAPI.
214+
- **Example**: `key_path: '/path/to/client.key'`
215+
216+
#### `cert_path`
217+
- **Type**: String
218+
- **Default**: `""` (empty)
219+
- **Description**: Path to client TLS certificate file for mutual TLS authentication with LAPI.
220+
- **Example**: `cert_path: '/path/to/client.crt'`
221+
222+
#### `ca_cert_path`
223+
- **Type**: String
224+
- **Default**: `""` (empty)
225+
- **Description**: Path to custom CA certificate file for verifying LAPI server certificate.
226+
- **Example**: `ca_cert_path: '/path/to/ca.crt'`
227+
228+
### Fastly Account Configuration
229+
230+
The `fastly_account_configs`) section defines one or more Fastly accounts and their associated services. Each account requires a separate API token.
231+
232+
#### Account Level Parameters
233+
234+
##### `account_token`
235+
- **Type**: String (required)
236+
- **Description**: Fastly API token with appropriate permissions to manage services, ACLs, and VCL configurations.
237+
- **Example**: `account_token: Rhy**************************EPNb`
238+
239+
##### `services`
240+
- **Type**: List of service configurations
241+
- **Description**: List of Fastly services to protect with CrowdSec decisions.
242+
243+
#### Service Level Parameters
244+
245+
##### `id`
246+
- **Type**: String (required)
247+
- **Description**: Fastly service ID to configure with CrowdSec protection.
248+
- **Example**: `id: jrLHbDGn9NbOHO7eSH1Xvo`
249+
250+
##### `activate`
251+
- **Type**: Boolean
252+
- **Default**: `false`
253+
- **Description**: Whether to automatically activate new service versions with CrowdSec configurations. Set to `true` for production deployment.
254+
- **Example**: `activate: true`
255+
256+
##### `max_items`
257+
- **Type**: Integer
258+
- **Default**: `20000`
259+
- **Description**: Maximum number of IP addresses that can be stored across all ACLs for this service. The bouncer will create multiple ACLs if needed to accommodate this limit.
260+
- **Example**: `max_items: 5000`
261+
262+
##### `recaptcha_site_key`
263+
- **Type**: String (required)
264+
- **Description**: Google reCAPTCHA site key for the captcha challenge functionality.
265+
- **Example**: `recaptcha_site_key: 6L*****************************N`
266+
267+
##### `recaptcha_secret_key`
268+
- **Type**: String (required)
269+
- **Description**: Google reCAPTCHA secret key for validating captcha responses.
270+
- **Example**: `recaptcha_secret_key: 6L***********************************g`
271+
272+
##### `captcha_cookie_expiry_duration`
273+
- **Type**: String
274+
- **Default**: `"1800"`
275+
- **Description**: Duration in seconds to persist the cookie containing proof of solving a captcha challenge.
276+
- **Example**: `captcha_cookie_expiry_duration: '1800'`
277+
278+
##### `reference_version`
279+
- **Type**: String (optional)
280+
- **Default**: `null` (uses active version)
281+
- **Description**: Specific Fastly service version to clone from instead of using the currently active version. Useful for maintaining consistent base configurations.
282+
- **Example**: `reference_version: 63`
283+
284+
285+
### Example Configuration
286+
287+
Below is an example configuration file with all parameters set to their defaults or example values.
89288

90289
```yaml
91290
crowdsec_config:
92291
lapi_key: ${LAPI_KEY}
93292
lapi_url: "http://localhost:8080/"
293+
only_include_decisions_from:
294+
- crowdsec
295+
- cscli
296+
- CAPI
297+
exclude_scenarios_containing: []
298+
include_scenarios_containing: ["ssh"]
299+
ca_cert_path: ''
300+
cert_path: ''
301+
insecure_skip_verify: false
302+
key_path: ''
94303
95304
fastly_account_configs:
96-
- account_token: # Obtain this from fastly
305+
- account_token: a***********************z # Get this from fastly
97306
services:
98-
- id: # The id of the service
99-
recaptcha_site_key: # Required for captcha support
100-
recaptcha_secret_key: # Required for captcha support
307+
- id: a***********************z # The id of the service
308+
recaptcha_site_key: a***********************z # Required for captcha support
309+
recaptcha_secret_key: a***********************z # Required for captcha support
101310
max_items: 20000 # max_items refers to the capacity of IP/IP ranges to ban/captcha.
102-
activate: false # # Set to true, to activate the new config in production
103-
reference_version: # version to clone/use
104-
clone_reference_version: true # whether to clone the "reference_version".
311+
activate: true # # Set to true, to activate the new config in production
105312
captcha_cookie_expiry_duration: '1800' # Duration to persist the cookie containing proof of solving captcha
313+
reference_version: null # Optional: specify a specific version to clone from instead of the active version
106314
107-
bouncer_version:
108-
update_frequency: 10 # Duration in seconds to poll the crowdsec API
315+
bouncer_version: v0.0.2
316+
update_frequency: 30 # Duration in seconds to poll the crowdsec API
109317
log_level: info # Valid choices are either of "debug","info","warning","error"
110318
log_mode: stdout # Valid choices are "file" or "stdout" or "stderr"
111319
log_file: /var/log/crowdsec-fastly-bouncer.log # Ignore if logging to stdout or stderr
112320
```
113321

114-
# Helpers:
322+
## Python Helpers
115323

116324
The component has few builtin helper features:
117325

118-
## Auto config generator:
326+
### Auto config generator
119327

120-
**Usage:**
328+
**Usage**
121329

122330
```bash
123-
crowdsec-fastly-bouncer -c <PATH_TO_BASE_CONFIG>\
124-
-g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2>
331+
crowdsec-fastly-bouncer -g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2>
125332
```
126333

127-
This will print boilerplate config with sane defaults for the provided comma separted fastly tokens.
334+
This will print boilerplate config with sane defaults for the provided comma separated Fastly tokens.
128335
Always review the generated config before proceeding further.
129336

130-
Crowdsec config is copied from the config at `PATH_TO_BASE_CONFIG`.
337+
Crowdsec config is copied from the config at `PATH_TO_BASE_CONFIG`.
338+
339+
### Config editor
340+
341+
**Usage**
342+
343+
```bash
344+
crowdsec-fastly-bouncer -e -g <FASTLY_TOKEN_1>,<FASTLY_TOKEN_2> -c <PATH_TO_BASE_CONFIG>
345+
```
346+
This will update the config at `PATH_TO_BASE_CONFIG` with the generated config for the provided comma separated Fastly tokens.
347+
Always review the updated config before proceeding further.
348+
131349

132-
## Cleaner:
350+
### Runner
133351

134-
**Usage:**
352+
**Usage**
135353

136354
```bash
137-
sudo crowdsec-fastly-bouncer -c <PATH_TO_BASE_CONFIG> -d
355+
crowdsec-fastly-bouncer -c <PATH_TO_BASE_CONFIG>
138356
```
139357

140-
This deletes the fastly resources created by the component.
141-
It only works if the configured service version is not locked.
142-
It is useful for quick iteration before activateing the new service.
358+
This starts the component in normal mode using the provided config file.
359+
360+
### Cleaner
361+
362+
**Usage**
363+
364+
```bash
365+
crowdsec-fastly-bouncer -c <PATH_TO_BASE_CONFIG> -d
366+
```
367+
368+
This deletes the Fastly resources created by the component (all resources starting with `crowdsec_` prefix).
369+
370+
Be aware that the created configuration will be created as a draft version even if `activate: true` is set in the config file.

0 commit comments

Comments
 (0)