bunkerity / bunkerweb

🛡️ Open-source and next-generation Web Application Firewall (WAF)
https://www.bunkerweb.io
GNU Affero General Public License v3.0
6.12k stars 339 forks source link

[BUG] in bunkerized-nginx-ui cannot save changes of service #160

Closed derdek closed 3 years ago

derdek commented 3 years ago

Description Hello, in settings.json for EMAIL_LETS_ENCRYPT used bad regex. I propose this changes:

And i have problems with other SSL fields in bunkerized-nginx-ui i think need rewrite regexs for SSL fields

How to reproduce go to bunkerized-nginx-ui, services, select one, click edit, click save

Logs I have the same error text with EMAIL_LETS_ENCRYPT Something went wrong... Variable SELF_SIGNED_SSL_COUNTRY is not valid.Traceback (most recent call last): File "/opt/entrypoint/entrypoint.py", line 89, in services app.config["CONFIG"].check_variables(variables) File "/opt/entrypoint/Config.py", line 77, in check_variables raise Exception("Variable " + k + " is not valid.") Exception: Variable SELF_SIGNED_SSL_COUNTRY is not valid.

hoaivan commented 3 years ago

I got the same issue

fl0ppy-d1sk commented 3 years ago

Hello @derdek,

Regarding EMAIL_LETS_ENCRYPT regex, I don't get the point on why you are allowing any characters ? The mail is passed to the certbot new command and MUST be a valid email like address@domain.tld. Your regex is matching anything with the .{0,} part. The initial .{0} is there for a specific reason : if there is no value set for the EMAIL_LETS_ENCRYPT then bunkerized-nginx will construct a default one like contact@first-domain.tld. Can you share more information on why your change is needed ?

derdek commented 3 years ago

Hello, i can't save my email address for example:

fl0ppy-d1sk commented 3 years ago

I can confirm the regex is not valid... Maybe something like ^([a-z0-9\-\.]+@[a-z\-0-9\.]+|.{0})$ would be ok ?

derdek commented 3 years ago

I testing regex on https://regex101.com/ and this regex work correctly

derdek commented 3 years ago

regex for SELF_SIGNED_SSL_COUNTRY is ^[:print:]+$ and i don't know what do with thit. Default values is CH, but regex say that SELF_SIGNED_SSL_COUNTRY not correct there may be a similar error for other fields it's easy to check, just go to the admin panel, select a service, save changes

derdek commented 3 years ago

https://github.com/bunkerity/bunkerized-nginx/blob/15bdb076c86bd71e7c95944b6e6b89f32556e5e6/settings.json#L613-L666 you can see, that regex is not correct

fl0ppy-d1sk commented 3 years ago

@hoaivan and @derdek : the new 1.2.8 release containing a fix for both SELFSIGNED* and EMAIL_LETS_ENCRYPT should have been pushed to Docker Hub. Let me know if everything is fine (don't forget to do a pull before).

derdek commented 3 years ago

Hello @fl0ppy-d1sk Now, nginx-ui working, but exist bug After save, reverse-proxy can dublicates. For example:

derdek commented 3 years ago

And after update docker images, auto conf exit with error: ERROR - wrong permission on /etc/letsencrypt i try fix this with chown -R 101:101, but this not helped

UPDATE after downgrade autoconf 1.2.7 working correctly, but exist problem with :

myautoconf_1      | Traceback (most recent call last):
myautoconf_1      |   File "/opt/entrypoint/app.py", line 67, in <module>
myautoconf_1      |     autoconf.process(server, event["Action"])
myautoconf_1      |   File "/opt/entrypoint/AutoConf.py", line 82, in process
myautoconf_1      |     self.__process_server(obj, event, id, name, labels)
myautoconf_1      |   File "/opt/entrypoint/AutoConf.py", line 176, in __process_server
myautoconf_1      |     if self.__config.reload() :
myautoconf_1      | TypeError: reload() missing 1 required positional argument: 'instances'
myautoconf_1      | [*] autoconf stopped
fl0ppy-d1sk commented 3 years ago

Can you share your compose so I can reproduce the bug ?

derdek commented 3 years ago


services:

  bunker:
    image: bunkerity/bunkerized-nginx
    restart: always
    ports:
      - 80:8080
      - 443:8443
    volumes:
      - letsencrypt:/etc/letsencrypt
      - /home/sites:/www:ro
      - autoconf:/etc/nginx
    environment:
      - SERVER_NAME=
      - MULTISITE=yes
      - AUTO_LETS_ENCRYPT=yes
      - REDIRECT_HTTP_TO_HTTPS=yes
      - DISABLE_DEFAULT_SERVER=yes
      - USE_CLIENT_CACHE=yes
      - USE_GZIP=yes
    labels:
      - "bunkerized-nginx.AUTOCONF"

  myautoconf:
    image: bunkerity/bunkerized-nginx-autoconf:1.2.7
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - autoconf:/etc/nginx
    depends_on:
      - bunker
      - example.com

  example.com:
    image: php:fpm
    restart: always
    volumes:
      - /home/sites/php-fpm/www.conf:/etc/php-fpm.d/www.conf
      - /home/sites/php-fpm/php-fpm.conf:/etc/php-fpm.conf
      - /home/sites/example.com:/www
    labels:
      - "bunkerized-nginx.SERVER_NAME=example.com"
      - "bunkerized-nginx.REMOTE_PHP=example.com"
      - "bunkerized-nginx.REMOTE_PHP_PATH=public"

volumes:
  letsencrypt:
  autoconf:```
fl0ppy-d1sk commented 3 years ago

Quickly tested it and it works on my side, here is the procedure.

First create a letsencrypt directory on the host :

$ mkdir letsencrypt

Give RWX rights to group 101 on the folder :

$ chgrp 101 letsencrypt
$ chmod g+rwx letsencrypt

Then your compose needs to be edited a little bit :

services:

  bunker:
    image: bunkerity/bunkerized-nginx
    restart: always
    ports:
      - 80:8080
      - 443:8443
    volumes:
      - ./letsencrypt:/etc/letsencrypt
      - /home/sites:/www:ro
      - autoconf:/etc/nginx
    environment:
      - SERVER_NAME=
      - MULTISITE=yes
      - AUTO_LETS_ENCRYPT=yes
      - REDIRECT_HTTP_TO_HTTPS=yes
      - DISABLE_DEFAULT_SERVER=yes
      - USE_CLIENT_CACHE=yes
      - USE_GZIP=yes
    labels:
      - "bunkerized-nginx.AUTOCONF"
      - "bunkerized-nginx.UI"

  myautoconf:
    image: bunkerity/bunkerized-nginx-autoconf
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - autoconf:/etc/nginx
    depends_on:
      - bunker
      - example.com

  example.com:
    image: php:fpm
    restart: always
    volumes:
      - /home/sites/php-fpm/www.conf:/etc/php-fpm.d/www.conf
      - /home/sites/php-fpm/php-fpm.conf:/etc/php-fpm.conf
      - /home/sites/example.com:/www
    labels:
      - "bunkerized-nginx.SERVER_NAME=example.com"
      - "bunkerized-nginx.REMOTE_PHP=example.com"
      - "bunkerized-nginx.REMOTE_PHP_PATH=/www"

volumes:
  autoconf:

Import things to note :

fl0ppy-d1sk commented 3 years ago

Closing this as it should be resolved.