Skip to content

Commit 5f06092

Browse files
chore: updates
2 parents 9d4a758 + 2f48dd7 commit 5f06092

File tree

165 files changed

+9857
-3301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+9857
-3301
lines changed

crowdsec-docs/components.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "https://ui.shadcn.com/schema.json",
3+
"tailwind": {
4+
"config": "tailwind.config.js",
5+
"css": "src/css/custom.css",
6+
"baseColor": "neutral",
7+
"prefix": "tw-",
8+
"cssVariables": false
9+
},
10+
"rsc": true,
11+
"aliases": {
12+
"utils": "@/src/utils",
13+
"components": "@/src/components",
14+
"ui": "@/src/ui",
15+
"hooks": "@/src/hooks",
16+
"lib": "@/src/lib"
17+
},
18+
"style": "default"
19+
}
20+

crowdsec-docs/docs/appsec/configuration.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,88 @@ inband_rules:
5858
#...
5959
```
6060

61+
## Disabling rules at runtime
62+
63+
Even though we try to provide rules without false positives, sometimes a virtual patching rule can block legitimate requests on a website.
64+
65+
You can disable rules at runtime, either globally (for all requests) or based on specific conditions (source IP, URI, ...).
66+
67+
You can can disable rules by:
68+
- Name with `RemoveInBandRuleByName`: Intended for disabling rules provided by crowdsec (the name is the name of the appsec-rule as seen in `cscli appsec-rules list`).
69+
- ID with `RemoveInBandRuleByID`: Intended for disabling seclang rules
70+
- Tag with `RemoveInBandRuleByTag`: Intended for disabling seclang rules
71+
72+
The same functions exist for out-of-band rules, prefixed with `RemovedOutBandRuleBy...`
73+
74+
To disable a rule, we'll first create a new `appsec-config` to avoid tainting the configuration from the hub (if you are already using a custom configuration, you can update this one instead).
75+
76+
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
77+
name: custom/my_config
78+
on_load:
79+
- apply:
80+
- RemoveInBandRuleByName("crowdsecurity/vpatch-env-access")
81+
pre_eval:
82+
- filter: IsInBand == true && req.URL.Path startsWith "/bar/"
83+
apply:
84+
- RemoveInBandRuleByName("crowdsecurity/generic-wordpress-uploads-php")
85+
```
86+
87+
We are using the [hooks](/docs/appsec/hooks.md) provided by the appsec to modify the configuration in 2 places:
88+
- `on_load`: Expressions here will be applied when crowdsec loads the configuration, effectively disabling the rule `crowdsecurity/vpatch-env-access` globally.
89+
- `pre_eval`: Expressions here will be applied only if the provided filter matches. In this example, we are disabling the rule `crowdsecurity/generic-wordpress-uploads-php` only if the request URI starts with `/blog/` and if we are currently processing in-band rules.
90+
91+
You can also disable native (seclang) rules by providing their ID with the `RemoveInBandRuleByID` helper. See the [hooks](appsec/hooks.md) documentation for a list of available helpers.
92+
93+
Also note that we are not loading any rules in our custom config: the rules are loaded by the `crowdsecurity/appsec-default` config, and we are just modifying the runtime behavior with this config.
94+
95+
Finally, we need to tell crowdsec to load our new config:
96+
97+
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
98+
appsec_configs:
99+
- crowdsecurity/appsec-default
100+
- custom/my_config
101+
labels:
102+
type: appsec
103+
listen_addr: 127.0.0.1:7422
104+
source: appsec
105+
```
106+
107+
## Allowlisting
108+
109+
### Fully allow a specific IP or range
110+
111+
If you want to ignore all rule matches for a specific IP or range, you can use a [centralized allowlist](local_api/allowlists.md).
112+
113+
Rules will be processed as usual, but the request will not be blocked even if a rule matches.
114+
115+
### Disable specific rules for a specific IP/range
116+
117+
If you want to disable rule(s) for a specific IP (or range), you will need to use the `pre_eval` hook (refer to the section above for more details):
118+
119+
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
120+
name: custom/my_config
121+
pre_eval:
122+
- filter: req.RemoteAddr == "1.2.3.4"
123+
apply:
124+
- RemoveInBandRuleByName("crowdsecurity/generic-wordpress-uploads-php")
125+
```
126+
127+
### Disable appsec for a specific FQDN
128+
129+
If your reverse-proxy forwards all requests to crowdsec, regardless of the FQDN, you can disable the appsec for specific domain with a custom appsec-config (ie, the request will be always allowed):
130+
131+
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
132+
name: custom/my_config
133+
on_match:
134+
- filter: req.URL.Host == "foo.com"
135+
apply:
136+
- CancelEvent()
137+
- CancelAlert()
138+
- SetRemediation("allow")
139+
```
140+
141+
With this config, the rules will still be evaluated, but if a rule matches no alert or event will be generated, and the remediation will be set to `allow`(ie, instruct the bouncer to let the request through).
142+
61143
## Appsec configuration
62144

63145
The AppSec configuration is referenced by the acquisition configuration (`appsec_config`, `appsec_configs` or `appsec_config_path`):

crowdsec-docs/docs/appsec/hooks.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,14 @@ Any other values (including `ban` and `captcha`) are transmitted as-is to the re
211211

212212

213213

214+
### `req` object
214215

216+
The `pre_eval`, `on_match` and `post_eval` hooks have access to a `req` variable that represents the HTTP request that was forwarded to the appsec.
217+
218+
It's a Go [http.Request](https://pkg.go.dev/net/http#Request) object, so you can directly access all the details about the request.
219+
220+
For example:
221+
- To get the requested URI: `req.URL.Path`
222+
- To get the client IP: `req.RemoteAddr`
223+
- To get the HTTP method: `req.Method`
224+
- To get the FQDN: `req.URL.Host`

crowdsec-docs/docs/appsec/intro.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ You can follow our quick start guides depending on your web server:
7070
Or consider learning more about the AppSec capabilities:
7171

7272
- **Rules**: [How to read, write and debug rules](/appsec/rules_syntax.md)
73-
<!-- TODO -->
74-
- **Scenarios**: How to create scenarios that leverage the AppSec Component events
75-
- **Hooks**: [For advanced use let's talk about possible Hooks](/appsec/hooks.md)
73+
- **Scenarios**: [How to create scenarios that leverage the AppSec Component events](/appsec/alerts_and_scenarios.md)
74+
- **Hooks**: [To customise behavior of the AppSec at runtime](/appsec/hooks.md)
7675
- **Troubleshoot**: [How to troubleshoot the behavior of the AppSec Component](/appsec/troubleshooting.md)
7776
- **AppSec Protocol**: [if you're maintaining or creating a remedation component and want to add the AppSec capabilities](/appsec/protocol.md)

crowdsec-docs/docs/appsec/protocol.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ This documentation can be useful in case you want to write your own remediation
2222

2323
To work with the CrowdSec application security component, some HTTP headers are require, in addition to the other HTTP headers and the body of the original request.
2424

25-
| Header Name | Description |
26-
| --------------------------- | -------------------------------------------------------------------------- |
27-
| `X-Crowdsec-Appsec-Ip` | The Real IP address of the original HTTP request |
28-
| `X-Crowdsec-Appsec-Uri` | The URI of the original HTTP request |
29-
| `X-Crowdsec-Appsec-Host` | The Host of the original HTTP request |
30-
| `X-Crowdsec-Appsec-Verb` | The Method of the original HTTP request |
31-
| `X-Crowdsec-Appsec-Api-Key` | The API Key to communicate with the CrowdSec application security component |
32-
| `X-Crowdsec-Appsec-User-Agent`| The User-Agent of the original HTTP request |
25+
| Header Name | Description |
26+
| -------------------------------- | ------------------------------------------------------------------------------------- |
27+
| `X-Crowdsec-Appsec-Ip` | The Real IP address of the original HTTP request |
28+
| `X-Crowdsec-Appsec-Uri` | The URI of the original HTTP request |
29+
| `X-Crowdsec-Appsec-Host` | The Host of the original HTTP request |
30+
| `X-Crowdsec-Appsec-Verb` | The Method of the original HTTP request |
31+
| `X-Crowdsec-Appsec-Api-Key` | The API Key to communicate with the CrowdSec application security component |
32+
| `X-Crowdsec-Appsec-User-Agent` | The User-Agent of the original HTTP request |
33+
| `X-Crowdsec-Appsec-Http-Version` | The HTTP version used by the original HTTP request (in integer form `10`, `11`, ...) |
3334

3435
:::note
3536

@@ -96,11 +97,11 @@ username=admin' OR '1'='1' -- &password=password
9697

9798
According to the result of the processing of the HTTP request, the application security component will respond with a different HTTP code and body.
9899

99-
| HTTP Code | Description | Body |
100-
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
101-
| `200` | The HTTP request is allowed | `{"action" : "allow"}` |
102-
| `403` | The HTTP request triggered one or more application security component rules | `{"action" : "ban", "http_status": 403}` or `{"action" : "captcha", "http_status": 403}` |
103-
| `500` | An error occurred in the application security component. The remediation component must support a `APPSEC_FAILURE_ACTION` parameter to handle this case | `null` |
104-
| `401` | The remediation component is not authenticated. It must use the same API Key that was generated to pull the local API request | `null` |
100+
| HTTP Code | Description | Body |
101+
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
102+
| `200` | The HTTP request is allowed | `{"action" : "allow"}` |
103+
| `403` | The HTTP request triggered one or more application security component rules | `{"action" : "ban", "http_status": 403}` or `{"action" : "captcha", "http_status": 403}` |
104+
| `500` | An error occurred in the application security component. The remediation component must support a `APPSEC_FAILURE_ACTION` parameter to handle this case | `null` |
105+
| `401` | The remediation component is not authenticated. It must use the same API Key that was generated to pull the local API request | `null` |
105106

106107
In case of a `403` response, the body will contain the action to take and the HTTP status code to return to the client.

crowdsec-docs/docs/appsec/quickstart/traefik.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ http:
157157
crowdsec:
158158
plugin:
159159
bouncer:
160+
enabled: true
160161
crowdsecAppsecEnabled: true
161162
crowdsecAppsecHost: crowdsec:7422
162163
crowdsecAppsecFailureBlock: true
@@ -168,6 +169,7 @@ Instead if you define the configuration using labels on the containers you can a
168169
169170
```yaml
170171
labels:
172+
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.enabled=true"
171173
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecAppsecEnabled=true"
172174
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecAppsecHost=crowdsec:7422"
173175
- "traefik.http.middlewares.crowdsec-bar.plugin.bouncer.crowdsecLapiKey=privateKey-foo"

