Skip to content

Commit 7291e14

Browse files
committed
update
1 parent 6b46b46 commit 7291e14

3 files changed

Lines changed: 90 additions & 152 deletions

File tree

crowdsec-docs/docs/appsec/quickstart/nginx-ingress.mdx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ lapi:
105105
key: BOUNCER_KEY_nginx_ingress_waf
106106
```
107107
108+
:::note
109+
Although this is the same bouncer key value, you need two `Secret` objects here:
110+
one in `crowdsec` and one in `ingress-nginx`. Kubernetes secrets are
111+
namespace-scoped, so the ingress controller cannot read a secret from the
112+
`crowdsec` namespace.
113+
:::
114+
108115
This YAML configuration snippet exposes the important configuration items:
109116
* `listen_addr: 0.0.0.0:7422` exposes the AppSec API inside the cluster.
110117
* `appsec_configs` loads the [AppSec configuration(s)](/appsec/configuration.md) that define which rules are evaluated (in-band vs out-of-band).
@@ -156,8 +163,8 @@ controller:
156163
image:
157164
registry: docker.io
158165
image: crowdsecurity/controller
159-
tag: v1.13.2
160-
digest: sha256:4575be24781cad35f8e58437db6a3f492df2a3167fed2b6759a6ff0dc3488d56
166+
tag: v1.14.3
167+
digest: sha256:9ab8791635f4cde9964ab2562fb8b15faf72fe0205f0fe288089a87e1455675d
161168
extraVolumes:
162169
- name: crowdsec-bouncer-plugin
163170
emptyDir: {}
@@ -236,8 +243,8 @@ controller:
236243
image:
237244
registry: docker.io
238245
image: crowdsecurity/controller
239-
tag: v1.13.2
240-
digest: sha256:...
246+
tag: v1.14.3
247+
digest: sha256:9ab8791635f4cde9964ab2562fb8b15faf72fe0205f0fe288089a87e1455675d
241248
```
242249

243250
The controller image is replaced with a CrowdSec-enabled build that includes the

