Skip to content

Commit 4620fdc

Browse files
committed
improve the appsec configuration documentation
1 parent 8202551 commit 4620fdc

File tree

1 file changed

+198
-38
lines changed

1 file changed

+198
-38
lines changed

crowdsec-docs/docs/appsec/configuration.md

Lines changed: 198 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,234 @@ title: AppSec Component 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 section covers the detailed configuration options for the CrowdSec AppSec Component.
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 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+
## Acquisition Configuration
2122

22-
> The default AppSec acquisition configuration
23-
```yaml
24-
appsec_config: crowdsecurity/appsec-default
23+
### Multiple AppSec Configurations
24+
25+
Use `appsec_configs` to load multiple configurations that work together:
26+
27+
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
28+
appsec_configs:
29+
- crowdsecurity/appsec-default # In-band virtual patching
30+
- crowdsecurity/crs # Out-of-band detection based on ModSec CRS - from crowdsecurity/appsec-crs collection
2531
labels:
2632
type: appsec
2733
listen_addr: 127.0.0.1:7422
2834
source: appsec
2935
```
3036
31-
## Creating custom configuration
37+
:::info
38+
Do not forget to `sudo cscli collections install crowdsecurity/appsec-crs`.
39+
This collection installs OWASP CRS in out-of-band and adds a scenario to ban IPs triggering multiple rules.
40+
:::
3241

42+
### Creating Custom Configurations
3343

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.
44+
Create new configuration files instead of modifying existing hub configurations. Modifying hub configurations will make them *tainted* and prevent automatic updates.
3645

