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

Added crowdsec openresty bouncer support #2677

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

LePresidente
Copy link

@LePresidente LePresidente commented Mar 13, 2023

Re Opened old PR that was closed due to force sync on develop branch

#1875

This adds support for Nginx Proxy Manager to be a firewall bouncer for Crowdsec

Blog post on what this does
https://crowdsec.net/blog/nginx-bouncer-v1/

Blog post on how to use this PR
https://www.crowdsec.net/blog/crowdsec-with-nginx-proxy-manager

This has been expanded to be a permanent addon to Nginx Proxy Manager,
This requires the following changes to the base image
NginxProxyManager/docker-nginx-full#7

There are three Configurations that would be needed to be configurable from Nginx Proxy Manager to configure the crowdsec-openresty-bouncer for the bare minimum to get it working

File: /data/crowdsec/crowdsec-openresty-bouncer.conf

#Enables/Disables the Proxy (true|false)
ENABLED=false
#URL to the crowdsec api
API_URL=
#APIKEY to the crowdsec api, generated on crowdsec using `cscli bouncers add NPM`
API_KEY=

I'm not really sure how to do the frontend, if I can get some guidance I could do it as well

This is also currently a global setting so if an IP is banned it won't be able to connect to any host.

Full config for crowdsec

ENABLED=true
API_URL=http://localhost:8080
API_KEY=
CACHE_EXPIRATION=1
# bounce for all type of remediation that the bouncer can receive from the local API
BOUNCING_ON_TYPE=all
FALLBACK_REMEDIATION=ban
REQUEST_TIMEOUT=3000
UPDATE_FREQUENCY=10
# live or stream
MODE=stream
# exclude the bouncing on those location
EXCLUDE_LOCATION=
#those apply for "ban" action
# /!\ REDIRECT_LOCATION and RET_CODE can't be used together. REDIRECT_LOCATION take priority over RET_CODE
BAN_TEMPLATE_PATH=/data/crowdsec/templates/ban.html
REDIRECT_LOCATION=
RET_CODE=
#those apply for "captcha" action
# ReCaptcha Secret Key
SECRET_KEY=
# Recaptcha Site key
SITE_KEY=
CAPTCHA_TEMPLATE_PATH=/data/crowdsec/templates/captcha.html
CAPTCHA_EXPIRATION=3600

@a1ad
Copy link

a1ad commented Mar 26, 2023

@LePresidente can I just use: jc21/nginx-proxy-manager:github-pr-2677 to test the PR?

@LePresidente
Copy link
Author

use this lepresidente/nginxproxymanager:latest as it requires a change in the base image

@pittbull
Copy link

I had your image running for a long time but after a recent update I am not able to get this back into a running state. I am using this image: lepresidente/nginx-proxy-manager and I've configured the image to point to my existing data (which works with jc21's original image). What I am seeing from the logs are this (which keeps on repeating):
[app ] [3/28/2023] [9:48:51 PM] [Migrate ] › ℹ info Current database version: none [app ] [3/28/2023] [9:48:51 PM] [Global ] › ✖ error Command failed: . /opt/certbot/bin/activate && pip install certbot-dns-cloudflare==$(certbot --version | grep -Eo '[0-9](\.[0-9]+)+') cloudflare && deactivate [app ] /bin/sh: .: line 0: can't open '/opt/certbot/bin/activate': No such file or directory [supervisor ] all services started. [app ] [3/28/2023] [9:48:52 PM] [Global ] › ℹ info Manual db configuration already exists, skipping config creation from environment variables [app ] [3/28/2023] [9:48:52 PM] [Migrate ] › ℹ info Current database version: none [app ] [3/28/2023] [9:48:52 PM] [Global ] › ✖ error Command failed: . /opt/certbot/bin/activate && pip install certbot-dns-cloudflare==$(certbot --version | grep -Eo '[0-9](\.[0-9]+)+') cloudflare && deactivate [app ] /bin/sh: .: line 0: can't open '/opt/certbot/bin/activate': No such file or directory

@pittbull
Copy link

