Skip to content

Commit 76e0e1b

Browse files
authored
Merge pull request #856 from crowdsecurity/improve_appsec_config_doc
improve the appsec configuration documentation
2 parents 8202551 + 543b814 commit 76e0e1b

File tree

4 files changed

+558
-42
lines changed

4 files changed

+558
-42
lines changed

crowdsec-docs/docs/appsec/configuration.md

Lines changed: 242 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,271 @@
11
---
22
id: configuration
3-
title: AppSec Component Configuration Files
3+
title: AppSec Configuration Files
44
sidebar_position: 6
55
---
66

7-
## Foreword
7+
## Overview
88

9-
Configuring the AppSec Component usually requires the use of multiple files:
9+
This page explains the interraction between various files involved in AppSec configuration and the details about the processing pipeline AppSec request processing.
1010

11-
- [AppSec rules](/appsec/rules_syntax.md) allow you to write a signature to detect and/or block malevolent requests. [You can find more information about the syntax here](/appsec/rules_syntax.md)
12-
- [Acquisition configuration](/log_processor/data_sources/appsec.md) indicates which port is the AppSec Component listening on, and which AppSec configuration it will use.
13-
- AppSec configuration tells which rules are loaded in in-band (blocking) and out-of-band (non-blocking)
14-
phases. [it as well allows you to tweak the behavior of the component via the powerful expr bindings](/appsec/rules_syntax.md)
11+
**Prerequisites**:
12+
- Familiarity with [AppSec concepts](/appsec/intro.md)
13+
- Basic AppSec setup completed (see Getting Started guides)
1514

16-
## Acquisition configuration
15+
The AppSec Component configuration consists of three main parts:
1716

18-
## Default configuration
17+
- **[Acquisition configuration](/log_processor/data_sources/appsec.md)**: Defines which port the AppSec Component listens on and which AppSec configurations files to load <!-- Fix linked page to ie. speak about appsec_configs-->
18+
- **AppSec configurations**: Define which rules are loaded and how they behave, along with [hooks](/appsec/hooks.md) for runtime customization
19+
- **[AppSec rules](/appsec/rules_syntax.md)**: The actual detection signatures that identify and block malicious requests
1920

20-
The Acquisition configuration is usually present directly within `/etc/crowdsec/acquis.d/` or `/etc/crowdsec/acquis.yaml`:
21+
## AppSec Acquisition
2122

