Skip to content

Commit 3892ce0

Browse files
authored
Merge pull request #569 from linuxserver/swag-crowdsec-v3init
2 parents 1b2fd98 + 16e1212 commit 3892ce0

File tree

9 files changed

+52
-10
lines changed

9 files changed

+52
-10
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is globally distributed to all container image projects from
2+
# https://github.com/linuxserver/docker-jenkins-builder/blob/master/.editorconfig
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
end_of_line = lf
10+
insert_final_newline = true
11+
# trim_trailing_whitespace may cause unintended issues and should not be globally set true
12+
trim_trailing_whitespace = false
13+
14+
[{Dockerfile*,**.yml}]
15+
indent_style = space
16+
indent_size = 2
17+
18+
[{**.sh,root/etc/cont-init.d/**,root/etc/services.d/**}]
19+
indent_style = space
20+
indent_size = 4

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Set the following environment variables on your SWAG container.
3131
| `CROWDSEC_SECRET_KEY` | **Optional** | reCAPTCHA v2 Secret Key |
3232
| `CROWDSEC_VERSION` | **Optional** | Specify a version of the bouncer to install instead of using the latest release, for example `v1.0.0`. Must be a valid [release tag](https://github.com/crowdsecurity/cs-nginx-bouncer/tags). **Does not support versions older than v1.0.0**.
3333
| `CROWDSEC_F2B_DISABLE` | **Optional** | Set to `true` to disable swag's built-in fail2ban service if you don't need it |
34+
| `CROWDSEC_MODE` | **Optional** | Set to `live` (immediate update) or `stream` to update requests every CROWDSEC_UPDATE_FREQUENCY seconds. Defaults to `live` |
35+
| `CROWDSEC_UPDATE_FREQUENCY` | **Optional** | Set update frequency for use with `stream` mode. Defaults to `10`. |
3436
| | | |
3537

3638
The variables need to remain in place while you are using the mod. If you remove **required** variables the bouncer will be disabled the next time you recreate the container, if you remove **optional** variables the associated features will be disabled the next time you recreate the container.
@@ -40,3 +42,9 @@ The variables need to remain in place while you are using the mod. If you remove
4042
If you're using the reCAPTCHA capability and you're running in an IPv4-only environment then you need to edit your `/config/nginx/resolver.conf` and add `ipv6=off` to the end of the `resolver` statement otherwise the bouncer will attempt to contact the reCAPTCHA endpoint over IPv6 and fail.
4143

4244
e.g. `resolver 127.0.0.11 valid=30s ipv6=off;`
45+
46+
## Versions
47+
48+
* **28.01.23:** - Support mode selection, handle s6v3 init.
49+
* **25.08.22:** - Make hybrid mod.
50+
* **14.03.22:** - Initial Release.

root/etc/cont-init.d/98-crowdsec

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
CONFIG_PATH="/config/crowdsec/"
45
LIB_PATH="/usr/local/lua/crowdsec/"
@@ -21,7 +22,7 @@ apk add -U --upgrade --no-cache \
2122
nginx-mod-http-lua
2223

2324
# Download nginx bouncer
24-
if [ -z ${CROWDSEC_VERSION+x} ]; then \
25+
if [[ -z ${CROWDSEC_VERSION+x} ]]; then \
2526
CROWDSEC_VERSION=$(curl -sX GET "https://api.github.com/repos/crowdsecurity/cs-nginx-bouncer/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]');
2627
fi
2728

@@ -36,7 +37,7 @@ tar xf \
3637
/tmp/crowdsec --strip-components=1
3738

3839
mkdir -p "${CONFIG_PATH}"
39-
if [ ! -f "${CONFIG_PATH}crowdsec-nginx-bouncer.conf" ]; then \
40+
if [[ ! -f "${CONFIG_PATH}crowdsec-nginx-bouncer.conf" ]]; then \
4041
cp /tmp/crowdsec/lua-mod/config_example.conf "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
4142
fi
4243

@@ -48,6 +49,10 @@ sed -i -r "s|API_URL=.*$|API_URL=${CROWDSEC_LAPI_URL}|" "${CONFIG_PATH}crowdsec-
4849
sed -i -r "s|SECRET_KEY=.*$|SECRET_KEY=${CROWDSEC_SECRET_KEY}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
4950
sed -i -r "s|SITE_KEY=.*$|SITE_KEY=${CROWDSEC_SITE_KEY}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
5051

52+
# Sed in CROWDSEC_MODE and UPDATE_FREQUENCY, if defined in the env, defaults to live and 10s
53+
sed -i -r "s|MODE=.*$|MODE=${CROWDSEC_MODE:-live}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
54+
sed -i -r "s|UPDATE_FREQUENCY=.*$|UPDATE_FREQUENCY=${CROWDSEC_UPDATE_FREQUENCY:-10}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
55+
5156
# Change config path
5257
sed -i "s|/etc/crowdsec/bouncers/|${CONFIG_PATH}|" /tmp/crowdsec/nginx/crowdsec_nginx.conf
5358

root/etc/s6-overlay/s6-rc.d/init-mod-swag-crowdsec-f2b/dependencies.d/legacy-services

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
3+
4+
# Disable f2b if requested
5+
if [[ ${CROWDSEC_F2B_DISABLE,,} == "true" ]]; then
6+
echo "**** Disabling fail2ban Service ****"
7+
s6-svc -d /run/service/svc-fail2ban
8+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mod-swag-crowdsec-f2b/run

root/etc/s6-overlay/s6-rc.d/init-mod-swag-crowdsec/run

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/with-contenv bash
2+
# shellcheck shell=bash
23

34
CONFIG_PATH="/config/crowdsec/"
45
LIB_PATH="/usr/local/lua/crowdsec/"
@@ -21,7 +22,7 @@ echo "\
2122
nginx-mod-http-lua" >> /mod-repo-packages-to-install.list
2223

2324
# Download nginx bouncer
24-
if [ -z ${CROWDSEC_VERSION+x} ]; then \
25+
if [[ -z ${CROWDSEC_VERSION+x} ]]; then \
2526
CROWDSEC_VERSION=$(curl -sX GET "https://api.github.com/repos/crowdsecurity/cs-nginx-bouncer/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]');
2627
fi
2728

@@ -36,7 +37,7 @@ tar xf \
3637
/tmp/crowdsec --strip-components=1
3738

3839
mkdir -p "${CONFIG_PATH}"
39-
if [ ! -f "${CONFIG_PATH}crowdsec-nginx-bouncer.conf" ]; then \
40+
if [[ ! -f "${CONFIG_PATH}crowdsec-nginx-bouncer.conf" ]]; then \
4041
cp /tmp/crowdsec/lua-mod/config_example.conf "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
4142
fi
4243

@@ -48,6 +49,10 @@ sed -i -r "s|API_URL=.*$|API_URL=${CROWDSEC_LAPI_URL}|" "${CONFIG_PATH}crowdsec-
4849
sed -i -r "s|SECRET_KEY=.*$|SECRET_KEY=${CROWDSEC_SECRET_KEY}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
4950
sed -i -r "s|SITE_KEY=.*$|SITE_KEY=${CROWDSEC_SITE_KEY}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
5051

52+
# Sed in CROWDSEC_MODE and UPDATE_FREQUENCY, if defined in the env, defaults to live and 10s
53+
sed -i -r "s|MODE=.*$|MODE=${CROWDSEC_MODE:-live}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
54+
sed -i -r "s|UPDATE_FREQUENCY=.*$|UPDATE_FREQUENCY=${CROWDSEC_UPDATE_FREQUENCY:-10}|" "${CONFIG_PATH}crowdsec-nginx-bouncer.conf"
55+
5156
# Change config path
5257
sed -i "s|/etc/crowdsec/bouncers/|${CONFIG_PATH}|" /tmp/crowdsec/nginx/crowdsec_nginx.conf
5358

@@ -84,10 +89,4 @@ rm -rf \
8489
/tmp/crowdsec \
8590
/tmp/crowdsec.tar.gz
8691

87-
# Disable f2b if requested
88-
if [[ $CROWDSEC_F2B_DISABLE == "true" ]]; then
89-
echo "**** Disabling fail2ban Service ****"
90-
touch /etc/services.d/fail2ban/down
91-
fi
92-
9392
echo "**** Successfully configured CrowdSec nginx Bouncer ${CROWDSEC_VERSION} ****"

root/etc/s6-overlay/s6-rc.d/user2/contents.d/init-mod-swag-crowdsec-f2b

Whitespace-only changes.

0 commit comments

Comments
 (0)