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
{{ message }}
Repository navigation
Commit 007db2d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: CLAUDE.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,6 @@ Conventions for authoring this skill. This governs how skill content is **writte
32
32
never against the authoring machine.
33
33
-**If you cannot verify something, mark it `untested` or leave it out.** Never present unconfirmed
34
34
behavior as confirmed.
35
+
-**Avoid duplicates** by checking in the existing skill documentation if the information is already present. If it is, ensure it's properly linked/routed, but don't duplicate instruction, code blocks or configurations.
Copy file name to clipboardExpand all lines: crowdsec/references/appsec/deploy.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,21 +113,33 @@ The smoke test above proves the WAF works. For production you point a real bounc
113
113
|---|---|
114
114
| `crowdsec-nginx-bouncer` (lua module) | `APPSEC_URL=http://127.0.0.1:7422` in `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` (shell-style `KEY=VALUE`, empty by default = WAF off). The self-registered `API_KEY` already serves AppSec — reuse it. |
115
115
| Traefik (`maxlerebourg/crowdsec-bouncer-traefik-plugin`) | Flat plugin options: `crowdsecAppsecEnabled: true`(default false), `crowdsecAppsecHost: crowdsec:7422` (host:port, no scheme), and the bouncer key in `crowdsecLapiKey`. Full recipe in [../configure/bouncers/web-servers.md](../configure/bouncers/web-servers.md) § Traefik. |
116
-
| `crowdsec-caddy-bouncer` (Caddy module) | Equivalent `appsec_url` directive on the bouncer block. |
116
+
| `github.com/hslatman/caddy-crowdsec-bouncer` (Caddy module) | Two handlers required in the Caddy route — **`appsec` AND `crowdsec`** (see critical note below). The `appsec_url` field goes in the top-level `crowdsec` app config block. |
117
117
| Any other AppSec-aware bouncer | Look for an `appsec_url` / `appsec.url` field; auth is always the bouncer's existing API key. |
118
118
119
119
After wiring: send a request through the real web server (not directly to 7422) and confirm the verdict propagates. The bouncer's own log should show one line per consultation; AppSec's `cscli metrics show appsec` increments.
120
120
121
+
> **Critical — Caddy (`hslatman/caddy-crowdsec-bouncer`) requires TWO handlers:**
122
+
> the `crowdsec` handler only enforces IP-level bans from LAPI — it does **not** forward requests to port 7422. WAF inspection requires the separate `appsec` handler. Both must be in the route, `appsec` first. If only `crowdsec` is present, AppSec metrics will always show 0 processed and no requests are ever blocked by WAF rules. The `appsec_url` field lives in the top-level `crowdsec` app block. Full Caddyfile and JSON recipes: [../configure/bouncers/web-servers.md](../configure/bouncers/web-servers.md) § Caddy.
123
+
121
124
See also: [../configure/bouncers/web-servers.md](../configure/bouncers/web-servers.md) for installing the bouncer in the first place.
122
125
123
126
## Per-environment notes
124
127
125
128
| Env | What changes |
126
129
|---|---|
127
130
| **systemd / bare-metal** | The recipe above as-is. |
131
+
| **OPNsense / FreeBSD** | Config root is `/usr/local/etc/crowdsec/`; drop acquisition in `acquis.d/appsec.yaml`. The `os-crowdsec` plugin manages the engine — reload with `service crowdsec reload`. No Lua module in the OPNsense nginx package: use the Caddy-based bouncer instead (see [../configure/bouncers/web-servers.md](../configure/bouncers/web-servers.md) § Caddy). Note the LAPI port conflict below. |
128
132
| **Docker / compose** | AppSec runs inside the crowdsec container and must `listen_addr: 0.0.0.0:7422`. Bouncer containers reach it via the service name + internal port (`appsec_url: http://crowdsec:7422`), not the published port. The acquisition file is mounted from the host or baked into a customised image. `docker compose exec crowdsec cscli appsec-*` for management commands. **Containerized lua bouncers need a DNS `resolver` — see [../install/docker.md](../install/docker.md) § Bouncer key bootstrap.** |
129
133
| **Kubernetes / Helm** | The official chart has `appsec.enabled: true` plus values for `appsec.listen_addr`, `appsec.config`, and a separate `appsec` Service. Bouncers target the AppSec Service DNS name. Required collections/rules can be listed in the chart's hub config. |
130
134
135
+
### OPNsense / FreeBSD: LAPI port conflict
136
+
137
+
CrowdSec LAPI binds to `127.0.0.1:8080` by default. Any bouncer that listens on `*:8080` (wildcard) will shadow the LAPI only from external IPs — loopback (`127.0.0.1`) always routes to LAPI. This means:
138
+
139
+
- **Do not test via `127.0.0.1:8080`** — you will hit LAPI, not the bouncer.
140
+
- Use the host's internal or external IP for end-to-end testing (e.g. `172.31.x.x:8080` on an AWS instance).
141
+
- If both LAPI and the bouncer bind `:8080`, move the **bouncer's backend** to another port (e.g. `:8888`) and keep the bouncer frontend on `:8080` listening on `0.0.0.0` only — LAPI stays on its loopback bind and the conflict is resolved.
142
+
131
143
## Advanced shapes
132
144
133
145
- **AppSec on a separate host** from the engine: set `listen_addr` to the private interface and protect with mTLS (cert configuration on both bouncer and AppSec sides; documented at <https://docs.crowdsec.net/docs/next/appsec/advanced_deployments>).
Copy file name to clipboardExpand all lines: crowdsec/references/configure/acquisition.md
+70Lines changed: 70 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ problem is here.
15
15
|---|---|
16
16
| Single legacy file |`/etc/crowdsec/acquis.yaml` (`acquisition_path` in `config.yaml`) |
17
17
| Drop-in dir (preferred) |`/etc/crowdsec/acquis.d/*.yaml` (`acquisition_dir` in `config.yaml`) — one file per source set |
18
+
| OPNsense / FreeBSD |`/usr/local/etc/crowdsec/acquis.d/` — same drop-in model; `os-crowdsec` plugin drops files here automatically |
18
19
| Docker | Bind-mount or env (`COLLECTIONS`, plus a mounted `acquis.d`); see Per-environment notes |
19
20
| Kubernetes | The chart's `config.acquisition` values render into the same `acquis.d` files |
20
21
@@ -50,6 +51,38 @@ Glob expansion is evaluated at startup; files created later that match are **not
50
51
up until reload. For high-rotation logs prefer the directory plus a glob over naming each
51
52
file.
52
53
54
+
| Field | Notes |
55
+
|---|---|
56
+
| `filenames` | List of paths; globs are supported. |
57
+
| `labels.type` | **Required.** The parser chain selector. |
58
+
| `force_inotify` | Set `true` to force inotify-based watching on filesystems that don't advertise it (some NFS mounts, older kernels). |
59
+
| `poll_without_inotify` | Set `true` when the file is a **symlink** that rotates by relinking (e.g. OPNsense's `latest.log` pattern). inotify watches the inode, not the path — without polling the engine misses rotation events. |
60
+
61
+
### OPNsense log paths
62
+
63
+
OPNsense writes logs in RFC 5424 syslog format. The path pattern is `/var/log/<facility>/latest.log` where `latest.log` is always a symlink to the newest rotation file.
> **Pitfall — SSH log path on OPNsense:** The `os-crowdsec` plugin ships `acquis.d/opnsense.yaml` which maps `/var/log/audit/latest.log` to the `sshd` collection. This file is the **configd** audit log (web admin actions), not SSH auth. Real SSH authentication events land in `/var/log/system/latest.log` (syslog format). Add a separate `acquis.d/ssh.yaml` pointing at the right path.
73
+
74
+
Because OPNsense's `latest.log` files are symlinks that rotate, always include both options:
75
+
76
+
```yaml
77
+
# acquis.d/ssh.yaml — SSH auth on OPNsense/FreeBSD
78
+
filenames:
79
+
- /var/log/system/latest.log
80
+
labels:
81
+
type: syslog
82
+
force_inotify: true
83
+
poll_without_inotify: true
84
+
```
85
+
53
86
## journald datasource
54
87
55
88
```yaml
@@ -64,6 +97,8 @@ The filter strings are passed straight to `journalctl`. After reload the source
64
97
metrics as `journalctl:journalctl-_SYSTEMD_UNIT=ssh.service`. A typo in the unit name is
65
98
silent — the source reads **0 lines** rather than erroring.
66
99
100
+
Not available on FreeBSD/OPNsense (no systemd).
101
+
67
102
## docker datasource
68
103
69
104
For a CrowdSec **container** reading other containers' stdout/stderr via the Docker socket:
@@ -80,6 +115,28 @@ Requires `/var/run/docker.sock` mounted into the CrowdSec container. The source
80
115
`docker:<container-name>`. Use this instead of a file source when apps log to stdout (the
81
116
12-factor norm in Docker/compose) — there is no log file to bind-mount.
82
117
118
+
## AppSec datasource
119
+
120
+
Tells the engine to spin up an inline WAF listener. This is **not a log reader** — it opens a TCP port that bouncers forward HTTP requests to. The CrowdSec agent evaluates them in-process and returns an allow/block verdict.
121
+
122
+
```yaml
123
+
# acquis.d/appsec.yaml
124
+
source: appsec
125
+
appsec_config: crowdsecurity/appsec-default
126
+
labels:
127
+
type: appsec
128
+
listen_addr: 127.0.0.1:7422
129
+
```
130
+
131
+
| Field | Notes |
132
+
|---|---|
133
+
| `source: appsec` | **Required.** Identifies the datasource type. Without it the engine ignores the block. |
134
+
| `appsec_config` | Hub-installed config name. `crowdsecurity/appsec-default` is included by both canonical WAF collections and carries the health-check test rule. |
135
+
| `listen_addr` | `127.0.0.1:7422` for loopback (single-host bouncer); `0.0.0.0:7422` for cross-host bouncers. |
136
+
| `labels.type: appsec` | Used by out-of-band scenarios. Keep as `appsec`. |
137
+
138
+
The WAF collections must be installed before the engine will start with this config — see [../appsec/deploy.md](../appsec/deploy.md).
139
+
83
140
## When to pick which source
84
141
85
142
| Logs come from… | `source:` |
@@ -115,6 +172,14 @@ sudo cscli explain --log 'May 21 09:00:00 host sshd[123]: Failed password for in
- **Globs are startup-only:** new files matching a glob need a reload to be acquired.
131
196
- **Edited but not applied:** `crowdsec -t` validates the file but does not load it — you
132
197
still need `systemctl reload crowdsec` (or recreate the container / `helm upgrade`).
198
+
- **Symlinked `latest.log` stops updating after rotation:** inotify watches the old inode — add `poll_without_inotify: true` (and optionally `force_inotify: true`).
199
+
- **SSH not detected on OPNsense:** acquisition points at `/var/log/audit/latest.log` (configd, not auth) — point at `/var/log/system/latest.log` with `labels.type: syslog`.
200
+
- **AppSec source fails to start:** WAF collections not installed — `cscli collections install crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules`.
| **OPNsense / FreeBSD** | Config root is `/usr/local/etc/crowdsec/`; drop-in dir is `/usr/local/etc/crowdsec/acquis.d/`. Use `file` source with `poll_without_inotify: true` for symlinked `latest.log` files. No journald. Reload with `service crowdsec reload`. |
139
208
| **Docker / compose** | Mount `./acquis.d:/etc/crowdsec/acquis.d` (and `/var/run/docker.sock` for the docker source). `COLLECTIONS=`/`PARSERS=` env install hub items at start. Run cscli with `docker exec <name> cscli metrics show acquisition`. Recreate the container to apply (a reload signal also works). |
140
209
| **Kubernetes / Helm** | Define sources under `config.acquisition` in values; `helm upgrade --reset-then-reuse-values`. Inspect with `kubectl exec -n <ns> <agent-pod> -- cscli metrics show acquisition`. The `k8s_audit` source needs the API server's audit webhook pointed at the agent. |
@@ -377,26 +397,76 @@ proxying.) Mint a bouncer key with `cscli bouncers add caddy -o raw`.
377
397
}
378
398
```
379
399
380
-
### Verify end-to-end (through Caddy)
400
+
### Config (JSON API — for OPNsense/FreeBSD or programmatic use)
401
+
402
+
The bouncer exposes two handlers and one top-level app:
403
+
404
+
```json
405
+
{
406
+
"apps": {
407
+
"crowdsec": {
408
+
"api_url": "http://127.0.0.1:8080",
409
+
"api_key": "<bouncer-key>",
410
+
"appsec_url": "http://127.0.0.1:7422",
411
+
"ticker_interval": "15s",
412
+
"enable_streaming": true,
413
+
"appsec_fail_open": false
414
+
},
415
+
"http": {
416
+
"servers": {
417
+
"demo": {
418
+
"listen": [":8080"],
419
+
"routes": [
420
+
{
421
+
"handle": [
422
+
{"handler": "appsec"},
423
+
{"handler": "crowdsec"},
424
+
{
425
+
"handler": "reverse_proxy",
426
+
"upstreams": [{"dial": "127.0.0.1:8888"}]
427
+
}
428
+
]
429
+
}
430
+
]
431
+
}
432
+
}
433
+
}
434
+
}
435
+
}
436
+
```
437
+
438
+
| Handler | Function |
439
+
|---|---|
440
+
| `http.handlers.appsec` | Forwards each request to AppSec (port 7422) for WAF inspection — returns 403 on inband rule match |
441
+
| `http.handlers.crowdsec` | Checks the LAPI decision list for the client IP — returns 403 on active ban |
442
+
443
+
> **Both handlers are required.** `crowdsec` alone silently skips WAF inspection — `cscli metrics show appsec` will show 0 processed. Put `appsec` first in the route.
cscli metrics show appsec # confirm processed/blocked counters
390
458
```
391
459
460
+
> **Do not test via `127.0.0.1:<bouncer-port>`** if LAPI is on `127.0.0.1:8080` and the bouncer frontend shares port `8080`. Loopback traffic routes to LAPI, not the bouncer. Use the host's internal/external IP instead.
461
+
392
462
### Pitfalls
393
463
394
-
- **Module not compiled in:** the stock `caddy` image has no `crowdsec` directive — Caddy
395
-
errors on the Caddyfile. You must `xcaddy build` (above) or use a prebuilt image that bundles
396
-
the module.
397
-
- **Real IP:** without `trusted_proxies` + `client_ip_headers`, Caddy treats the proxy/Docker
398
-
hop as the client and bans never match. Set both in the global `servers` block.
399
-
- **Handler order:** put `appsec` before `crowdsec` in the route so WAF inspection runs ahead of
400
-
decision enforcement.
401
-
- **WAF off:** omit `appsec_url` and the module enforces decisions only. AppSec must listen on
402
-
`0.0.0.0:7422`for a containerized Caddy to reach it.
464
+
- **`crowdsec-caddy-bouncer` / `crowdsecurity/caddy-cs-bouncer` do not exist** — these names return 404 on GitHub and pkg.go.dev. The correct module is `github.com/hslatman/caddy-crowdsec-bouncer`.
465
+
- **Module not compiled in:** the stock `caddy` image has no `crowdsec` directive — Caddy errors on the Caddyfile. You must `xcaddy build` (above) or use a prebuilt image that bundles the module.
466
+
- **xcaddy needs `git`** — the build fails with "git not found" on a minimal FreeBSD install. `sudo pkg install -y git` first.
467
+
- **Build to `/tmp`, then copy** — xcaddy may not have write access to `/usr/local/bin` directly; build to `/tmp/caddy-cs`, then `sudo cp`.
468
+
- **Real IP:** without `trusted_proxies` + `client_ip_headers`, Caddy treats the proxy/Docker hop as the client and bans never match. Set both in the global `servers` block.
469
+
- **Handler order:** put `appsec` before `crowdsec` in the route so WAF inspection runs ahead of decision enforcement.
470
+
- **WAF off:** omit `appsec_url` and the module enforces decisions only. AppSec must listen on `0.0.0.0:7422` for a containerized Caddy to reach it.
471
+
- **LAPI port conflict** — see [../../appsec/deploy.md](../../appsec/deploy.md) § OPNsense / FreeBSD: LAPI port conflict.
0 commit comments