crowdsec-docs/docs/configuration/crowdsec_configuration.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ common:
114114
log_max_age: <max_age_of_log_file>
115115
log_max_files: <number_of_log_files_to_keep>
116116
compress_logs: (true|false)
117+
log_format: "(text|json)"
117118
config_paths:
118119
config_dir: "<path_to_crowdsec_config_folder>"
119120
data_dir: "<path_to_crowdsec_data_folder>"
@@ -145,6 +146,9 @@ db_config:
145146
host: "<db_host_ip>" # for mysql/pgsql
146147
port: "<db_host_port>" # for mysql/pgsql
147148
sslmode: "<require/disable>" # for pgsql
149+
ssl_ca_cert: "<path_to_ca_cert_file>" # for mysql/pgsql
150+
ssl_client_cert: "<path_to_client_cert_file>" # for mysql/pgsql
151+
ssl_client_key: "<path_to_client_key_file>" # for mysql/pgsql
148152
use_wal: "true|false" # for sqlite
149153
max_open_conns: "<max_number_of_conns_to_db>"
150154
flush:
@@ -167,6 +171,7 @@ api:
167171
client:
168172
insecure_skip_verify: "(true|false)"
169173
credentials_path: "<path_to_local_api_client_credential_file>"
174+
unregister_on_exit: "(true|false)"
170175
server:
171176
enable: <true|false> # enable or disable local API
172177
log_level: "(error|info|debug|trace>")"
@@ -223,6 +228,7 @@ common:
223228
log_max_age: <max_age_of_log_file>
224229
log_max_files: <number_of_log_files_to_keep>
225230
compress_logs: (true|false)
231+
log_format: "(text|json)"
226232
```
227233

228234
#### `daemonize`
@@ -279,6 +285,11 @@ Maximum number of old log files to retain. The default is to retain 3 old log f
279285

280286
Whether to compress the log file after rotation or not.
281287

288+
#### `log_format`
289+
> string
290+
291+
Format of crowdsec log. Can be `text` (default) or `json`
292+
282293
### `config_paths`
283294

284295
This section contains most paths to various sub configuration items.
@@ -452,6 +463,9 @@ db_config:
452463
host: "<db_host_ip>" # for mysql/postgresql/pgx # must be omitted if using socket file
453464
port: "<db_host_port>" # for mysql/postgresql/pgx # must be omitted if using socket file
454465
sslmode: "<require/disable>" # for postgresql/pgx
466+
ssl_ca_cert: "<path_to_ca_cert_file>" # for mysql/pgsql
467+
ssl_client_cert: "<path_to_client_cert_file>" # for mysql/pgsql
468+
ssl_client_key: "<path_to_client_key_file>" # for mysql/pgsql
455469
max_open_conns: "<max_number_of_conns_to_db>"
456470
decision_bulk_size: "<decision_bulk_size>"
457471
flush:
@@ -549,13 +563,48 @@ db_config:
549563
The port to connect to (only if the type of database is `mysql` or `postgresql`). Must be omitted if using socket file.
550564

551565

566+
#### `sslmode`
567+
552568
```yaml
553569
db_config:
554570
type: postgresql
555571
556572
sslmode: require
557573
```
558-
Require or disable ssl connection to database (only if the type of database is `postgresql`). See [PostgreSQL SSL modes](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS) for possible values.
574+
Require or disable ssl connection to database (only if the type of database is `mysql` or `postgresql` or `pgx`).
575+
576+
See [PostgreSQL SSL modes](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-SSLMODE-STATEMENTS) for possible values.
577+
See [MySQL SSL modes](https://dev.mysql.com/doc/refman/8.0/en/using-encrypted-connections.html) for possible values within the `Client-Side` configuration.
578+
579+
#### `ssl_ca_cert`
580+
581+
```yaml
582+
db_config:
583+
type: mysql|postgresql|pgx
584+
585+
ssl_ca_cert: /path/to/ca.crt
586+
```
587+
Path to the CA certificate file (only if the type of database is `mysql` or `postgresql` or `pgx`)
588+
589+
#### `ssl_client_cert`
590+
591+
```yaml
592+
db_config:
593+
type: mysql|postgresql|pgx
594+
595+
ssl_client_cert: /path/to/client.crt
596+
```
597+
Path to the client certificate file when using mTLS (only if the type of database is `mysql` or `postgresql` or `pgx`)
598+
599+
#### `ssl_client_key`
600+
601+
```yaml
602+
db_config:
603+
type: mysql|postgresql|pgx
604+
605+
ssl_client_key: /path/to/client.key
606+
```
607+
Path to the client key file when using mTLS (only if the type of database is `mysql` or `postgresql` or `pgx`)
559608

560609
#### `max_open_conns`
561610

@@ -693,6 +742,7 @@ api:
693742
client:
694743
insecure_skip_verify: "(true|false)"
695744
credentials_path: "<path_to_local_api_client_credential_file>"
745+
unregister_on_exit: "(true|false)"
696746
server:
697747
enable: <true|false>
698748
log_level: "(error|info|debug|trace>"
@@ -782,6 +832,7 @@ The client subsection is used by `crowdsec` and `cscli` to read and write decisi
782832
client:
783833
insecure_skip_verify: "(true|false)"
784834
credentials_path: "<path_to_local_api_client_credential_file>"
835+
unregister_on_exit: "(true|false)"
785836
```
786837

