Skip to content

Commit 60b9732

Browse files
committed
bump openresty documentation
1 parent 3d5c611 commit 60b9732

File tree

2 files changed

+77
-14
lines changed

2 files changed

+77
-14
lines changed

crowdsec-docs/unversioned/bouncers/nginx.mdx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,46 @@ SSL_VERIFY=true
202202
The Remediation Component NGINX configuration is located in `/etc/nginx/conf.d/crowdsec_nginx.conf` :
203203

204204
```bash title="/etc/nginx/conf.d/crowdsec_nginx.conf"
205-
lua_package_path '/usr/lib/crowdsec/lua/?.lua;;';
205+
lua_package_path '/usr/local/lua/crowdsec/?.lua;;';
206206
lua_shared_dict crowdsec_cache 50m;
207-
resolver 8.8.8.8 ipv6=off;
208207
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
209208
init_by_lua_block {
210209
cs = require "crowdsec"
211-
local ok, err = cs.init("/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf", "crowdsec-nginx-bouncer/v0.0.7")
210+
local ok, err = cs.init("/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf", "crowdsec-nginx-bouncer/v1.1.3")
212211
if ok == nil then
213212
ngx.log(ngx.ERR, "[Crowdsec] " .. err)
214213
error()
215214
end
216215
ngx.log(ngx.ALERT, "[Crowdsec] Initialisation done")
217216
}
218217

218+
map $server_addr $unix {
219+
default 0;
220+
"~unix:" 1;
221+
}
222+
219223
access_by_lua_block {
220-
local cs = require "crowdsec"
221-
cs.Allow(ngx.var.remote_addr)
224+
local cs = require "crowdsec"
225+
if ngx.var.unix == "1" then
226+
ngx.log(ngx.DEBUG, "[Crowdsec] Unix socket request ignoring...")
227+
else
228+
cs.Allow(ngx.var.remote_addr)
229+
end
222230
}
223-
```
231+
232+
init_worker_by_lua_block {
233+
cs = require "crowdsec"
234+
local mode = cs.get_mode()
235+
if string.lower(mode) == "stream" then
236+
ngx.log(ngx.INFO, "Initializing stream mode for worker " .. tostring(ngx.worker.id()))
237+
cs.SetupStream()
238+
end
239+
240+
if ngx.worker.id() == 0 then
241+
ngx.log(ngx.INFO, "Initializing metrics for worker " .. tostring(ngx.worker.id()))
242+
cs.SetupMetrics()
243+
end
244+
}```
224245
225246
The component uses [lua_shared_dict](https://github.com/openresty/lua-nginx-module#lua_shared_dict) to share cache between all workers.
226247
@@ -279,7 +300,7 @@ If you want to use captcha with your Nginx, you must provide a Site key and Secr
279300
Edit `etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf` and configure the following options:
280301
281302
```bash
282-
CAPTCHA_PROVDER=
303+
CAPTCHA_PROVIDER=
283304
SECRET_KEY=
284305
SITE_KEY=
285306
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html

crowdsec-docs/unversioned/bouncers/openresty.mdx

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import RemediationSupportBadges from '@site/src/components/RemediationSupportBad
2525
<RemediationSupportBadges
2626
Mode
2727
Appsec
28+
Metrics
2829
/>
2930

3031
A lua Remediation Component for OpenResty.
@@ -41,6 +42,7 @@ Supported features:
4142
- Captcha remediation (can return a captcha)
4243
- Works with IPv4/IPv6
4344
- Support IP ranges (can apply a remediation on an IP range)
45+
- Application Security Component (forward request to CrowdSec Application Security Engine and block is necessary)
4446

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

@@ -128,6 +130,8 @@ If you are on a mono-machine setup, the `crowdsec-openresty-bouncer` install scr
128130

129131
### Component configuration
130132

133+
134+
131135
```bash title="/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf"
132136
API_URL=<CROWDSEC_LAPI_URL>
133137
API_KEY=<CROWDSEC_LAPI_KEY>
@@ -159,6 +163,7 @@ SITE_KEY=
159163
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html
160164
CAPTCHA_EXPIRATION=3600
161165

166+
162167
## Application Security Component Configuration
163168
APPSEC_URL=
164169
#### default ###
@@ -171,30 +176,61 @@ SSL_VERIFY=true
171176
################
172177
```
173178