crowdsec-docs/unversioned/bouncers/ingress-nginx.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ lapi:
9191
key: BOUNCER_KEY_nginx_ingress_waf
9292
```
9393
94+
:::note
95+
Although this is the same bouncer key value, you need two `Secret` objects here:
96+
one in `crowdsec` and one in `ingress-nginx`. Kubernetes secrets are
97+
namespace-scoped, so the ingress controller cannot read a secret from the
98+
`crowdsec` namespace.
99+
:::
100+
94101
Create the secret holding the same key in the `ingress-nginx` namespace:
95102

96103
```yaml title="crowdsec-ingress-bouncer-secret.yaml"
@@ -101,7 +108,7 @@ metadata:
101108
namespace: ingress-nginx
102109
type: Opaque
103110
stringData:
104-
api-key: "<same-value-as-BOUNCER_KEY_nginx_ingress_waf>"
111+
api-key: "<choose-a-long-random-key>"
105112
```
106113

107114
Apply it:

crowdsec-docs/unversioned/bouncers/nginx.mdx

Lines changed: 71 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,22 @@ import RemediationSupportBadges from "@site/src/components/remediation-support-b
2323
<img src="https://img.shields.io/badge/tests-pass-green" />
2424
</p>
2525
<p align="center">
26-
&#x1F4DA; <a href="#install-the-nginx-bouncer">Documentation</a>
26+
&#x1F4DA; <a href="#installation/">Documentation</a>
2727
&#x1F4A0; <a href="https://hub.crowdsec.net">Hub</a>
2828
&#128172; <a href="https://discourse.crowdsec.net">Discourse </a>
2929
</p>
3030

3131
<RemediationSupportBadges Mode Appsec Metrics MTLS />
3232

33-
# CrowdSec Remediation QuickStart for NGINX
34-
35-
## Objectives
36-
37-
This quickstart shows how to deploy the CrowdSec NGINX bouncer on a Linux host
38-
and protect traffic served through [NGINX](https://nginx.com/) using the Lua
39-
remediation component.
40-
41-
At the end, you will have:
42-
43-
- A working NGINX bouncer querying CrowdSec LAPI
44-
- The bouncer loaded in NGINX request processing
45-
- A dedicated bouncer API key registered in CrowdSec
46-
- A safer secret-management pattern that keeps the API key in
47-
`/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local`
48-
49-
This bouncer is a Lua remediation component for NGINX.
33+
A lua Remediation Component for nginx.
5034

5135
:::tip Enable the WAF for optimal protection
5236
After installing the bouncer, enable the [AppSec (WAF) Component](/docs/next/appsec/intro) to get virtual patching and defense against known CVEs, SQL injection, XSS, and other application-layer attacks.
5337

5438
Follow the dedicated [AppSec Quickstart for Nginx/OpenResty](/docs/next/appsec/quickstart/nginxopenresty) — it picks up right where this page ends.
5539
:::
5640

57-
## Prerequisites
58-
59-
1. It is assumed that you already have:
60-
- A working CrowdSec [Security Engine](/intro) installation. For a
61-
Linux install quickstart, refer to
62-
[/u/getting_started/installation/linux](/u/getting_started/installation/linux).
63-
- A working NGINX installation serving traffic on this host.
64-
- NGINX access logs acquired by CrowdSec, so remediation decisions are
65-
created from the real traffic hitting NGINX.
66-
67-
:::warning
68-
This bouncer depends on the NGINX Lua module and has only been tested on
69-
Debian/Ubuntu based distributions.
70-
:::
71-
72-
## How does it work?
41+
## How does it work ?
7342

7443
This component leverages nginx lua's API, namely `access_by_lua_block` to check the IP address against the local API.
7544

@@ -85,28 +54,7 @@ Supported features:
8554

8655
At the back, this component uses [crowdsec lua lib](https://github.com/crowdsecurity/lua-cs-bouncer/).
8756

88-
## Source IPs
89-
90-
For remediation to work correctly, CrowdSec must detect and decide on the same
91-
client IP that NGINX evaluates at request time.
92-
93-
If NGINX is behind a load balancer, CDN, or another reverse proxy, configure
94-
the real IP module so `remote_addr` is rewritten to the original client IP
95-
before the CrowdSec Lua hook runs:
96-
97-
```nginx title="/etc/nginx/conf.d/realip.conf"
98-
set_real_ip_from 10.0.0.0/8;
99-
set_real_ip_from 192.168.0.0/16;
100-
real_ip_header X-Forwarded-For;
101-
real_ip_recursive on;
102-
```
103-
104-
Replace the trusted ranges and header with the values used by your upstream.
105-
106-
If NGINX only sees the proxy IP, CrowdSec will create decisions for the wrong
107-
source and bouncing will not work as expected.
108-
109-
## Install the NGINX bouncer
57+
## Installation
11058

11159
### Dependencies
11260

@@ -117,13 +65,13 @@ sudo apt install nginx lua5.1 libnginx-mod-http-lua luarocks gettext-base lua-cj
11765
```
11866