787838
##### `insecure_skip_verify`
@@ -794,6 +845,13 @@ Allows the use of https with self-signed certificates.
794845

795846
Path to the credential files (contains API url + login/password).
796847

848+
##### `unregister_on_exit`
849+
>bool
850+
851+
If set to `true`, the log processor will remove delete itself from LAPI when stopping.
852+
853+
Intended for use in dynamic environment such as Kubernetes.
854+
797855
#### `server`
798856

799857
The `server` subsection is the local API configuration.
@@ -864,6 +922,13 @@ This option will disable the registration of remote agents using `cscli lapi reg
864922
##### `capi_whitelists_path`
865923
> string
866924

925+
:::warning
926+
927+
This option is deprecated.
928+
You should use [centralized allowlists](local_api/allowlists.md) instead.
929+
930+
:::
931+
867932
The path to whitelists file for community and 3rd party blocklists.
868933
Those IPs/CIDR whitelists apply on all the IPs received from community blocklist or 3rd party lists subscriptions.
869934

crowdsec-docs/docs/cscli/cscli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ It is meant to allow you to manage bans, parsers/scenarios/etc, api and generall
2828
### SEE ALSO
2929

3030
* [cscli alerts](/cscli/cscli_alerts.md) - Manage alerts
31+
* [cscli allowlists](/cscli/cscli_allowlists.md) - Manage centralized allowlists
3132
* [cscli appsec-configs](/cscli/cscli_appsec-configs.md) - Manage hub appsec-configs
3233
* [cscli appsec-rules](/cscli/cscli_appsec-rules.md) - Manage hub appsec-rules
3334
* [cscli bouncers](/cscli/cscli_bouncers.md) - Manage bouncers [requires local API]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
id: cscli_allowlists
3+
title: cscli allowlists
4+
---
5+
## cscli allowlists
6+
7+
Manage centralized allowlists
8+
9+
### Options
10+
11+
```
12+
-h, --help help for allowlists
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--color string Output color: yes, no, auto (default "auto")
19+
-c, --config string path to crowdsec config file (default "/etc/crowdsec/config.yaml")
20+
--debug Set logging to debug
21+
--error Set logging to error
22+
--info Set logging to info
23+
-o, --output string Output format: human, json, raw
24+
--trace Set logging to trace
25+
--warning Set logging to warning
26+
```
27+
28+
### SEE ALSO
29+
30+
* [cscli](/cscli/cscli.md) - cscli allows you to manage crowdsec
31+
* [cscli allowlists add](/cscli/cscli_allowlists_add.md) - Add content to an allowlist
32+
* [cscli allowlists create](/cscli/cscli_allowlists_create.md) - Create a new allowlist
33+
* [cscli allowlists delete](/cscli/cscli_allowlists_delete.md) - Delete an allowlist
34+
* [cscli allowlists inspect](/cscli/cscli_allowlists_inspect.md) - Inspect an allowlist
35+
* [cscli allowlists list](/cscli/cscli_allowlists_list.md) - List all allowlists
36+
* [cscli allowlists remove](/cscli/cscli_allowlists_remove.md) - Remove content from an allowlist
37+

0 commit comments

Comments
 (0)