Skip to content

Commit 13b660d

Browse files
committed
Added Crowdsec Bouncer 1.0.1.
1 parent 488141f commit 13b660d

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ ARG DOCKER_IMAGE_VERSION=
99

1010
# Define software versions.
1111
ARG OPENRESTY_VERSION=1.19.9.1
12+
ARG CROWDSEC_OPENRESTY_BOUNCER_VERSION=1.0.1
1213
ARG NGINX_PROXY_MANAGER_VERSION=2.10.4
1314
ARG NGINX_HTTP_GEOIP2_MODULE_VERSION=3.3
1415
ARG LIBMAXMINDDB_VERSION=1.5.0
1516
ARG BCRYPT_TOOL_VERSION=1.1.2
1617

1718
# Define software download URLs.
1819
ARG OPENRESTY_URL=https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz
20+
ARG CROWDSEC_OPENRESTY_BOUNCER_URL=https://github.com/crowdsecurity/cs-openresty-bouncer/releases/download/v${CROWDSEC_OPENRESTY_BOUNCER_VERSION}/crowdsec-openresty-bouncer.tgz
1921
ARG NGINX_PROXY_MANAGER_URL=https://github.com/jc21/nginx-proxy-manager/archive/v${NGINX_PROXY_MANAGER_VERSION}.tar.gz
2022
ARG NGINX_HTTP_GEOIP2_MODULE_URL=https://github.com/leev/ngx_http_geoip2_module/archive/${NGINX_HTTP_GEOIP2_MODULE_VERSION}.tar.gz
2123
ARG LIBMAXMINDDB_URL=https://github.com/maxmind/libmaxminddb/releases/download/${LIBMAXMINDDB_VERSION}/libmaxminddb-${LIBMAXMINDDB_VERSION}.tar.gz
@@ -78,6 +80,14 @@ RUN \
7880
find /tmp/certbot-install/usr/lib/python3.10/site-packages -type f -name "*.exe" -delete && \
7981
find /tmp/certbot-install/usr/lib/python3.10/site-packages -type d -name tests -print0 | xargs -0 rm -r
8082

83+
# Build cs-openresty-boucner.
84+
FROM alpine:3.16 AS cs-openresty-bouncer
85+
ARG TARGETPLATFORM
86+
ARG CROWDSEC_OPENRESTY_BOUNCER_URL
87+
COPY --from=xx / /
88+
COPY src/cs-openresty-bouncer /build
89+
RUN /build/build.sh "$CROWDSEC_OPENRESTY_BOUNCER_URL"
90+
8191
# Pull base image.
8292
FROM jlesage/baseimage:alpine-3.16-v3.5.2
8393

@@ -117,6 +127,7 @@ COPY --from=nginx /tmp/openresty-install/ /
117127
COPY --from=npm /tmp/nginx-proxy-manager-install/ /
118128
COPY --from=bcrypt-tool /tmp/go/bin/bcrypt-tool /usr/bin/
119129
COPY --from=certbot /tmp/certbot-install/ /
130+
COPY --from=cs-openresty-bouncer /tmp/crowdsec-openresty-bouncer-install/ /
120131

121132
# Set internal environment variables.
122133
RUN \
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
set -e # Exit immediately if a command exits with a non-zero status.
4+
5+
mkdir -p /config/crowdsec/templates
6+
echo "Deploy Crowdsec Openresty Bouncer.."
7+
sed -i 's|/defaults/crowdsec|/config/crowdsec|' /etc/nginx/conf.d/crowdsec_openresty.conf
8+
9+
if [ -f /data/crowdsec/crowdsec-openresty-bouncer.conf ]; then
10+
echo "Patch crowdsec-openresty-bouncer.conf .."
11+
sed "s/=.*//g" /config/crowdsec/crowdsec-openresty-bouncer.conf > /tmp/crowdsec.conf.raw
12+
sed "s/=.*//g" /defaults/crowdsec/crowdsec-openresty-bouncer.conf > /tmp/crowdsec-openresty-bouncer.conf.raw
13+
if grep -vf /tmp/crowdsec.conf.raw /tmp/crowdsec-openresty-bouncer.conf.raw ; then
14+
grep -vf /tmp/crowdsec.conf.raw /tmp/crowdsec-openresty-bouncer.conf.raw > /tmp/config.newvals
15+
cp /config/crowdsec/crowdsec-openresty-bouncer.conf /config/crowdsec/crowdsec-openresty-bouncer.conf.bak
16+
grep -f /tmp/config.newvals /defaults/crowdsec/crowdsec-openresty-bouncer.conf >> /config/crowdsec/crowdsec-openresty-bouncer.conf
17+
fi
18+
else
19+
echo "Deploy new crowdsec-openresty-bouncer.conf .."
20+
cp /defaults/crowdsec/crowdsec-openresty-bouncer.conf /config/crowdsec/crowdsec-openresty-bouncer.conf
21+
fi
22+
#Make sure the config location is where we get the config from instead of /default/
23+
sed -i 's|/defaults/crowdsec|/config/crowdsec|' /config/crowdsec/crowdsec-openresty-bouncer.conf
24+
echo "Deploy Crowdsec Templates .."
25+
#Make sure we only copy files that don't exist in /data/crowdsec.
26+
cd /defaults/crowdsec/templates/
27+
for file in *.html
28+
do
29+
if [ ! -e "/config/crowdsec/templates/${file}" ]
30+
then
31+
cp -r "/defaults/crowdsec/templates/${file}" "/config/crowdsec/templates/"
32+
fi
33+
done

src/cs-openresty-bouncer/build.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
set -e # Exit immediately if a command exits with a non-zero status.
4+
set -u # Treat unset variables as an error.
5+
6+
log() {
7+
echo ">>> $*"
8+
}
9+
10+
CROWDSEC_OPENRESTY_BOUNCER_URL="${1:-}"
11+
12+
ROOTFS=/tmp/crowdsec-openresty-bouncer-install
13+
14+
if [ -z "$CROWDSEC_OPENRESTY_BOUNCER_URL" ]; then
15+
log "ERROR: bcrypt tool version missing."
16+
exit 1
17+
fi
18+
19+
#
20+
# Install required packages.
21+
#
22+
23+
apk --no-cache add \
24+
build-base \
25+
gettext \
26+
curl \
27+
bash \
28+
29+
#
30+
# Build.
31+
#
32+
33+
log "Downloading Crowdsec Openresty Bouncer package..."
34+
mkdir /tmp/crowdsec-openresty-bouncer
35+
curl -# -L "${CROWDSEC_OPENRESTY_BOUNCER_URL}" | tar xz --strip 1 -C /tmp/crowdsec-openresty-bouncer
36+
log "Deploy Crowdsec Openresty Bouncer..."
37+
cd /tmp/crowdsec-openresty-bouncer
38+
bash ./install.sh --NGINX_CONF_DIR=${ROOTFS}/etc/nginx/conf.d --LIB_PATH=${ROOTFS}/var/lib/nginx/lualib --CONFIG_PATH=${ROOTFS}/defaults/crowdsec/ --DATA_PATH=${ROOTFS}/defaults/crowdsec/ --SSL_CERTS_PATH=/etc/ssl/certs/ca-cert-GTS_Root_R1.pem --docker
39+
sed -i 's|/tmp/crowdsec-openresty-bouncer-install||g' ${ROOTFS}/etc/nginx/conf.d/crowdsec_openresty.conf
40+
sed -i 's|ENABLED=.*|ENABLED=false|' ${ROOTFS}/defaults/crowdsec/crowdsec-openresty-bouncer.conf

src/openresty/build.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ make -C /tmp/openresty -j$(nproc)
180180
log "Installing OpenResty..."
181181
make DESTDIR=/tmp/openresty-install -C /tmp/openresty install
182182

183+
#Install lua-resty-http required for Crowdsec OpenResty Bouncer
184+
/tmp/openresty-install/var/lib/nginx/bin/opm --install-dir="/tmp/openresty-install/var/lib/nginx/site/" get pintsized/lua-resty-http
185+
183186
rm -r \
184187
/tmp/openresty-install/etc/nginx/*.default \
185188
/tmp/openresty-install/var/lib/nginx/bin/opm \
@@ -189,5 +192,4 @@ rm -r \
189192
/tmp/openresty-install/var/lib/nginx/bin/md2pod.pl \
190193
/tmp/openresty-install/var/lib/nginx/pod \
191194
/tmp/openresty-install/var/lib/nginx/resty.index \
192-
/tmp/openresty-install/var/lib/nginx/site \
193195
/tmp/openresty-install/var/run \

0 commit comments

Comments
 (0)