pittbull commented Mar 28, 2023

Having found this pull request and updated my docker to use the image you stated above I am now presented with a different error:

[3/28/2023] [10:18:02 PM] [SSL ] › ✖ error Error: Command failed: certbot renew --non-interactive --quiet --config "/etc/letsencrypt.ini" --preferred-challenges "dns,http" --disable-hook-validation
Renewal configuration file /etc/letsencrypt/renewal/npm-1.conf (cert: npm-1) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-2.conf (cert: npm-2) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-3.conf (cert: npm-3) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-4.conf (cert: npm-4) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-5.conf (cert: npm-5) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-6.conf (cert: npm-6) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-7.conf (cert: npm-7) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-8.conf (cert: npm-8) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.
Renewal configuration file /etc/letsencrypt/renewal/npm-9.conf (cert: npm-9) produced an unexpected error: 'Namespace' object has no attribute 'dns_cloudflare_credentials'. Skipping.

@pittbull
Copy link

Manually executing this: pip3 install certbot-dns-cloudflare removes the error and the log states:

[3/28/2023] [10:41:15 PM] [Global ] › ℹ info Backend PID 106 listening on port 3000 ...
[3/28/2023] [10:41:15 PM] [Nginx ] › ℹ info Reloading Nginx
[3/28/2023] [10:41:15 PM] [SSL ] › ℹ info Renew Complete

I am not able to log in though using either my original username/password or admin@example.

@LePresidente
Copy link
Author

I had your image running for a long time but after a recent update I am not able to get this back into a running state. I am using this image: lepresidente/nginx-proxy-manager and I've configured the image to point to my existing data (which works with jc21's original image). What I am seeing from the logs are this (which keeps on repeating): [app ] [3/28/2023] [9:48:51 PM] [Migrate ] › ℹ info Current database version: none [app ] [3/28/2023] [9:48:51 PM] [Global ] › ✖ error Command failed: . /opt/certbot/bin/activate && pip install certbot-dns-cloudflare==$(certbot --version | grep -Eo '[0-9](\.[0-9]+)+') cloudflare && deactivate [app ] /bin/sh: .: line 0: can't open '/opt/certbot/bin/activate': No such file or directory [supervisor ] all services started. [app ] [3/28/2023] [9:48:52 PM] [Global ] › ℹ info Manual db configuration already exists, skipping config creation from environment variables [app ] [3/28/2023] [9:48:52 PM] [Migrate ] › ℹ info Current database version: none [app ] [3/28/2023] [9:48:52 PM] [Global ] › ✖ error Command failed: . /opt/certbot/bin/activate && pip install certbot-dns-cloudflare==$(certbot --version | grep -Eo '[0-9](\.[0-9]+)+') cloudflare && deactivate [app ] /bin/sh: .: line 0: can't open '/opt/certbot/bin/activate': No such file or directory

ok so this was my image for https://github.com/jlesage/docker-nginx-proxy-manager which is a fork of this that was done for unraid, and dont think they compatible to interchange so you need to switch back. I'll have to see why its failing or if there is a change upstream since he reworked how the image was built which might of broken things

@LePresidente
Copy link
Author

@pittbull please try the latest image from here for the /jlesage/docker-nginx-proxy-manager image lepresidente/nginx-proxy-manager:dev

@pittbull
Copy link

Using :dev on a replica of the original NPM folder did the trick. Came right up!

This has crowdsec, right? How about modsec?

@garsiv1932
Copy link

@LePresidente, your image works perfectly, but i am experiencing problems with cloudflare SSL certificates.

Here is the error I got....

Screenshot from 2023-04-03 00-18-25

@LaurenceJJones
Copy link

Hey Laurence from crowdsec support. I can see there is a lot of interaction on this PR, I do not know the project very well. Will this be something that will be merged or will user have to rely on forks?

@garsiv1932
Copy link

I migrated my proxy manager to traefik, but its could be nice to get the original proxy manager with crowdsec.

@bmunro-peralex
Copy link

something went wrong yesterday when i tried to update my fork, i'll need to look into this and amybe redo a new squashed commit