22-
> The default AppSec acquisition configuration
23-
```yaml
24-
appsec_config: crowdsecurity/appsec-default
23+
The goals of the acquisition file are:
24+
- To specify the **address** and **port** where the AppSec-enabled Remediation Component(s) will forward the requests to.
25+
- And specify one or more [AppSec configuration files](#appsec-configuration) to use as definition of what rules to apply and how.
26+
27+
Details can be found in the [AppSec Datasource page](/log_processor/data_sources/apps).
28+
29+
### Defining Multiple AppSec Configurations
30+
31+
Often you will want to activate multiple AppSec configuration defining groups of rules that will be handled the same way.
32+
33+
Use the `appsec_configs` *(with an S)* parameter to load multiple configurations that work together.
34+
35+
In the following example we have two configurations:
36+
- One with [CrowdSec default AppSec rules ↗️](https://app.crowdsec.net/hub/author/crowdsecurity/appsec-configurations/appsec-default) running in inband mode
37+
- The other for the [CRS rules ↗️](https://app.crowdsec.net/hub/author/crowdsecurity/collections/appsec-crs) that by default run in out of band mode.
38+
39+
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
40+
appsec_configs:
41+
- crowdsecurity/appsec-default # In-band virtual patching
42+
- crowdsecurity/crs # Out-of-band detection based on ModSec CRS - from crowdsecurity/appsec-crs collection
2543
labels:
2644
type: appsec
2745
listen_addr: 127.0.0.1:7422
2846
source: appsec
2947
```
3048
31-
## Creating custom configuration
49+
:::info
50+
CrowdSec AppSec collections are available on [CrowdSec Hub ↗️](https://app.crowdsec.net/hub/collections?filters=search%3Dappsec) and kept up to date.
51+
52+
For example the CRS collection: `sudo cscli collections install crowdsecurity/appsec-crs`.
53+
This collection installs OWASP CRS in out-of-band and adds a scenario to ban IPs triggering multiple rules.
54+
:::
55+
56+
### Using Custom Configurations
3257

58+
If you want to alter the default configuration files we recommend creating a new configuration files instead of modifying existing hub configurations.
59+
Modifying hub configurations will make them *tainted* and prevent automatic updates.
3360

34-
If you want to add some custom rules or hooks, it is suggested to add a custom `appsec_config`.
35-
Modifying existing `appsec_config` will make it *tainted* and will interfere with future updates.
61+
For example, if you want to change the default vpatch rules config, create your own and use it instead in the acquisition file.
3662

3763
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
3864
appsec_configs:
39-
- crowdsecurity/appsec-default
40-
- custom/my_vpatch_rules
65+
- crowdsecurity/appsec-default
66+
- custom/my_vpatch_rules
4167
labels:
4268
type: appsec
4369
listen_addr: 127.0.0.1:7422
4470
source: appsec
4571
```
4672

47-
:::info
48-
When loading several app sec configs, _hooks_ and _appsec rules_ are appended, and for conflicting options (e.g., `default_remediation`), the last one takes precedence.
49-
:::
50-
73+
A custom configuration file could look like this:
5174

5275
```yaml title="/etc/crowdsec/appsec-configs/my_vpatch_rules.yaml"
5376
name: custom/my_vpatch_rules
5477
default_remediation: ban
5578
inband_rules:
56-
- custom/custom-vpatch-*
57-
#on_match:
58-
#...
79+
- custom/custom-vpatch-*
80+
# Add custom hooks as needed
81+
```
82+
83+
## AppSec Configuration Files
84+
85+
AppSec configuration files declare **which rules to load** in the **in-band** *(blocking)* and/or **out-of-band** *(non-blocking)*, define how matches are handled (e.g., default remediation), and let you tweak processing via hooks like `on_load`, `pre_eval`, `post_eval`, and `on_match`.
86+
87+
For details, jump to the [Configuration properties list](#appendix-appsec-configuration-properties)
88+
89+
:::info
90+
When loading multiple AppSec configs, _hooks_ and _appsec rules_ are appended, and for conflicting options (e.g., `default_remediation`), the last one takes precedence.
91+
:::
92+
93+
### Configuration Processing Order
94+
95+
When multiple AppSec configurations are loaded, they are processed in the order specified in the `appsec_configs` list. For details on how in-band and out-of-band rules work, see the [AppSec Introduction](/appsec/intro.md#inband-rules-and-out-of-band-rules).
96+
97+
### Multi-Config Rule Evaluation
98+
99+
1. All `inband_rules` from all configurations are combined and evaluated together
100+
2. All `outofband_rules` from all configurations are combined and evaluated together
101+
3. Hooks from all configurations are executed in the order the configurations are listed
102+
4. For conflicting configuration options (like `default_remediation`), the last configuration's value takes precedence
103+
104+
## AppSec Configuration Reference
105+
106+
Each AppSec configuration file defines how rules are loaded and processed.
107+
You can create custom configuration files in the following folder: `/etc/crowdsec/appsec-configs/`
108+
109+
Here's the complete reference of available directives:
110+
111+
### Core Configuration Directives
112+
113+
#### `name` (required)
114+
Unique identifier for the AppSec configuration, used for logging and referencing.
115+
116+
```yaml
117+
name: custom/my-appsec-config
118+
```
119+
120+
#### `inband_rules` (optional)
121+
List of rule patterns to load as in-band rules. See [in-band rule processing](/appsec/intro.md#inband-rule-processing) for details.
122+
123+
```yaml
124+
inband_rules:
125+
- crowdsecurity/base-config
126+
- crowdsecurity/vpatch-*
127+
- custom/critical-patches
128+
```
129+
130+
#### `outofband_rules` (optional)
131+
List of rule patterns to load as out-of-band rules. See [out-of-band rule processing](/appsec/intro.md#out-of-band-rules-processing) for details.
132+
133+
```yaml
134+
outofband_rules:
135+
- crowdsecurity/crs
136+
- custom/detection-rules
137+
```
138+
139+
### Remediation Configuration
140+
141+
#### `default_remediation` (optional, default: "ban")
142+
Default action for in-band rules that match. Special value `allow` prevents blocking.
143+
144+
```yaml
145+
default_remediation: ban # or "allow", "captcha", etc.
146+
```
147+
148+
:::info
149+
When using multiple AppSec configs the last declared one takes precedence for this property
150+
:::
151+
152+
#### `default_pass_action` (optional, default: "allow")
153+
Action for requests that don't match any rules or match rules with pass action.
154+
155+
```yaml
156+
default_pass_action: allow # or any custom value
157+
```
158+
159+
:::info
160+
When using multiple AppSec configs the last declared one takes precedence for this property
161+
:::
162+
163+
### HTTP Response Codes
164+
165+
#### `blocked_http_code` (optional, default: 403)
166+
HTTP status code returned to the remediation component for blocked requests.
167+
168+
#### `passed_http_code` (optional, default: 200)
169+
HTTP status code returned to the remediation component for allowed requests.
170+
171+
#### `user_blocked_http_code` (optional, default: 403)
172+
HTTP status code returned to the end user for blocked requests.
173+
174+
#### `user_passed_http_code` (optional, default: 200)
175+
HTTP status code returned to the end user for allowed requests.
176+
177+
```yaml
178+
blocked_http_code: 403
179+
passed_http_code: 200
180+
user_blocked_http_code: 403
181+
user_passed_http_code: 200
182+
```
183+
184+
### Performance and Processing Options
185+
186+
#### `inband_options` and `outofband_options`
187+
Performance tuning options for rule processing:
188+
189+
```yaml
190+
inband_options:
191+
disable_body_inspection: false # Skip HTTP body inspection
192+
request_body_in_memory_limit: 1048576 # Max body size in memory (bytes)
193+
194+
outofband_options:
195+
disable_body_inspection: false
196+
request_body_in_memory_limit: 1048576
197+
```
198+
199+
**`disable_body_inspection`**: Set to `true` to skip HTTP body analysis for performance.
200+
**`request_body_in_memory_limit`**: Maximum request body size to load into memory (default: 1MB). Larger bodies are processed differently.
201+
202+
#### `log_level` (optional)
203+
Logging verbosity for this configuration. Available levels: `debug`, `info`, `warn`, `error`.
204+
205+
```yaml
206+
log_level: info # Use "debug" for troubleshooting
207+
```
208+
209+
### Hook Configuration
210+
211+
AppSec configurations support four types of hooks for custom behavior:
212+
213+
#### `on_load`
214+
Executed when the configuration is loaded. Typically used for global rule modifications.
215+
216+
```yaml
217+
on_load:
218+
- apply:
219+
- RemoveInBandRuleByName("problematic-rule")
220+
```
221+
222+
#### `pre_eval`
223+
Executed before rule evaluation for each request. Supports conditional logic.
224+
225+
```yaml
226+
pre_eval:
227+
- filter: IsInBand && req.RemoteAddr == "192.168.1.100"
228+
apply:
229+
- RemoveInBandRuleByName("strict-rule")
230+
```
231+
232+
#### `post_eval`
233+
Executed after rule evaluation. Useful for debugging and analysis.
234+
235+
```yaml
236+
post_eval:
237+
- filter: IsInBand
238+
apply:
239+
- DumpRequest().WithBody().ToJSON()
59240
```
60241

61-
## Disabling rules at runtime
242+
#### `on_match`
243+
Executed when rules match. Used to modify remediation or generate custom alerts.
244+
245+
```yaml
246+
on_match:
247+
- filter: req.URL.Host == "staging.example.com"
248+
apply:
249+
- SetRemediation("allow")
250+
- CancelAlert()
251+
```
252+
253+
For complete hook documentation, see [AppSec Hooks](/appsec/hooks.md).
254+
255+
## Rule Management
62256

63-
Even though we try to provide rules without false positives, sometimes a virtual patching rule can block legitimate requests on a website.
257+
### Disabling Rules at Runtime
64258

65259
You can disable rules at runtime, either globally (for all requests) or based on specific conditions (source IP, URI, ...).
66260

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
261+
You can disable rules by:
262+
- Name with `RemoveInBandRuleByName`: For CrowdSec rules (name as seen in `cscli appsec-rules list`)
263+
- ID with `RemoveInBandRuleByID`: For seclang/ModSecurity rules by numeric ID
264+
- Tag with `RemoveInBandRuleByTag`: For seclang/ModSecurity rules by tag
71265

72-
The same functions exist for out-of-band rules, prefixed with `RemovedOutBandRuleBy...`
266+
The same functions exist for out-of-band rules, prefixed with `RemoveOutBandRuleBy...`
73267

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).
268+
To disable a rule, create a new AppSec config to avoid tainting the configuration from the hub (or update your existing custom configuration).
75269

76270
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
77271
name: custom/my_config
@@ -84,20 +278,20 @@ pre_eval:
84278
- RemoveInBandRuleByName("crowdsecurity/generic-wordpress-uploads-php")
85279
```
86280

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.
281+
This example uses [hooks](/docs/appsec/hooks.md) to modify the configuration in 2 places:
282+
- `on_load`: Expressions here will be applied when CrowdSec loads the configuration, effectively disabling the rule `crowdsecurity/vpatch-env-access` globally.
89283
- `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.
90284

91285
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.
92286

93287
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.
94288

95-
Finally, we need to tell crowdsec to load our new config:
289+
Finally, add your new config to the acquisition configuration:
96290

97291
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
98292
appsec_configs:
99-
- crowdsecurity/appsec-default
100-
- custom/my_config
293+
- crowdsecurity/appsec-default
294+
- custom/my_config
101295
labels:
102296
type: appsec
103297
listen_addr: 127.0.0.1:7422
@@ -126,7 +320,7 @@ pre_eval:
126320

127321
### Disable appsec for a specific FQDN
128322

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):
323+
If your reverse-proxy forwards all requests to CrowdSec regardless of the FQDN, you can disable AppSec for specific domains with a custom AppSec config (the request will always be allowed):
130324

131325
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
132326
name: custom/my_config
@@ -140,7 +334,7 @@ on_match:
140334

141335
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).
142336

143-
## Appsec configuration
337+
## Appendix: Appsec configuration properties
144338

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

@@ -172,10 +366,18 @@ An optional list of rules to be loaded in in-band phase. In band rules are block
172366

173367
An optional remediation for in-band rules, defaults to `ban`. If set to `allow`, remediation component won't block the request (even if it matched rules). Any other value (including `captcha`) is passed as-is back to the remediation component.
174368

369+
:::info
370+
When using multiple AppSec configs the last declared one takes precedence for this property
371+
:::
372+
175373
### `default_pass_action`
176374

177375
An optional remediation for requests that didn't match any rules (or rules with a pass action). Defaults to `allow`. Any other value will be passed as-is to the remediation component.
178376

377+
:::info
378+
When using multiple AppSec configs the last declared one takes precedence for this property
379+
:::
380+
179381
### `blocked_http_code`
180382

181383
The HTTP code to return to the remediation component when a request should be blocked. Defaults to `403`

0 commit comments

Comments
 (0)