3746
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
3847
appsec_configs:
39-
- crowdsecurity/appsec-default
40-
- custom/my_vpatch_rules
48+
- crowdsecurity/appsec-default
49+
- custom/my_vpatch_rules
4150
labels:
4251
type: appsec
4352
listen_addr: 127.0.0.1:7422
4453
source: appsec
4554
```
4655

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-
56+
Create your custom configuration:
5157

5258
```yaml title="/etc/crowdsec/appsec-configs/my_vpatch_rules.yaml"
5359
name: custom/my_vpatch_rules
5460
default_remediation: ban
5561
inband_rules:
56-
- custom/custom-vpatch-*
57-
#on_match:
58-
#...
62+
- custom/custom-vpatch-*
63+
# Add custom hooks as needed
64+
```
65+
66+
:::info
67+
When loading multiple AppSec configs, _hooks_ and _appsec rules_ are appended, and for conflicting options (e.g., `default_remediation`), the last one takes precedence.
68+
:::
69+
70+
## Configuration Processing Order
71+
72+
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).
73+
74+
### Multi-Config Rule Evaluation
75+
76+
1. All `inband_rules` from all configurations are combined and evaluated together
77+
2. All `outofband_rules` from all configurations are combined and evaluated together
78+
3. Hooks from all configurations are executed in the order the configurations are listed
79+
4. For conflicting configuration options (like `default_remediation`), the last configuration's value takes precedence
80+
81+
## AppSec Configuration Reference
82+
83+
Each AppSec configuration file defines how rules are loaded and processed. Here's the complete reference of available directives:
84+
85+
### Core Configuration Directives
86+
87+
#### `name` (required)
88+
Unique identifier for the AppSec configuration, used for logging and referencing.
89+
90+
```yaml
91+
name: custom/my-appsec-config
92+
```
93+
94+
#### `inband_rules` (optional)
95+
List of rule patterns to load as in-band rules. See [in-band rule processing](/appsec/intro.md#inband-rule-processing) for details.
96+
97+
```yaml
98+
inband_rules:
99+
- crowdsecurity/base-config
100+
- crowdsecurity/vpatch-*
101+
- custom/critical-patches
102+
```
103+
104+
#### `outofband_rules` (optional)
105+
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.
106+
107+
```yaml
108+
outofband_rules:
109+
- crowdsecurity/crs
110+
- custom/detection-rules
111+
```
112+
113+
### Remediation Configuration
114+
115+
#### `default_remediation` (optional, default: "ban")
116+
Default action for in-band rules that match. Special value `allow` prevents blocking.
117+
118+
```yaml
119+
default_remediation: ban # or "allow", "captcha", etc.
120+
```
121+
122+
#### `default_pass_action` (optional, default: "allow")
123+
Action for requests that don't match any rules or match rules with pass action.
124+
125+
```yaml
126+
default_pass_action: allow # or any custom value
59127
```
60128

61-
## Disabling rules at runtime
129+
### HTTP Response Codes
130+
131+
#### `blocked_http_code` (optional, default: 403)
132+
HTTP status code returned to the remediation component for blocked requests.
133+
134+
#### `passed_http_code` (optional, default: 200)
135+
HTTP status code returned to the remediation component for allowed requests.
136+
137+
#### `user_blocked_http_code` (optional, default: 403)
138+
HTTP status code returned to the end user for blocked requests.
139+
140+
#### `user_passed_http_code` (optional, default: 200)
141+
HTTP status code returned to the end user for allowed requests.
142+
143+
```yaml
144+
blocked_http_code: 403
145+
passed_http_code: 200
146+
user_blocked_http_code: 403
147+
user_passed_http_code: 200
148+
```
149+
150+
### Performance and Processing Options
151+
152+
#### `inband_options` and `outofband_options`
153+
Performance tuning options for rule processing:
154+
155+
```yaml
156+
inband_options:
157+
disable_body_inspection: false # Skip HTTP body inspection
158+
request_body_in_memory_limit: 1048576 # Max body size in memory (bytes)
159+
160+
outofband_options:
161+
disable_body_inspection: false
162+
request_body_in_memory_limit: 1048576
163+
```
164+
165+
**`disable_body_inspection`**: Set to `true` to skip HTTP body analysis for performance.
166+
**`request_body_in_memory_limit`**: Maximum request body size to load into memory (default: 1MB). Larger bodies are processed differently.
167+
168+
#### `log_level` (optional)
169+
Logging verbosity for this configuration. Available levels: `debug`, `info`, `warn`, `error`.
170+
171+
```yaml
172+
log_level: info # Use "debug" for troubleshooting
173+
```
174+
175+
### Hook Configuration
176+
177+
AppSec configurations support four types of hooks for custom behavior:
178+
179+
#### `on_load`
180+
Executed when the configuration is loaded. Typically used for global rule modifications.
181+
182+
```yaml
183+
on_load:
184+
- apply:
185+
- RemoveInBandRuleByName("problematic-rule")
186+
```
187+
188+
#### `pre_eval`
189+
Executed before rule evaluation for each request. Supports conditional logic.
190+
191+
```yaml
192+
pre_eval:
193+
- filter: IsInBand && req.RemoteAddr == "192.168.1.100"
194+
apply:
195+
- RemoveInBandRuleByName("strict-rule")
196+
```
197+
198+
#### `post_eval`
199+
Executed after rule evaluation. Useful for debugging and analysis.
200+
201+
```yaml
202+
post_eval:
203+
- filter: IsInBand
204+
apply:
205+
- DumpRequest().WithBody().ToJSON()
206+
```
207+
208+
#### `on_match`
209+
Executed when rules match. Used to modify remediation or generate custom alerts.
210+
211+
```yaml
212+
on_match:
213+
- filter: req.URL.Host == "staging.example.com"
214+
apply:
215+
- SetRemediation("allow")
216+
- CancelAlert()
217+
```
218+
219+
For complete hook documentation, see [AppSec Hooks](/appsec/hooks.md).
220+
221+
## Rule Management
62222

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

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

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
227+
You can disable rules by:
228+
- Name with `RemoveInBandRuleByName`: For CrowdSec rules (name as seen in `cscli appsec-rules list`)
229+
- ID with `RemoveInBandRuleByID`: For seclang/ModSecurity rules by numeric ID
230+
- Tag with `RemoveInBandRuleByTag`: For seclang/ModSecurity rules by tag
71231

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

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

76236
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
77237
name: custom/my_config
@@ -84,20 +244,20 @@ pre_eval:
84244
- RemoveInBandRuleByName("crowdsecurity/generic-wordpress-uploads-php")
85245
```
86246

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

91251
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.
92252

93253
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.
94254

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

97257
```yaml title="/etc/crowdsec/acquis.d/appsec.yaml"
98258
appsec_configs:
99-
- crowdsecurity/appsec-default
100-
- custom/my_config
259+
- crowdsecurity/appsec-default
260+
- custom/my_config
101261
labels:
102262
type: appsec
103263
listen_addr: 127.0.0.1:7422
@@ -126,7 +286,7 @@ pre_eval:
126286

127287
### Disable appsec for a specific FQDN
128288

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):
289+
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):
130290

131291
```yaml title="/etc/crowdsec/appsec-configs/my_config.yaml"
132292
name: custom/my_config

0 commit comments

Comments
 (0)