@bmunro-peralex
Copy link

I'm going to clean this up and close this PR and open a new one.

LePresidente pushed a commit to LePresidente/nginx-proxy-manager that referenced this pull request Apr 26, 2023
@pittbull
Copy link

@pittbull please try the latest image from here for the /jlesage/docker-nginx-proxy-manager image lepresidente/nginx-proxy-manager:dev

There seem to be a bit of confusion on the various versions available. @LePresidente could you update me which image to now use and if this will get updated along the master image?

@a1ad
Copy link

a1ad commented Sep 10, 2023

@pittbull please try the latest image from here for the /jlesage/docker-nginx-proxy-manager image lepresidente/nginx-proxy-manager:dev

There seem to be a bit of confusion on the various versions available. @LePresidente could you update me which image to now use and if this will get updated along the master image?

Yeah same for me, I still use the old "baudneo" one, and I really want a more up-to-date version.

@LePresidente
Copy link
Author

Lepresidente/nginx-proxy-manager = jlesange/nginx-proxy-manager (up-to-date) (unraid fork I use)
Lepresidente/nginxproxymanager = jc21/nginx-proxy-manager (up-to-date)

They are inplace replacements for the official images.

didn't mean to delete the comment

@tokar86a
Copy link

Should be nice to see something like this added.

@bensmith2697
Copy link

Any chance this will be added?

@a1ad
Copy link

a1ad commented Mar 12, 2024

Edit: never mind, the error is also present in the original base image: #3592

@LePresidente I still use your "Lepresidente/nginxproxymanager" version and just did a docker pull. And now the image won't start with error:

npm  | [3/12/2024] [8:29:55 AM] [Certbot  ] › ▶  start     Installing godaddy...
npm  | [3/12/2024] [8:29:55 AM] [Global   ] › ⬤  debug     CMD: . /opt/certbot/bin/activate && pip install --no-cache-dir  certbot-dns-godaddy==$(certbot --version | grep -Eo '[0-9](\.[0-9]+)+')  && deactivate
npm  | [3/12/2024] [8:29:56 AM] [Certbot  ] › ✖  error     ERROR: Could not find a version that satisfies the requirement certbot-dns-godaddy==2.9.0 (from versions: 0.1.0, 0.1.1, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 2.6.0, 2.7.4, 2.8.0)
npm  | ERROR: No matching distribution found for certbot-dns-godaddy==2.9.0

Any idea?

@jrpetersjr
Copy link

jrpetersjr commented Mar 12, 2024

Is there any chance that this gets worked on?

@LePresidente
Copy link
Author

@jrpetersjr I mean it just needs to be tested and merged by the maintainer, I don't think there have been any real complaint from people using my builds that basically includes this PR and NginxProxyManager/docker-nginx-full#8

@a1ad
Copy link

a1ad commented Mar 14, 2024

i am using it for ages, in production and public facing stuff.

@nginxproxymanagerci
Copy link

CI Error:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
certbot-node: Pulling from nginxproxymanager/nginx-full
Digest: sha256:eaa2ebcb50dd87557c9a8f95a3230128d94cac1ea17800261c036e59378e7d49
Status: Image is up to date for nginxproxymanager/nginx-full:certbot-node
docker.io/nginxproxymanager/nginx-full:certbot-node
�[1;34m❯ �[1;36mBuilding Frontend ...�[0m
yarn install v1.22.22
[1/4] Resolving packages...
[2/4] Fetching packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error Command failed.
Exit code: 128
Command: git
Arguments: clone https://github.com/tabler/tabler.git /usr/local/share/.cache/yarn/v6/.tmp/e11a93799a52aa978c82015e29fbe309
Directory: /app/frontend
Output:
Cloning into '/usr/local/share/.cache/yarn/v6/.tmp/e11a93799a52aa978c82015e29fbe309'...
error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
error: 2040 bytes of body are still expected
fetch-pack: unexpected disconnect while reading sideband packet
fatal: early EOF
fatal: fetch-pack: invalid index-pack output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants