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/appsec/rules_deploy.md
+47-17Lines changed: 47 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,56 @@
1
1
---
2
2
id: rules_deploy
3
-
title: Custom Rules deployment
3
+
title: Rules deployment
4
4
sidebar_position: 81
5
5
---
6
6
7
7
# WAF Rules Deployment
8
8
9
-
This guide starts once you have already authored and validated a custom AppSec (WAF) rule locally. The steps below focus on packaging that rule so CrowdSec can load it, wiring the configuration into the acquisition pipeline, deploying the files, and finally smoke-testing the result.
9
+
This walkthrough assumes you already wrote and validated a custom AppSec (WAF) rule. We will deploy a concrete example so you can mirror the exact commands on your host.
10
+
11
+
## Example Rule We Will Deploy
12
+
13
+
The example blocks any `GET` request whose `user_id` query argument contains non-numeric characters. While you iterate locally, keep it in a working directory as `./block-nonnumeric-user-id.yaml`:
14
+
15
+
```yaml title="./block-nonnumeric-user-id.yaml"
16
+
name: custom/block-nonnumeric-user-id
17
+
description: Block GET requests with a non-numeric user_id parameter.
18
+
rules:
19
+
- and:
20
+
- zones:
21
+
- METHOD
22
+
match:
23
+
type: equals
24
+
value: GET
25
+
- zones:
26
+
- ARGS
27
+
variables:
28
+
- user_id
29
+
match:
30
+
type: regex
31
+
value: "[^0-9]"
32
+
labels:
33
+
type: exploit
34
+
service: http
35
+
confidence: 2
36
+
spoofable: 0
37
+
behavior: "http:exploit"
38
+
label: "Non numeric user id"
39
+
```
40
+
41
+
Once the rule behaves as expected, the remaining steps package it for CrowdSec, wire it into the acquisition pipeline, and test it end to end.
10
42
11
43
## Step 1 — Stage the Rule File
12
44
13
45
CrowdSec loads AppSec rules from `/etc/crowdsec/appsec-rules/`. Copy your YAML rule into that directory (create a `custom/` subfolder to keep things tidy if you manage several rules):
Make sure the `name` inside the rule file matches the file name convention you plan to reference (for example `custom/my-virtual-patch`).
53
+
Make sure the `name` inside the rule file matches the file name convention you plan to reference (in our example `custom/block-nonnumeric-user-id`).
22
54
23
55
:::tip
24
56
If you run CrowdSec in a container, copy the file into the volume that is mounted at `/etc/crowdsec/appsec-rules/` inside the container.
@@ -28,17 +60,17 @@ If you run CrowdSec in a container, copy the file into the volume that is mounte
28
60
29
61
An AppSec configuration lists which rules to load and how to handle matches. Create a new file under `/etc/crowdsec/appsec-configs/` that targets your custom rule:
- `name`is how you will reference this configuration from the acquisition file and in logs.
41
-
-`inband_rules` (and/or `outofband_rules`) accept glob patterns, so you can load multiple rules with a single entry such as `custom/my-virtual-patch-*`.
73
+
- `inband_rules`(and/or `outofband_rules`) accept glob patterns, so you can load multiple rules with a single entry such as `custom/block-*`.
42
74
- Keep file permissions restrictive (`640`) so only the `crowdsec` user can read the file.
43
75
- During the reload step CrowdSec validates the syntax; if anything is off, the reload fails and the service logs the parsing error.
The rule should appear as `enabled`, and the configuration should show up in the list. CrowdSec logs confirm the configuration was loaded without errors.
78
110
79
111
## Step 5 — Functional Test with `curl`
80
112
81
-
Trigger the behaviour your rule is meant to catch to ensure it blocks as expected. For example, if the rule protects `/admin` against a malicious header, you can test from the WAF host:
113
+
Trigger the behaviour your rule is meant to catch to ensure it blocks as expected. For the example rule, send a request with a non-numeric `user_id` value:
82
114
83
115
```bash
84
-
curl -i -H 'X-Foobar-Bypass: 1' \
85
-
-d 'user_id=123;cat /etc/passwd&do=yes' \
86
-
http://127.0.0.1/admin
116
+
curl -i 'http://127.0.0.1/profile?user_id=abc123'
87
117
```
88
118
89
119
A successful block returns an HTTP status such as `403 Forbidden`, and CrowdSec logs a matching alert:
If the request is not blocked, double-check that the rule `name` matches the pattern in your AppSec configuration, that the acquisition file lists your configuration, and that the CrowdSec service picked up the changes.
0 commit comments