@@ -25,6 +25,7 @@ import RemediationSupportBadges from '@site/src/components/RemediationSupportBad
2525<RemediationSupportBadges
2626 Mode
2727 Appsec
28+ Metrics
2829/>
2930
3031A 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
4547At 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"
132136API_URL=< CROWDSEC_LAPI_URL>
133137API_KEY=< CROWDSEC_LAPI_KEY>
@@ -159,6 +163,7 @@ SITE_KEY=
159163CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html
160164CAPTCHA_EXPIRATION=3600
161165
166+
162167# # Application Security Component Configuration
163168APPSEC_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
176185The 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"
179188lua_package_path ' $prefix/../lualib/plugins/crowdsec/?.lua;;' ;
180189lua_shared_dict crowdsec_cache 50m;
181- resolver local=on ipv6=off;
182190lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
191+
183192init_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
193211access_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
200236The 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
254290Edit ` etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf` and configure the following options:
255291
256292` ` ` bash
257- CAPTCHA_PROVDER =
293+ CAPTCHA_PROVIDER =
258294SECRET_KEY=
259295SITE_KEY=
260296CAPTCHA_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
572608The 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