Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created startup script as /bin/sh instead of bash #59

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ RUN SSL_CERTS_PATH=/etc/ssl/certs/ca-certificates.crt envsubst '$SSL_CERTS_PATH'
RUN sed -i '1 i\resolver local=on ipv6=off;' /etc/nginx/conf.d/crowdsec_openresty.conf
COPY ./docker/docker_start.sh /

ENTRYPOINT /bin/bash docker_start.sh
ENTRYPOINT /bin/sh docker_start.sh
5 changes: 4 additions & 1 deletion Dockerfile.lua-bouncer-plugin
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ COPY ./ingress-nginx /crowdsec
COPY ./docker/docker_start.sh /

ENV IS_LUALIB_IMAGE=true
ENTRYPOINT /bin/bash docker_start.sh

USER nobody

ENTRYPOINT /bin/sh docker_start.sh
91 changes: 32 additions & 59 deletions docker/docker_start.sh
Original file line number Diff line number Diff line change
@@ -1,63 +1,36 @@
#!/bin/bash
#set -x
#!/bin/sh
set -e
echo "[crowdsec] Starting crowdsec bouncer init"

CROWDSEC_BOUNCER_CONFIG="/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf"

if [ "$BOUNCER_CONFIG" != "" ]; then
CROWDSEC_BOUNCER_CONFIG="$BOUNCER_CONFIG"
fi
if [ "$API_URL" != "" ]; then
sed -i "s,API_URL.*,API_URL=$API_URL," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$API_KEY" != "" ]; then
sed -i "s,API_KEY.*,API_KEY=$API_KEY," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$CACHE_EXPIRATION" != "" ]; then
sed -i "s,CACHE_EXPIRATION.*,CACHE_EXPIRATION=$CACHE_EXPIRATION," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$BOUNCING_ON_TYPE" != "" ]; then
sed -i "s,BOUNCING_ON_TYPE.*,BOUNCING_ON_TYPE=$BOUNCING_ON_TYPE," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$FALLBACK_REMEDIATION" != "" ]; then
sed -i "s,FALLBACK_REMEDIATION.*,FALLBACK_REMEDIATION=$FALLBACK_REMEDIATION," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$REQUEST_TIMEOUT" != "" ]; then
sed -i "s,REQUEST_TIMEOUT.*,REQUEST_TIMEOUT=$REQUEST_TIMEOUT," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$UPDATE_FREQUENCY" != "" ]; then
sed -i "s,UPDATE_FREQUENCY.*,UPDATE_FREQUENCY=$UPDATE_FREQUENCY," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$MODE" != "" ]; then
sed -i "s,MODE.*,MODE=$MODE," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$EXCLUDE_LOCATION" != "" ]; then
sed -i "s,EXCLUDE_LOCATION.*,EXCLUDE_LOCATION=$EXCLUDE_LOCATION," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$BAN_TEMPLATE_PATH" != "" ]; then
sed -i "s,BAN_TEMPLATE_PATH.*,BAN_TEMPLATE_PATH=$BAN_TEMPLATE_PATH," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$REDIRECT_LOCATION" != "" ]; then
sed -i "s,REDIRECT_LOCATION.*,REDIRECT_LOCATION=$REDIRECT_LOCATION," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$RET_CODE" != "" ]; then
sed -i "s,RET_CODE.*,RET_CODE=$RET_CODE," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$SECRET_KEY" != "" ]; then
sed -i "s,SECRET_KEY.*,SECRET_KEY=$SECRET_KEY," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$SITE_KEY" != "" ]; then
sed -i "s,SITE_KEY.*,SITE_KEY=$SITE_KEY," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$CAPTCHA_TEMPLATE_PATH" != "" ]; then
sed -i "s,CAPTCHA_TEMPLATE_PATH.*,CAPTCHA_TEMPLATE_PATH=$CAPTCHA_TEMPLATE_PATH," "$CROWDSEC_BOUNCER_CONFIG"
fi
if [ "$CAPTCHA_EXPIRATION" != "" ]; then
sed -i "s,CAPTCHA_EXPIRATION.*,CAPTCHA_EXPIRATION=$CAPTCHA_EXPIRATION," "$CROWDSEC_BOUNCER_CONFIG"
fi
# Use provided config file if specified
[ -n "$BOUNCER_CONFIG" ] && CROWDSEC_BOUNCER_CONFIG="$BOUNCER_CONFIG"

