You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crowdsec-docs/docs/contributing/specs/bouncer_appsec_specs.mdx
+46-42Lines changed: 46 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ import useBaseUrl from "@docusaurus/useBaseUrl"
7
7
8
8
## Context
9
9
10
-
A **Remediation Component***(aka **Bouncer**)* is enforcing **decisions** made by **CrowdSec Security Engine** based on detected malicious behaviors [\[See figure 1\]](#bookmark=id.1m5bs6wbkfr7), or Directly with CrowdSec SaaS endpoint channeling public, crowdsec or user made blocklsits.
10
+
A **Remediation Component***(aka **Bouncer**)* is enforcing **decisions** made by **CrowdSec Security Engine** based on detected malicious behaviors [\[See figure 1\]](#crowdsec-security-engine-diagram), or Directly with CrowdSec SaaS endpoint channeling public, crowdsec or user made blocklsits.
11
11
12
12
A **decision** dictates what action should be applied on incoming traffic from a specific **IP** or **IP-Range**. *(It could also be on the user scope or any other, but these specifications will focus on the IP and Range scopes)*
13
13
@@ -20,15 +20,15 @@ The Bouncer applies the appropriate remediation *(we’ll only focus on ban/bloc
20
20
* Communication with the Local API (aka LAPI) or its SaaS counterpart
And the yet unreviewed but functional [NGINX NJS version](https://github.com/crowdsecurity/cs-nginx-njs-bouncer/pull/1/files) (doesn’t have appsec capabilities yet)
31
+
And the yet prototyped but functional [NGINX NJS version](https://github.com/crowdsecurity/cs-nginx-njs-bouncer/pull/1/files) (doesn’t have appsec capabilities yet)
32
32
33
33
⚠️ **Your bouncer must always delete/clean it’s resources on shutdown**
34
34
@@ -40,20 +40,20 @@ The remediation can be blocking or displaying a captcha.
40
40
41
41
Fields in purple and/or with the mention (configurable) must appear in the config file, the case of the parameters names can be UPPER or LOWER depending on the type of config file, match the appropriate standard for the bouncer you’re implementing. Try to group them in a logical way in the config file template.
42
42
43
-
Details about the config file in the [Installation chapter](#installation-/-documentation)
43
+
Details about the config file in the [Installation chapter](#installation--documentation)
44
44
45
45
### Connecting to the Local API (LAPI)
46
46
47
-
You can find the swagger here [https://crowdsecurity.github.io/api\_doc/lapi/](https://crowdsecurity.github.io/api_doc/lapi/)
48
-
Details about the endpoints parameters can be found [in the appendix](#bookmark=id.h7yz6lpk4af7)
47
+
You can find the swagger here [https://crowdsecurity.github.io/api_doc/lapi/](https://crowdsecurity.github.io/api_doc/lapi/)
48
+
Details about the endpoints parameters can be found [in the appendix](#appendix)
49
49
50
-
* URL to Local API endpoint: configurable field **api\_url**
51
-
* Default value likely to be: http://121.0.0.1:8080
* For now we only have a v1 of LAPI, bouncer states the version he’s using
54
54
* Authentication
55
-
* Either by API key passed in the header **X-Api-Key:** configurable field **api\_key**
56
-
* Or via certificate configurable fields **tls.cert\_file\+ tls.key\_file**
55
+
* Either by API key passed in the header **X-Api-Key:** configurable field **api_key**
56
+
* Or via certificate configurable fields **tls.cert_file\+ tls.key_file**
57
57
58
58
### Retrieving decisions
59
59
@@ -81,15 +81,15 @@ The live mode endpoint is **/decisions**
81
81
* No need to make this configurable
82
82
* Caching
83
83
* To avoid consecutive calls for decisions about an IP we’ll cache the decisions per IP
84
-
* default **1s** configurable field cache\_expiration
84
+
* default **1s** configurable field cache_expiration
85
85
* Timeout
86
86
* If LAPI doesn’t respond
87
-
* Default **200ms** configurable field lapi\_timeout
87
+
* Default **200ms** configurable field lapi_timeout
88
88
***Fallback**:
89
89
* Fallback in case of timeout
90
90
* By default passthrough : let him pass
91
91
* Possible values: passthrough, ban, captcha
92
-
* configurable field lapi\_failure\_action
92
+
* configurable field lapi_failure_action
93
93
94
94
#### Stream Mode (by default)
95
95
@@ -100,7 +100,7 @@ Allows to pull all decisions from LAPI and then periodically get a delta
100
100
* ⚠️ To retrieve the initial full list, use the **startup \= true** parameter
101
101
* This is necessary if you don’t have the decision list in memory
102
102
* Following calls need to have startup \= false
103
-
* Recommended pull period **10s** configurable field stream\_update\_frequency
103
+
* Recommended pull period **10s** configurable field stream_update_frequency
104
104
* Parameters
105
105
106
106
*Only the following fields are to be considered for a basic bouncer implementation*
@@ -110,18 +110,18 @@ Allows to pull all decisions from LAPI and then periodically get a delta
110
110
* empty by default mean all origins are considered
111
111
* editable by the user to look in a specific origin: configurable field origins (same field as for live)
112
112
* Origins are comma separated strings (e.g. crowdsec,capi,cscli)
113
-
***scenarios\_containing** and **scenarios\_not\_containing**
113
+
***scenarios_containing** and **scenarios_not_containing**
114
114
* Means that the decisions are linked (or not) to alerts triggered by such or such scenario
115
115
* The check done by LAPI is a string.contains(...)
116
-
* Default as empty configurable fields scenarios\_containing && scenarios\_not\_containing
116
+
* Default as empty configurable fields scenarios_containing && scenarios_not_containing
117
117
* Storing decisions
118
118
* ℹ️ The number of decisions you can expect is:
119
119
* 30-70k ips from Fire (nominal case)
120
120
* Can vary a lot depending on the BL subscription of the user
121
121
* Have the code be able to handle 100k to be safe for the nominal case
122
122
* Storing in memory is ideal, we recommend to convert IPs to integers
123
123
* The decisions format is the following:
124
-
* See [decisions example in appendix](#bookmark=id.6hv12rnhk5iz)
124
+
* See [decisions example in appendix](#appendix)
125
125
* There can be multiple decisions per IP
126
126
* Store each decisions independently as they have their own remediation action and TTL
127
127
* Ranges are stored too
@@ -137,27 +137,27 @@ If a remediation is found and for the LAPI timeout fallback here are the remedia
137
137
* Remediation type
138
138
* Remediation property will be “ban”, “captcha” or potentially any custom string
139
139
***ban** (block)
140
-
* Return a 403: configurable field ban\_return\_code
140
+
* Return a 403: configurable field ban_return_code
141
141
* Accompanied by an HTML body
142
-
* Default page model [provided (single HTML file)](#bookmark=id.rcfrhly566w8)
143
-
* Page path configurable: configurable field ban\_template\_path
142
+
* Default page model [provided (single HTML file)](#ban-template-page)
143
+
* Page path configurable: configurable field ban_template_path
144
144
***captcha**
145
145
* Various type of captcha must be supported
146
146
* configurable fields:
147
-
* captcha \_provider
148
-
*captcha\_secret\_key
149
-
*captcha\_site\_key
150
-
*captcha\_template\_path
147
+
* captcha _provider
148
+
*captcha_secret_key
149
+
*captcha_site_key
150
+
*captcha_template_path
151
151
* Type to support
152
152
* RE-captcha
153
153
* Turnstile
154
154
* Hcaptcha
155
155
* onFails
156
156
* Re-present the captcha
157
157
* ⚠️ Cache: in order not to repeat the captcha too often
158
-
***1h** cache **per IP** after successful captcha configurable field cache\_expiration
158
+
***1h** cache **per IP** after successful captcha configurable field cache_expiration
159
159
***Custom remediation**
160
-
* Defaults to ignore/ban/captcha configurable field **remediation\_fallback**
160
+
* Defaults to ignore/ban/captcha configurable field **remediation_fallback**
161
161
* If ignored, you don’t even need to store the decision
162
162
* Remediation priority
163
163
* There is a priority in the remediation to take in account if an IP has multiple
@@ -197,23 +197,23 @@ An additional activatable capability of the bouncer is to forward the request to
197
197
198
198
The request forwarding is a blocking process, when the AppSec capability is activated the bouncer should wait for a response at each request forwarding to process with the request handling.
199
199
200
-
AppSec is disabled by default and activable if url exists configurable field appsec\_url
200
+
AppSec is disabled by default and activable if url exists configurable field appsec_url
201
201
202
202
* Connect to AppSec endpoint
203
203
* The security engine should have activated the AppSec and a listen address should be present in the SecurityEngine acquisition
204
-
* Default endpoint http://127.0.0.1:7422
204
+
* Default endpoint `http://127.0.0.1:7422`
205
205
* Auth by API key passed in the header **X-Api-Key:** same param as LAPI apikey
206
206
* Request forwarding
207
-
* You can find information about the forwarding protocol on this doc page [https://docs.crowdsec.net/docs/next/appsec/protocol/](https://docs.crowdsec.net/docs/next/appsec/protocol/)
207
+
* You can find information about the forwarding protocol on this doc page:[https://docs.crowdsec.net/docs/next/appsec/protocol/](https://docs.crowdsec.net/docs/next/appsec/protocol/)
208
208
* When forwarding the query to the AppSec endpoint, the security engine will evaluate the actions to do and return the appropriate response code that the remediation component should display.
209
209
* ⚠️ At the exception of codes **500** and **401** which mean that the forwarding or authentication to the endpoint failed. For those response codes you should trigger the fallback described there after..
210
210
* ⚠️ As stated earlier this is a blocking process
211
-
***Timeout** 200ms configurable field appsec\_timeout
211
+
***Timeout** 200ms configurable field appsec_timeout
212
212
***Fallback**:
213
213
* Fallback in case of timeout or response failure (500,401…)
214
214
* By default passthrough : let him pass
215
215
* Possible values: passthrough, ban, captcha
216
-
* configurable field appsec\_failure\_action
216
+
* configurable field appsec_failure_action
217
217
218
218
## Extra Details and Requirements
219
219
@@ -299,6 +299,7 @@ You can refer to the AppSec documentation to test request forwarding.
299
299
300
300
## Appendix
301
301
302
+
### CrowdSec Security Engine diagram
302
303
**Figure 1** : Interactions around **CrowdSec Security Engine**
303
304
<divstyle={{ display: "flex" }}>
304
305
<divstyle={{ textAlign: "center", flex: "1" }}>
@@ -310,14 +311,15 @@ You can refer to the AppSec documentation to test request forwarding.
310
311
</div>
311
312
</div>
312
313
313
-
**Details about LAPI endpoints parameters**
314
+
### Details about LAPI endpoints parameters
315
+
314
316
**GET /decisions/stream**
315
317
316
318
***startup:** set it to **TRUE** for the **initial call** to get all decisions *(when False you’ll get the delta from your last call)*
317
319
***scopes: “**ip,range” is the only relevant values when remediating on IPs
318
-
***origins:** Leave blank to allow all origins, test your configurable origins with [those tests](#bookmark=id.qso6jljxlov9)
319
-
***scenarios\_containing:** leave blank by default, allow change in config
320
-
***scenarios\_not\_containing:** leave blank by default, allow change in config
320
+
***origins:** Leave blank to allow all origins, test your configurable origins with [those tests](#decision-example)
321
+
***scenarios_containing:** leave blank by default, allow change in config
322
+
***scenarios_not_containing:** leave blank by default, allow change in config
321
323
322
324
**GET /decisions**
323
325
@@ -327,11 +329,11 @@ You can refer to the AppSec documentation to test request forwarding.
327
329
***ip:** ignore/leave blank: shortcut for scope:ip \+ value
328
330
***range:** ignore/leave blank: shortcut for scope:range \+ value
329
331
***contains:** leave blank by default, configurable by user
330
-
***origins:** Leave blank to allow all origins, test your configurable origins with [those tests](#bookmark=id.qso6jljxlov9)
331
-
***scenarios\_containing:** leave blank by default, allow change in config
332
-
***scenarios\_not\_containing:** leave blank by default, allow change in config
332
+
***origins:** Leave blank to allow all origins, test your configurable origins with [those tests](#decision-example)
333
+
***scenarios_containing:** leave blank by default, allow change in config
334
+
***scenarios_not_containing:** leave blank by default, allow change in config
333
335
334
-
**Decision example**
336
+
### Decision example
335
337
336
338
```javascript
337
339
{
@@ -361,7 +363,7 @@ You can refer to the AppSec documentation to test request forwarding.
361
363
362
364
```
363
365
364
-
**Ban template page**
366
+
### Ban template page
365
367
366
368
```javascript
367
369
<!DOCTYPE html>
@@ -479,7 +481,9 @@ You can refer to the AppSec documentation to test request forwarding.
479
481
480
482
```
481
483
482
-
**Metrics payload**
484
+
### Metrics payload
485
+
486
+
More details about metrics in [Metrics specs](/contributing/specs/bouncer_metrics_specs/)
0 commit comments