179+
Any `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf.local` content will take
180+
precedence over `/etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf`. All fields
181+
don't have to be present in this `.local.` file.
182+
174183
### OpenResty Configuration
175184

176185
The component OpenResty configuration is located in `/usr/local/openresty/nginx/conf/conf.d/crowdsec_openresty.conf` :
177186

178187
```bash title="/usr/local/openresty/nginx/conf/conf.d/crowdsec_openresty.conf"
179188
lua_package_path '$prefix/../lualib/plugins/crowdsec/?.lua;;';
180189
lua_shared_dict crowdsec_cache 50m;
181-
resolver local=on ipv6=off;
182190
lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
191+
183192
init_by_lua_block {
184193
cs = require "crowdsec"
185-
local ok, err = cs.init("/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf", "crowdsec-openresty-bouncer/v0.0.7")
194+
local ok, err = cs.init("/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf", "crowdsec-openresty-bouncer/v1.1.0")
186195
if ok == nil then
187196
ngx.log(ngx.ERR, "[Crowdsec] " .. err)
188197
error()
189198
end
190-
ngx.log(ngx.ALERT, "[Crowdsec] Initialisation done")
199+
if ok == "Disabled" then
200+
ngx.log(ngx.ALERT, "[Crowdsec] Bouncer Disabled")
201+
else
202+
ngx.log(ngx.ALERT, "[Crowdsec] Initialisation done")
203+
end
204+
}
205+
206+
map $server_addr $unix {
207+
default 0;
208+
"~unix:" 1;
191209
}
192210

193211
access_by_lua_block {
194212
local cs = require "crowdsec"
195-
cs.Allow(ngx.var.remote_addr)
213+
if ngx.var.unix == "1" then
214+
ngx.log(ngx.DEBUG, "[Crowdsec] Unix socket request ignoring...")
215+
else
216+
cs.Allow(ngx.var.remote_addr)
217+
end
196218
}
197-
```
219+
220+
221+
init_worker_by_lua_block {
222+
cs = require "crowdsec"
223+
local mode = cs.get_mode()
224+
if string.lower(mode) == "stream" then
225+
ngx.log(ngx.INFO, "Initializing stream mode for worker " .. tostring(ngx.worker.id()))
226+
cs.SetupStream()
227+
end
228+
229+
if ngx.worker.id() == 0 then
230+
ngx.log(ngx.INFO, "Initializing metrics for worker " .. tostring(ngx.worker.id()))
231+
cs.SetupMetrics()
232+
end
233+
}```
198234
199235
200236
The component uses [lua_shared_dict](https://github.com/openresty/lua-nginx-module#lua_shared_dict) to share cache between all workers.
@@ -254,7 +290,7 @@ If you want to use captcha with your OpenResty, you must provide a Site key and
254290
Edit `etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf` and configure the following options:
255291
256292
```bash
257-
CAPTCHA_PROVDER=
293+
CAPTCHA_PROVIDER=
258294
SECRET_KEY=
259295
SITE_KEY=
260296
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html
@@ -291,7 +327,7 @@ And restart OpenResty.
291327
292328
### Migrate from v0 to v1
293329
294-
The best way to migrate from the crowdsec-openresty-bouncer v0.* to v1 is to reinstall the bouncer. Indeed, many new configurations options are now available and some has been removed.
330+
The best way to migrate from the crowdsec-openresty-bouncer v0.* to v1 is to reinstall the bouncer. Indeed, many new configurations options are now available and some have been removed.
295331
296332
- Backup your CrowdSec Local API key from your configuration file (`/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf`)
297333
- Remove the old component:
@@ -570,3 +606,9 @@ APPSEC_PROCESS_TIMEOUT=500 # default
570606
```
571607
572608
The timeout to process the request from the Remediation Component to the AppSec Component.
609+
610+
### Nginx variables
611+
Nginx variables can be used to adapt behaviour and or more flexible configurations:
612+
* ngx.var.cs_disable_bouncer: set to 1, it will disable the bouncer
613+
* ngx.var.enable_appsec: set to 1, it will enable the appsec even if it's disabled by configuration or if bouncer is disabled
614+
* ngx.var.disable_appsec: set to 1, it will disable the appsec

0 commit comments

Comments
 (0)