if [ "$CAPTCHA_PROVIDER" != "" ]; then
sed -i "s,CAPTCHA_PROVIDER.*,CAPTCHA_PROVIDER=$CAPTCHA_PROVIDER," "$CROWDSEC_BOUNCER_CONFIG"
fi
echo "[crowdsec] Setting config in $CROWDSEC_BOUNCER_CONFIG"
# Update configuration values only if they are not empty
[ -n "$API_URL" ] && sed -i "s,API_URL.*,API_URL=$${API_URL}," "$$CROWDSEC_BOUNCER_CONFIG"
[ -n "$API_KEY" ] && sed -i "s,API_KEY.*,API_KEY=$${API_KEY}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$CACHE_EXPIRATION" ] && sed -i "s,CACHE_EXPIRATION.*,CACHE_EXPIRATION=${CACHE_EXPIRATION}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$BOUNCING_ON_TYPE" ] && sed -i "s,BOUNCING_ON_TYPE.*,BOUNCING_ON_TYPE=${BOUNCING_ON_TYPE}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$FALLBACK_REMEDIATION" ] && sed -i "s,FALLBACK_REMEDIATION.*,FALLBACK_REMEDIATION=${FALLBACK_REMEDIATION}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$REQUEST_TIMEOUT" ] && sed -i "s,REQUEST_TIMEOUT.*,REQUEST_TIMEOUT=${REQUEST_TIMEOUT}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$UPDATE_FREQUENCY" ] && sed -i "s,UPDATE_FREQUENCY.*,UPDATE_FREQUENCY=${UPDATE_FREQUENCY}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$MODE" ] && sed -i "s,MODE.*,MODE=${MODE}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$EXCLUDE_LOCATION" ] && sed -i "s,EXCLUDE_LOCATION.*,EXCLUDE_LOCATION=$${EXCLUDE_LOCATION}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$BAN_TEMPLATE_PATH" ] && sed -i "s,BAN_TEMPLATE_PATH.*,BAN_TEMPLATE_PATH=$${BAN_TEMPLATE_PATH}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$REDIRECT_LOCATION" ] && sed -i "s,REDIRECT_LOCATION.*,REDIRECT_LOCATION=$${REDIRECT_LOCATION}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$RET_CODE" ] && sed -i "s,RET_CODE.*,RET_CODE=$${RET_CODE}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$SECRET_KEY" ] && sed -i "s,SECRET_KEY.*,SECRET_KEY=$${SECRET_KEY}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$SITE_KEY" ] && sed -i "s,SITE_KEY.*,SITE_KEY=$${SITE_KEY}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$CAPTCHA_TEMPLATE_PATH" ] && sed -i "s,CAPTCHA_TEMPLATE_PATH.*,CAPTCHA_TEMPLATE_PATH=$${CAPTCHA_TEMPLATE_PATH}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$CAPTCHA_EXPIRATION" ] && sed -i "s,CAPTCHA_EXPIRATION.*,CAPTCHA_EXPIRATION=$${CAPTCHA_EXPIRATION}," "$CROWDSEC_BOUNCER_CONFIG"
[ -n "$CAPTCHA_PROVIDER" ] && sed -i "s,CAPTCHA_PROVIDER.*,CAPTCHA_PROVIDER=$${CAPTCHA_PROVIDER}," "$CROWDSEC_BOUNCER_CONFIG"

if [ "${IS_LUALIB_IMAGE,,}" != "true" ]; then
exec /usr/local/openresty/bin/openresty -g "daemon off;"
fi
# Convert IS_LUALIB_IMAGE to lowercase and check if it's true
if [ "$(echo "$IS_LUALIB_IMAGE" | tr '[:upper:]' '[:lower:]')" != "true" ]; then
/usr/local/openresty/bin/openresty -g "daemon off;"
fi
[ -d "/lua_plugins" ] && mkdir -p /lua_plugins/crowdsec/
[ -d "/lua_plugins/crowdsec" ] && cp -R /crowdsec/* /lua_plugins/crowdsec/
echo "[crowdsec] Init completed"