11967
::::warning
120-
If you have Ubuntu 22.xx, you may have an issue with `lua` module in nginx.
68+
If you have Unbuntu 22.xx, you may have an issue with `lua` module in nginx.
12169
Look at [FAQ for more information](#ubuntu-22xx-getting-lua-error).
12270
::::
12371

12472
### Using packages
12573

126-
First, [setup CrowdSec repositories](/u/getting_started/installation/linux#repository-installation).
74+
First, [setup crowdsec repositories](/u/getting_started/installation/linux#repository-installation).
12775

12876
<Tabs
12977
defaultValue="nginx_debian"
@@ -161,9 +109,9 @@ cd crowdsec-nginx-bouncer-v*/
161109
./install.sh
162110
```
163111

164-
Note: Don't run the script with `sudo` (the script already uses `sudo` to install dependencies).
112+
Note: Don't run the script with `sudo` (the script already use `sudo` to install dependencies).
165113

166-
If you are on a mono-machine setup, the `crowdsec-nginx-bouncer` install script can register directly to the local CrowdSec LAPI. The safer operational pattern is still to manage the API key explicitly as shown below.
114+
If you are on a mono-machine setup, the `crowdsec-nginx-bouncer` install script will register directly to the local crowdsec, so you're good to go !
167115

168116
:warning: the installation script will take care of dependencies for Debian/Ubuntu
169117

@@ -178,82 +126,44 @@ If you are on a mono-machine setup, the `crowdsec-nginx-bouncer` install script
178126

179127
</details>
180128

181-
## Register the bouncer key and store it outside the base config
182-
183-
As with the Envoy and Traefik guides, the practical approach is to choose a
184-
fixed key, register it in CrowdSec, and keep it in a dedicated secret location
185-
instead of editing the package-managed base file.
186-
187-
Generate a key and register the bouncer:
188-
189-
```bash
190-
BOUNCER_KEY="$(openssl rand -hex 32)"
191-
sudo cscli bouncers add nginx-bouncer --key "$BOUNCER_KEY"
192-
```
193-
194-
Then store only the override in
195-
`/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local`:
196-
197-
```bash
198-
sudo install -m 600 /dev/null /etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local
199-
sudo tee /etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local > /dev/null <<EOF
200-
API_KEY=$BOUNCER_KEY
201-
EOF
202-
unset BOUNCER_KEY
203-
```
129+
## Enable the WAF (AppSec Component)
204130

205-
:::important
206-
`/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local` takes precedence
207-
over `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf`.
131+
For real-time WAF protection — virtual patching, defense against known CVEs, SQLi, XSS, and other application-layer attacks — turn on the AppSec Component after installing the bouncer.
208132

209-
Use this `.local` file for secrets and local overrides. Avoid committing a real
210-
`API_KEY=` value in automation, Git repositories, or image templates.
133+
:::tip Recommended: enable the WAF for optimal protection
134+
Follow the [AppSec Quickstart for Nginx/OpenResty](/docs/next/appsec/quickstart/nginxopenresty) to enable the WAF. It's a few copy-paste commands and picks up right where this installation ends.
211135
:::
212136

213-
If your NGINX host does not talk to a local LAPI, also override `API_URL` in
214-
the same file:
215-
216-
```bash title="/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local"
217-
API_URL=http://<lapi-host>:8080
218-
API_KEY=<your-fixed-bouncer-key>
219-
```
137+
The AppSec-related knobs in `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` are documented in the [Configuration Reference](#configuration-reference) below (all `APPSEC_*` entries).
220138

221-
## Verify CrowdSec LAPI access
139+
## Upgrade
222140

223-
Make sure the bouncer appears in CrowdSec and that NGINX can load the bouncer
224-
configuration:
141+
### From package
225142

226143
```bash
227-
sudo cscli bouncers list
228-
sudo nginx -t
229-
sudo systemctl restart nginx
144+
sudo apt-get update
145+
sudo apt-get install crowdsec-nginx-bouncer
230146
```
231147

232-
You should see:
233-
234-
- An `nginx-bouncer` entry in `cscli bouncers list`
235-
- `nginx -t` returning a successful configuration test
236-
- NGINX restarting cleanly
148+
:::warning
149+
Upgrade from v0 to v1 introduce many changes. Pick up the maintainer configuration to avoid anything breaking. Configuration migration might not be trivial.
150+
:::
237151

238-
## Validate remediation
152+
### Manual Upgrade
239153

240-
Create a temporary decision for your client IP and confirm NGINX enforces it:
154+
If you already have `crowdsec-nginx-bouncer` installed, please download the [latest release](https://github.com/crowdsecurity/cs-nginx-bouncer/releases) and run the following commands:
241155

242156
```bash
243-
sudo cscli decisions add -i <IP_TO_TEST> -t ban
244-
curl -I http://<your-nginx-host>/
157+
tar xzvf crowdsec-nginx-bouncer.tgz
158+
cd crowdsec-nginx-bouncer-v*/
159+
sudo ./upgrade.sh
160+
sudo systemctl restart nginx
245161
```
246162

247-
You should get a ban response, typically `403 Forbidden`, or your configured
248-
redirect/custom ban page.
249-
250-
## NGINX bouncer configuration
163+
## Configuration
251164

252165
### Component configuration
253166

254-
The main bouncer configuration is located in
255-
`/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf`.
256-
257167
```bash title="/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf"
258168
API_URL=<CROWDSEC_LAPI_URL>
259169
API_KEY=<CROWDSEC_LAPI_KEY>
@@ -309,10 +219,9 @@ Any `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local` content will take
309219
precedence over `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf`. All fields
310220
don't have to be present in this `.local.` file.
311221

312-
### NGINX configuration
222+
### NGINX Configuration
313223

314-
The remediation component NGINX configuration is located in
315-
`/etc/nginx/conf.d/crowdsec_nginx.conf`:
224+
The Remediation Component NGINX configuration is located in `/etc/nginx/conf.d/crowdsec_nginx.conf` :
316225

317226
```bash title="/etc/nginx/conf.d/crowdsec_nginx.conf"
318227
lua_package_path '/usr/local/lua/crowdsec/?.lua;;';
@@ -379,42 +288,61 @@ You can also change this with a valid one :
379288
- /etc/ssl/cert.pem (OpenBSD, Alpine)
380289
```
381290
382-
## Enable the WAF (AppSec Component)
291+
### Application Security Component Configuration
383292
384-
For real-time WAF protection — virtual patching, defense against known CVEs, SQLi, XSS, and other application-layer attacks — turn on the AppSec Component after installing the bouncer.
293+
To turn on the WAF, follow the [AppSec Quickstart for Nginx/OpenResty](/docs/next/appsec/quickstart/nginxopenresty).
294+
295+
The AppSec-related options in `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf`:
296+
297+
```bash title="/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf"
298+
# Mandatory - set to enable AppSec
299+
APPSEC_URL=http://127.0.0.1:7422
300+
301+
# Optional
302+
APPSEC_FAILURE_ACTION=passthrough # default
303+
APPSEC_CONNECT_TIMEOUT=100 # default
304+
APPSEC_SEND_TIMEOUT=100 # default
305+
APPSEC_PROCESS_TIMEOUT=1000 # default
306+
ALWAYS_SEND_TO_APPSEC=false # default
307+
APPSEC_DROP_UNREADABLE_BODY=false # default
308+
SSL_VERIFY=true # default
309+
```
310+
311+
:::warning
312+
313+
Due to limitations in the underlying library used by the remediation component, by default, the body of any HTTP2/HTTP3 request without a Content-Length will not be analyzed.
314+
To avoid potential bypasses of the WAF, you can set the option `APPSEC_DROP_UNREADABLE_BODY` to `true` to drop any request whose body cannot be inspected.
385315
386-
:::tip Recommended: enable the WAF for optimal protection
387-
Follow the [AppSec Quickstart for Nginx/OpenResty](/docs/next/appsec/quickstart/nginxopenresty) to enable the WAF. It's a few copy-paste commands and picks up right where this installation ends.
388316
:::
389317
390-
The AppSec-related knobs in `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` are documented in the [Configuration Reference](#configuration-reference) below (all `APPSEC_*` entries).
318+
### Setup captcha
391319
392-
## Upgrade
320+
> Currently, we have support for 3 providers: recaptcha, hcaptcha or turnstile
393321
394-
### From package
322+
If you want to use captcha with your Nginx, you must provide a Site key and Secret key in your component configuration. If you wish to use any other provider than recaptcha you must also provide a Captcha provider.
323+
324+
([recaptcha documentation](https://developers.google.com/recaptcha/intro)).
325+
326+
([tunstile documentation](https://developers.cloudflare.com/turnstile/)).
327+
328+
([hcaptcha documentation](https://docs.hcaptcha.com/))
329+
330+
Edit `etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` and configure the following options:
395331
396332
```bash
397-
sudo apt-get update
398-
sudo apt-get install crowdsec-nginx-bouncer
333+
CAPTCHA_PROVIDER=
334+
SECRET_KEY=
335+
SITE_KEY=
336+
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html
337+
CAPTCHA_EXPIRATION=3600
399338
```
400339
401-
:::warning
402-
Upgrade from v0 to v1 introduces many changes. Pick up the maintainer
403-
configuration to avoid anything breaking. Configuration migration might not be
404-
trivial.
405-
:::
406-
407-
### Manual upgrade
340+
Restart Nginx.
408341
409-
If you already have `crowdsec-nginx-bouncer` installed, download the
410-
[latest release](https://github.com/crowdsecurity/cs-nginx-bouncer/releases)
411-
and run:
342+
You can add a decisions with a type `captcha` to check if it works correctly:
412343
413344
```bash
414-
tar xzvf crowdsec-nginx-bouncer.tgz
415-
cd crowdsec-nginx-bouncer-v*/
416-
sudo ./upgrade.sh
417-
sudo systemctl restart nginx
345+
sudo cscli decisions add -i <IP_TO_TEST> -t captcha
418346
```
419347
420348
## FAQ
@@ -469,10 +397,6 @@ CrowdSec Local API key.
469397
470398
Generated with [`sudo cscli bouncers add`](/u/getting_started/installation/linux) command.
471399
472-
For secret-management best practice, keep the real key in
473-
`/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local` rather than
474-
modifying the package-managed base file.
475-
476400
### `API_URL`
477401
478402
> string

0 commit comments

Comments
 (0)