From 4932ef30360f2a8baf78fb0f8f3efc92b8a06179 Mon Sep 17 00:00:00 2001 From: C-A de Salaberry Date: Fri, 10 Nov 2017 18:36:03 +0100 Subject: [PATCH 001/126] Upd: Boost worker_connections from 1024 to 10240. --- Dockerfile | 3 ++- Dockerfile.alpine | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 149fb90..584040e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,8 @@ RUN apt-get update \ # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ - && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf + && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf # Install Forego ADD https://github.com/jwilder/forego/releases/download/v0.16.1/forego /usr/local/bin/forego diff --git a/Dockerfile.alpine b/Dockerfile.alpine index fce6aae..5294e59 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -9,7 +9,8 @@ RUN apk add --no-cache --virtual .run-deps \ # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ - && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf + && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf # Install Forego ADD https://github.com/jwilder/forego/releases/download/v0.16.1/forego /usr/local/bin/forego From 07f4c66ee952ec5b05426dd253e8b74d2fa9aaf3 Mon Sep 17 00:00:00 2001 From: "Kevin F. Konrad" Date: Fri, 22 Jun 2018 19:48:53 +0200 Subject: [PATCH 002/126] clarify default host usage --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 054b4d1..210ee7d 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,9 @@ To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for $ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy +nginx-proxy will then redirect all requests to a container where `VIRTUAL_HOST` is set to `DEFAULT_HOST`, if they don't match any (other) `VIRTUAL_HOST`. Using the example above requests without matching `VIRTUAL_HOST` will be redirected to a plain nginx instance after running the following command: + + $ docker run -d -e VIRTUAL_HOST=foo.bar.com nginx ### Separate Containers From e014065d9ecb96da5b3557d65ec782e2049d4c4b Mon Sep 17 00:00:00 2001 From: kylegoetz Date: Wed, 24 Oct 2018 09:50:28 -0500 Subject: [PATCH 003/126] Update README.md - sample yml needed expose option Example docker-compose.yml does not work without defining an exposed port for whoami service. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5c83548..6f7fc8d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ services: whoami: image: jwilder/whoami + expose: + - "8000" environment: - VIRTUAL_HOST=whoami.local ``` From 330d2cdc0e73f23884f152dfa200f3c336ac5836 Mon Sep 17 00:00:00 2001 From: Sergey Besedin Date: Wed, 24 Oct 2018 19:10:24 +0300 Subject: [PATCH 004/126] Set proper X-Forwarded-Ssl for SSL-terminated setups --- nginx.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index d861050..7a65c72 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -51,8 +51,8 @@ server_names_hash_bucket_size 128; ssl_dhparam /etc/nginx/dhparam/dhparam.pem; {{ end }} -# Set appropriate X-Forwarded-Ssl header -map $scheme $proxy_x_forwarded_ssl { +# Set appropriate X-Forwarded-Ssl header based on $proxy_x_forwarded_proto +map $proxy_x_forwarded_proto $proxy_x_forwarded_ssl { default off; https on; } From 45690ee0444e72f9810bb0300f4215c706fb83b7 Mon Sep 17 00:00:00 2001 From: Marcel Sinn Date: Thu, 19 Sep 2019 07:55:43 +0200 Subject: [PATCH 005/126] Will fix spelling Just read the documentation and found this spelling issue. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index daa5875..611cd9c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ allow 172.16.0.0/12; deny all; ``` -When internal-only access is enabled, external clients with be denied with an `HTTP 403 Forbidden` +When internal-only access is enabled, external clients will be denied with an `HTTP 403 Forbidden` > If there is a load-balancer / reverse proxy in front of `nginx-proxy` that hides the client IP (example: AWS Application/Elastic Load Balancer), you will need to use the nginx `realip` module (already installed) to extract the client's IP from the HTTP request headers. Please see the [nginx realip module configuration](http://nginx.org/en/docs/http/ngx_http_realip_module.html) for more details. This configuration can be added to a new config file and mounted in `/etc/nginx/conf.d/`. From 944163d70d5f1df6f999d3c1fe952fd46bba0c84 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 20 Mar 2020 22:28:15 +0100 Subject: [PATCH 006/126] Bring ACME no redirection inline with companion Add the following to the Let's Encrypt ACME challenge "no redirection to HTTPS" https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion/pull/570 https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion/pull/335 --- nginx.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index 18f943a..2c3f36c 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -251,8 +251,9 @@ server { access_log /var/log/nginx/access.log vhost; # Do not HTTPS redirect Let'sEncrypt ACME challenge - location /.well-known/acme-challenge/ { + location ^~ /.well-known/acme-challenge/ { auth_basic off; + auth_request off; allow all; root /usr/share/nginx/html; try_files $uri =404; From 5c252001a50cb8225426cc91fbf7d4ca828a8499 Mon Sep 17 00:00:00 2001 From: Esteban Cerutti Date: Sat, 3 Oct 2020 21:08:12 -0300 Subject: [PATCH 007/126] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4c680ad..0b0e05b 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ services: image: jwilder/whoami environment: - VIRTUAL_HOST=whoami.local + - VIRTUAL_PORT=8000 ``` ```shell From ea28f2f32faa9c84b84b64610d43e532d2272c9d Mon Sep 17 00:00:00 2001 From: lemker Date: Thu, 8 Oct 2020 19:05:47 -0700 Subject: [PATCH 008/126] Upgrade Nginx to 1.19.3 --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e4fa49c..c528481 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM nginx:1.17.8 +FROM nginx:1.19.3 LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 847c848..4b5545b 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,4 +1,4 @@ -FROM nginx:1.17.8-alpine +FROM nginx:1.19.3-alpine LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates diff --git a/README.md b/README.md index 4c680ad..39a9b78 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest 0.7.0](https://img.shields.io/badge/latest-0.7.0-green.svg?style=flat) -![nginx 1.17.8](https://img.shields.io/badge/nginx-1.17.8-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') +![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. From c8a6785898e1ac860f5734a1eac6d395158a777f Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 30 Oct 2020 10:19:56 -0600 Subject: [PATCH 009/126] Update version to 0.8.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 39a9b78..0c62a10 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![latest 0.7.0](https://img.shields.io/badge/latest-0.7.0-green.svg?style=flat) +![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) ![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') From aba100ff7b27251aceb20d80d7e6abeff0b42665 Mon Sep 17 00:00:00 2001 From: Thibault Soubiran Date: Wed, 2 Dec 2020 13:18:32 +0100 Subject: [PATCH 010/126] Update docker-entrypoint.sh Default key size is not 2048 anymore but 4096, reference : https://github.com/nginx-proxy/nginx-proxy/blob/master/generate-dhparam.sh#L4 --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b425dfe..b5ed3c6 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -15,7 +15,7 @@ if [[ $DOCKER_HOST = unix://* ]]; then fi # Generate dhparam file if required -# Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 2048 as a default +# Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 4096 as a default # Note2: if $DHPARAM_GENERATION is set to false in environment variable, dh param generator will skip completely /app/generate-dhparam.sh $DHPARAM_BITS $DHPARAM_GENERATION From 8d0ab905360f8671951023336a36b112f43061e5 Mon Sep 17 00:00:00 2001 From: Thibault Soubiran Date: Sun, 6 Dec 2020 19:09:55 +0100 Subject: [PATCH 011/126] Update README for DHParam default size --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c62a10..3709ec5 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ at startup. Since it can take minutes to generate a new `dhparam.pem`, it is do background. Once generation is complete, the `dhparam.pem` is saved on a persistent volume and nginx is reloaded. This generation process only occurs the first time you start `nginx-proxy`. -> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 2048 bits for A+ security. Some +> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some > older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these > clients, you must either provide your own `dhparam.pem`, or tell `nginx-proxy` to generate a 1024-bit > key on startup by passing `-e DHPARAM_BITS=1024`. @@ -226,7 +226,7 @@ is reloaded. This generation process only occurs the first time you start `ngin In the separate container setup, no pregenerated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will generate one. If you still want A+ security -in a separate container setup, you'll have to generate a 2048 bits DH key file manually and mount it on the +in a separate container setup, you'll have to generate a 2048 or 4096 bits DH key file manually and mount it on the nginx container, at `/etc/nginx/dhparam/dhparam.pem`. #### Wildcard Certificates @@ -268,7 +268,7 @@ and the [AWS ELB Security Policies](https://docs.aws.amazon.com/elasticloadbalan `AWS-TLS-1-2-2017-01`, `AWS-TLS-1-1-2017-01`, `AWS-2016-08`, `AWS-2015-05`, `AWS-2015-03` and `AWS-2015-02`. Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container generates -a 2048 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing +a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing this, either globally or per virtual-host. The default behavior for the proxy when port 80 and 443 are exposed is as follows: From 2bde43c6e94c9f9cb818636b1c84858537830300 Mon Sep 17 00:00:00 2001 From: Joe Polny Date: Fri, 5 Feb 2021 19:56:56 +0000 Subject: [PATCH 012/126] remove scoped ipv6 resolvers --- docker-entrypoint.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b425dfe..6eeada9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -21,9 +21,16 @@ fi # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] export RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g') + +SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]" + if [ "x$RESOLVERS" = "x" ]; then - echo "Warning: unable to determine DNS resolvers for nginx" >&2 - unset RESOLVERS + echo "Warning: unable to determine DNS resolvers for nginx" >&2 + unset RESOLVERS +elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then + echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2 + echo $RESOLVERS | grep -Eo $SCOPED_IPV6_REGEX | paste -s -d ' ' >&2 + export RESOLVERS=$(echo $RESOLVERS | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n) fi # If the user has run the default command and the socket doesn't exist, fail From 1a0d0d822ef1b07d1100b1af0cac231d94c35880 Mon Sep 17 00:00:00 2001 From: Joe Polny Date: Sat, 6 Feb 2021 18:47:01 +0000 Subject: [PATCH 013/126] update IPv6 section in README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 0c62a10..595b461 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,14 @@ You can activate the IPv6 support for the nginx-proxy container by passing the v $ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy +#### Scoped IPv6 Resolvers + +NginX does not support scoped IPv6 resolvers. In [docker-entrypoint.sh](./docker-entrypoint.sh) the resolvers are parsed from resolv.conf, but any scoped IPv6 addreses will be removed. + +#### IPv6 NAT + +By default, docker uses IPv6-to-IPv4 NAT. This means all client connections from IPv6 addresses will show docker's internal IPv4 host address. To see true IPv6 client IP addresses, you must [enable IPv6](https://docs.docker.com/config/daemon/ipv6/) and use [ipv6nat](https://github.com/robbertkl/docker-ipv6nat). You must also disable the userland proxy by adding `"userland-proxy": false` to `/etc/docker/daemon.json` and restarting the daemon. + ### Multiple Ports If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected. From 886dd04b62a300c70b77e4b4519868f5f88addb7 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Fri, 10 Jul 2020 14:26:03 +0200 Subject: [PATCH 014/126] Enable multi-architecture docker image builds Previously, the Dockerfile downloaded 'docker-gen' and 'forego' binaries during build time. This caused a problem as it hard-coded the amd64 architecture for the images. This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to build the `forego` and `docker-gen` executables from scratch instead of downloading binaries directly. This is achieved using multi-stage builds [1]. Two seperate stages first build the binaries, and are then copied over to the final stage. The advantage of this change is two-fold: First, it enables building this image on architectures other than amd64. Secondly it adds trust by not adding external binaries to the docker image. This modified version passes the test both a linux desktop (amd64) as well as a raspberry pi (armv7) with some caveats: - On armv7, a modified version of the `jwilder/docker-gen` image is required. See a seperate PR at [2]. - The 'test_dhparam_is_generated_if_missing' test fails. This also doesn't currently pass on master. [1] https://docs.docker.com/develop/develop-images/multistage-build/ [2] https://github.com/jwilder/docker-gen/pull/327 --- Dockerfile | 63 +++++++++++++++++++++++++++++++++++++++------- Dockerfile.alpine | 64 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 109 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index c528481..c3e9b41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,50 @@ -FROM nginx:1.19.3 +# setup build arguments for version of dependencies to use +ARG NGINX_VERSION=1.19.3 +ARG GO_VERSION=1.14 + +ARG DOCKER_GEN_VERSION=0.7.4 +ARG FOREGO_VERSION=0.16.1 + +# Use a specific version of golang to build both binaries +FROM golang:$GO_VERSION as gobuilder + +# Build docker-gen from scratch +FROM gobuilder as dockergen + +# Download the sources for the given version +ARG DOCKER_GEN_VERSION +ADD https://github.com/jwilder/docker-gen/archive/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz + +# Move the sources into the right directory +RUN tar -xzf sources.tar.gz && \ + mkdir -p /go/src/github.com/jwilder/ && \ + mv docker-gen-* /go/src/github.com/jwilder/docker-gen + +# Install the dependencies and make the docker-gen executable +WORKDIR /go/src/github.com/jwilder/docker-gen +RUN go get -v ./... && \ + CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen + +# Build forego from scratch +# Because this relies on golang workspaces, we need to use go < 1.8. +FROM gobuilder as forego + +# Download the sources for the given version +ARG FOREGO_VERSION +ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz + +# Move the sources into the right directory +RUN tar -xzf sources.tar.gz && \ + mkdir -p /go/src/github.com/ddollar/ && \ + mv forego-* /go/src/github.com/ddollar/forego + +# Install the dependencies and make the forego executable +WORKDIR /go/src/github.com/ddollar/forego/ +RUN go get -v ./... && \ + CGO_ENABLED=0 GOOS=linux go build -o forego . + +# Build the final image +FROM nginx:$NGINX_VERSION LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates @@ -14,15 +60,14 @@ RUN apt-get update \ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf -# Install Forego -ADD https://github.com/jwilder/forego/releases/download/v0.16.1/forego /usr/local/bin/forego -RUN chmod u+x /usr/local/bin/forego +# Install Forego + docker-gen +COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego +COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen -ENV DOCKER_GEN_VERSION 0.7.4 - -RUN wget https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ - && tar -C /usr/local/bin -xvzf docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ - && rm /docker-gen-linux-amd64-$DOCKER_GEN_VERSION.tar.gz +# Add DOCKER_GEN_VERSION environment variable +# Because some external projects rely on it +ARG DOCKER_GEN_VERSION +ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} COPY network_internal.conf /etc/nginx/ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 4b5545b..af4e9a0 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,4 +1,51 @@ -FROM nginx:1.19.3-alpine +# setup build arguments for version of dependencies to use +ARG NGINX_VERSION=1.19.3-alpine +ARG GO_VERSION=1.14-alpine + +ARG DOCKER_GEN_VERSION=0.7.4 +ARG FOREGO_VERSION=0.16.1 + +# Use a specific version of golang to build both binaries +FROM golang:$GO_VERSION as gobuilder +RUN apk add --no-cache git + +# Build docker-gen from scratch +FROM gobuilder as dockergen + +# Download the sources for the given version +ARG DOCKER_GEN_VERSION +ADD https://github.com/jwilder/docker-gen/archive/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz + +# Move the sources into the right directory +RUN tar -xzf sources.tar.gz && \ + mkdir -p /go/src/github.com/jwilder/ && \ + mv docker-gen-* /go/src/github.com/jwilder/docker-gen + +# Install the dependencies and make the docker-gen executable +WORKDIR /go/src/github.com/jwilder/docker-gen +RUN go get -v ./... && \ + CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen + +# Build forego from scratch +# Because this relies on golang workspaces, we need to use go < 1.8. +FROM gobuilder as forego + +# Download the sources for the given version +ARG FOREGO_VERSION +ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz + +# Move the sources into the right directory +RUN tar -xzf sources.tar.gz && \ + mkdir -p /go/src/github.com/ddollar/ && \ + mv forego-* /go/src/github.com/ddollar/forego + +# Install the dependencies and make the forego executable +WORKDIR /go/src/github.com/ddollar/forego/ +RUN go get -v ./... && \ + CGO_ENABLED=0 GOOS=linux go build -o forego . + +# Build the final image +FROM nginx:$NGINX_VERSION LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates @@ -11,15 +58,14 @@ RUN apk add --no-cache --virtual .run-deps \ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf -# Install Forego -ADD https://github.com/jwilder/forego/releases/download/v0.16.1/forego /usr/local/bin/forego -RUN chmod u+x /usr/local/bin/forego +# Install Forego + docker-gen +COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego +COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen -ENV DOCKER_GEN_VERSION 0.7.4 - -RUN wget --quiet https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ - && tar -C /usr/local/bin -xvzf docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ - && rm /docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz +# Add DOCKER_GEN_VERSION environment variable +# Because some external projects rely on it +ARG DOCKER_GEN_VERSION +ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} COPY network_internal.conf /etc/nginx/ From 3a8b49f153ea71a0c01ac6532706205219273723 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 1 Apr 2021 12:14:32 +0200 Subject: [PATCH 015/126] ci: build and push to DockerHub w/ GitHub Actions --- .github/workflows/dockerhub.yml | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/dockerhub.yml diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml new file mode 100644 index 0000000..8191c26 --- /dev/null +++ b/.github/workflows/dockerhub.yml @@ -0,0 +1,87 @@ +name: DockerHub + +on: + workflow_dispatch: + push: + branches: + - master + tags: + - '*.*.*' + paths-ignore: + - 'test/*' + - '.gitignore' + - '.travis.yml' + - 'docker-compose-separate-containers.yml' + - 'docker-compose.yml' + - 'LICENSE' + - 'Makefile' + - '*.md' + +jobs: + multiarch-build: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Get Docker tags for Debian based image + id: docker_meta_debian + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: nginxproxy/nginx-proxy + tag-semver: | + {{version}} + {{major}}.{{minor}} + + - name: Get Docker tags for Alpine based image + id: docker_meta_alpine + uses: crazy-max/ghaction-docker-meta@v1 + with: + images: nginxproxy/nginx-proxy + tag-semver: | + {{version}}-alpine + {{major}}.{{minor}}-alpine + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push the Debian based image + id: docker_build_debian + uses: docker/build-push-action@v2 + with: + file: Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ github.ref != 'refs/heads/master' && steps.docker_meta_debian.outputs.tags || '' }} + ${{ github.ref == 'refs/heads/master' && 'nginxproxy/nginx-proxy:latest' || '' }} + labels: ${{ steps.docker_meta.outputs.labels }} + + - name: Build and push the Alpine based image + id: docker_build_alpine + uses: docker/build-push-action@v2 + with: + file: Dockerfile.alpine + platforms: linux/amd64 + push: true + tags: | + ${{ github.ref != 'refs/heads/master' && steps.docker_meta_alpine.outputs.tags || '' }} + ${{ github.ref == 'refs/heads/master' && 'nginxproxy/nginx-proxy:alpine' || '' }} + labels: ${{ steps.docker_meta.outputs.labels }} + + - name: Images digests + run: | + echo ${{ steps.docker_build_debian.outputs.digest }} + echo ${{ steps.docker_build_alpine.outputs.digest }} From 6b8cd894dab7321853c7b25ce6fafca87f5b3d0b Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Thu, 1 Apr 2021 13:54:37 +0200 Subject: [PATCH 016/126] Hardcode go 1.15.10 for use in Docker Images This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to use 'go.15.10' when building the dependencies. This change was implemented after feedback from @buchdag to be able to use dependabot. --- Dockerfile | 3 +-- Dockerfile.alpine | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3e9b41..bf7d4cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,11 @@ # setup build arguments for version of dependencies to use ARG NGINX_VERSION=1.19.3 -ARG GO_VERSION=1.14 ARG DOCKER_GEN_VERSION=0.7.4 ARG FOREGO_VERSION=0.16.1 # Use a specific version of golang to build both binaries -FROM golang:$GO_VERSION as gobuilder +FROM golang:1.15.10 as gobuilder # Build docker-gen from scratch FROM gobuilder as dockergen diff --git a/Dockerfile.alpine b/Dockerfile.alpine index af4e9a0..feb9651 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,12 +1,11 @@ # setup build arguments for version of dependencies to use ARG NGINX_VERSION=1.19.3-alpine -ARG GO_VERSION=1.14-alpine ARG DOCKER_GEN_VERSION=0.7.4 ARG FOREGO_VERSION=0.16.1 # Use a specific version of golang to build both binaries -FROM golang:$GO_VERSION as gobuilder +FROM golang:1.15.10-alpine as gobuilder RUN apk add --no-cache git # Build docker-gen from scratch From 83ca0511d17b4d4202ab72abfed50dbaddef4fde Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Thu, 1 Apr 2021 15:54:26 +0200 Subject: [PATCH 017/126] Hardcode nginx 1.19.3 for use in Docker Images This commit updates both 'Dockerfile' and 'Dockerfile.alpine' to use 'nginx 1.19.3'. This change was implemented after feedback from @buchdag to be able to use dependabot. --- Dockerfile | 4 +--- Dockerfile.alpine | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index bf7d4cb..8dfc682 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,4 @@ # setup build arguments for version of dependencies to use -ARG NGINX_VERSION=1.19.3 - ARG DOCKER_GEN_VERSION=0.7.4 ARG FOREGO_VERSION=0.16.1 @@ -43,7 +41,7 @@ RUN go get -v ./... && \ CGO_ENABLED=0 GOOS=linux go build -o forego . # Build the final image -FROM nginx:$NGINX_VERSION +FROM nginx:1.19.3 LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index feb9651..55f3912 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,6 +1,4 @@ # setup build arguments for version of dependencies to use -ARG NGINX_VERSION=1.19.3-alpine - ARG DOCKER_GEN_VERSION=0.7.4 ARG FOREGO_VERSION=0.16.1 @@ -44,7 +42,7 @@ RUN go get -v ./... && \ CGO_ENABLED=0 GOOS=linux go build -o forego . # Build the final image -FROM nginx:$NGINX_VERSION +FROM nginx:1.19.3-alpine LABEL maintainer="Jason Wilder mail@jasonwilder.com" # Install wget and install/updates certificates From ad7c02570bc69ffe184c7d4e431daf6765f8ef84 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 1 Apr 2021 16:06:09 +0200 Subject: [PATCH 018/126] chore: use nginxproxy's DockerHub registry Transitioning away from jwilder/nginx-proxy Please see #1304 for more details --- Makefile | 4 +- README.md | 48 +++++++++---------- docker-compose.yml | 2 +- docker-entrypoint.sh | 2 +- test/README.md | 8 ++-- test/conftest.py | 24 +++++----- .../test_deleted_cert/docker-compose.yml | 2 +- .../test_unreachable_network/README.md | 2 +- .../docker-compose.yml | 2 +- test/test_DOCKER_HOST_unix_socket.yml | 2 +- test/test_composev2.yml | 2 +- test/test_custom/test_defaults-location.yml | 2 +- test/test_custom/test_defaults.yml | 2 +- test/test_custom/test_location-per-vhost.yml | 2 +- test/test_custom/test_per-vhost.yml | 2 +- test/test_custom/test_proxy-wide.yml | 2 +- test/test_dockergen/test_dockergen_v2.py | 6 +-- test/test_dockergen/test_dockergen_v3.py | 6 +-- test/test_events.yml | 2 +- test/test_headers/test_http.yml | 2 +- test/test_headers/test_https.yml | 2 +- test/test_ipv6.yml | 2 +- test/test_multiple-hosts.yml | 2 +- test/test_multiple-networks.yml | 2 +- .../test_multiple-ports/test_VIRTUAL_PORT.yml | 2 +- test/test_multiple-ports/test_default-80.yml | 2 +- .../test_single-port-not-80.yml | 2 +- test/test_nominal.yml | 2 +- test/test_ssl/test_dhparam.yml | 2 +- test/test_ssl/test_dhparam_generation.yml | 2 +- test/test_ssl/test_hsts.py | 4 +- test/test_ssl/test_hsts.yml | 2 +- test/test_ssl/test_nohttp.yml | 2 +- test/test_ssl/test_nohttps.yml | 2 +- test/test_ssl/test_noredirect.yml | 2 +- test/test_ssl/test_wildcard.yml | 2 +- .../docker-compose.yml | 2 +- test/test_wildcard_host.yml | 2 +- 38 files changed, 79 insertions(+), 83 deletions(-) diff --git a/Makefile b/Makefile index 5f965f7..d7db2b8 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ update-dependencies: test/requirements/build.sh test-debian: update-dependencies - docker build -t jwilder/nginx-proxy:test . + docker build -t nginxproxy/nginx-proxy:test . test/pytest.sh test-alpine: update-dependencies - docker build -f Dockerfile.alpine -t jwilder/nginx-proxy:test . + docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . test/pytest.sh test: test-debian test-alpine diff --git a/README.md b/README.md index 0c62a10..a390a5c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) -![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/jwilder/nginx-proxy 'DockerHub') +![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. @@ -10,7 +10,7 @@ See [Automated Nginx Reverse Proxy for Docker][2] for why you might want to use To run it: - $ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com` @@ -24,17 +24,17 @@ Provided your DNS is setup to forward foo.bar.com to the host running nginx-prox The nginx-proxy images are available in two flavors. -#### jwilder/nginx-proxy:latest +#### nginxproxy/nginx-proxy:latest -This image uses the debian:jessie based nginx image. +This image uses the debian:buster based nginx image. - $ docker pull jwilder/nginx-proxy:latest + $ docker pull nginxproxy/nginx-proxy:latest -#### jwilder/nginx-proxy:alpine +#### nginxproxy/nginx-proxy:alpine This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using letsencrypt" for more info). - $ docker pull jwilder/nginx-proxy:alpine + $ docker pull nginxproxy/nginx-proxy:alpine ### Docker Compose @@ -43,7 +43,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy + image: nginxproxy/nginx-proxy ports: - "80:80" volumes: @@ -65,7 +65,7 @@ I'm 5b129ab83266 You can activate the IPv6 support for the nginx-proxy container by passing the value `true` to the `ENABLE_IPV6` environment variable: - $ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy ### Multiple Ports @@ -90,7 +90,7 @@ If you want your `nginx-proxy` container to be attached to a different network, ```console $ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \ - --name my-nginx-proxy --net my-network jwilder/nginx-proxy + --name my-nginx-proxy --net my-network nginxproxy/nginx-proxy $ docker network connect my-other-network my-nginx-proxy ``` @@ -142,7 +142,7 @@ If you use fastcgi,you can set `VIRTUAL_ROOT=xxx` for your root directory To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example - $ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy ### Separate Containers @@ -160,7 +160,7 @@ $ curl -H "Host: whoami.local" localhost I'm 5b129ab83266 ``` -To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/jwilder/nginx-proxy/blob/master/nginx.tmpl) on your host system. +To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/nginx-proxy/nginx-proxy/blob/master/nginx.tmpl) on your host system. First start nginx with a volume: @@ -181,7 +181,7 @@ Finally, start your containers with `VIRTUAL_HOST` environment variables. $ docker run -e VIRTUAL_HOST=foo.bar.com ... ### SSL Support using letsencrypt -[letsencrypt-nginx-proxy-companion](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion) is a lightweight companion container for the nginx-proxy. It allows the creation/renewal of Let's Encrypt certificates automatically. +[letsencrypt-nginx-proxy-companion](https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion) is a lightweight companion container for the nginx-proxy. It allows the creation/renewal of Let's Encrypt certificates automatically. Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` @@ -194,7 +194,7 @@ certificates or optionally specifying a cert name (for SNI) as an environment va To enable SSL: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy The contents of `/path/to/certs` should contain the certificates and private keys for any virtual hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and @@ -309,7 +309,7 @@ $ docker run -d -p 80:80 -p 443:443 \ -v /path/to/htpasswd:/etc/nginx/htpasswd \ -v /path/to/certs:/etc/nginx/certs \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ - jwilder/nginx-proxy + nginxproxy/nginx-proxy ``` You'll need apache2-utils on the machine where you plan to create the htpasswd file. Follow these [instructions](http://httpd.apache.org/docs/2.2/programs/htpasswd.html) @@ -351,7 +351,7 @@ To add settings on a proxy-wide basis, add your configuration file under `/etc/n This can be done in a derived image by creating the file in a `RUN` command or by `COPY`ing the file into `conf.d`: ```Dockerfile -FROM jwilder/nginx-proxy +FROM nginxproxy/nginx-proxy RUN { \ echo 'server_tokens off;'; \ echo 'client_max_body_size 100m;'; \ @@ -360,7 +360,7 @@ RUN { \ Or it can be done by mounting in your custom configuration in your `docker run` command: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy #### Per-VIRTUAL_HOST @@ -370,7 +370,7 @@ In order to allow virtual hosts to be dynamically configured as backends are add For example, if you have a virtual host named `app.example.com`, you could provide a custom configuration for that host as follows: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy $ { echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/app.example.com If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink: @@ -390,7 +390,7 @@ just like the previous section except with the suffix `_location`. For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy + $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy $ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink: @@ -409,15 +409,15 @@ Before submitting pull requests or issues, please check github to make sure an e #### Running Tests Locally -To run tests, you need to prepare the docker image to test which must be tagged `jwilder/nginx-proxy:test`: +To run tests, you need to prepare the docker image to test which must be tagged `nginxproxy/nginx-proxy:test`: - docker build -t jwilder/nginx-proxy:test . # build the Debian variant image + docker build -t nginxproxy/nginx-proxy:test . # build the Debian variant image and call the [test/pytest.sh](test/pytest.sh) script. Then build the Alpine variant of the image: - docker build -f Dockerfile.alpine -t jwilder/nginx-proxy:test . # build the Alpline variant image + docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . # build the Alpline variant image and call the [test/pytest.sh](test/pytest.sh) script again. @@ -428,7 +428,3 @@ If your system has the `make` command, you can automate those tasks by calling: You can learn more about how the test suite works and how to write new tests in the [test/README.md](test/README.md) file. - -### Need help? - -If you have questions on how to use the image, please ask them on the [Q&A Group](https://groups.google.com/forum/#!forum/nginx-proxy) diff --git a/docker-compose.yml b/docker-compose.yml index b76f0c0..138f396 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy + image: nginxproxy/nginx-proxy container_name: nginx-proxy ports: - "80:80" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b425dfe..988a357 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -7,7 +7,7 @@ if [[ $DOCKER_HOST = unix://* ]]; then if ! [ -S $socket_file ]; then cat >&2 <<-EOT ERROR: you need to share your Docker host socket with a volume at $socket_file - Typically you should run your jwilder/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` + Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` See the documentation at http://git.io/vZaGJ EOT socketMissing=1 diff --git a/test/README.md b/test/README.md index 9d7a57c..c62960a 100644 --- a/test/README.md +++ b/test/README.md @@ -15,13 +15,13 @@ If you can't install those requirements on your computer, you can alternatively Prepare the nginx-proxy test image ---------------------------------- - docker build -t jwilder/nginx-proxy:test .. + docker build -t nginxproxy/nginx-proxy:test .. or if you want to test the alpine flavor: - docker build -t jwilder/nginx-proxy:test -f Dockerfile.alpine .. + docker build -t nginxproxy/nginx-proxy:test -f Dockerfile.alpine .. -make sure to tag that test image exactly `jwilder/nginx-proxy:test` or the test suite won't work. +make sure to tag that test image exactly `nginxproxy/nginx-proxy:test` or the test suite won't work. Run the test suite @@ -65,7 +65,7 @@ In your tests, you can use the `docker_compose` variable to query and command th Also this fixture alters the way the python interpreter resolves domain names to IP addresses in the following ways: -Any domain name containing the substring `nginx-proxy` will resolve to the IP address of the container that was created from the `jwilder/nginx-proxy:test` image. So all the following domain names will resolve to the nginx-proxy container in tests: +Any domain name containing the substring `nginx-proxy` will resolve to the IP address of the container that was created from the `nginxproxy/nginx-proxy:test` image. So all the following domain names will resolve to the nginx-proxy container in tests: - `nginx-proxy` - `nginx-proxy.com` - `www.nginx-proxy.com` diff --git a/test/conftest.py b/test/conftest.py index 6bd172a..a9bead2 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -68,11 +68,11 @@ class requests_for_docker(object): """ Return the nginx config file """ - nginx_proxy_containers = docker_client.containers.list(filters={"ancestor": "jwilder/nginx-proxy:test"}) + nginx_proxy_containers = docker_client.containers.list(filters={"ancestor": "nginxproxy/nginx-proxy:test"}) if len(nginx_proxy_containers) > 1: - pytest.fail("Too many running jwilder/nginx-proxy:test containers", pytrace=False) + pytest.fail("Too many running nginxproxy/nginx-proxy:test containers", pytrace=False) elif len(nginx_proxy_containers) == 0: - pytest.fail("No running jwilder/nginx-proxy:test container", pytrace=False) + pytest.fail("No running nginxproxy/nginx-proxy:test container", pytrace=False) return get_nginx_conf_from_container(nginx_proxy_containers[0]) def get(self, *args, **kwargs): @@ -162,16 +162,16 @@ def container_ipv6(container): def nginx_proxy_dns_resolver(domain_name): """ if "nginx-proxy" if found in host, return the ip address of the docker container - issued from the docker image jwilder/nginx-proxy:test. + issued from the docker image nginxproxy/nginx-proxy:test. :return: IP or None """ log = logging.getLogger('DNS') log.debug("nginx_proxy_dns_resolver(%r)" % domain_name) if 'nginx-proxy' in domain_name: - nginxproxy_containers = docker_client.containers.list(filters={"status": "running", "ancestor": "jwilder/nginx-proxy:test"}) + nginxproxy_containers = docker_client.containers.list(filters={"status": "running", "ancestor": "nginxproxy/nginx-proxy:test"}) if len(nginxproxy_containers) == 0: - log.warn("no container found from image jwilder/nginx-proxy:test while resolving %r", domain_name) + log.warn("no container found from image nginxproxy/nginx-proxy:test while resolving %r", domain_name) return nginxproxy_container = nginxproxy_containers[0] ip = container_ip(nginxproxy_container) @@ -211,7 +211,7 @@ def monkey_patch_urllib_dns_resolver(): """ Alter the behavior of the urllib DNS resolver so that any domain name containing substring 'nginx-proxy' will resolve to the IP address - of the container created from image 'jwilder/nginx-proxy:test'. + of the container created from image 'nginxproxy/nginx-proxy:test'. """ prv_getaddrinfo = socket.getaddrinfo dns_cache = {} @@ -278,10 +278,10 @@ def docker_compose_down(compose_file='docker-compose.yml'): def wait_for_nginxproxy_to_be_ready(): """ - If one (and only one) container started from image jwilder/nginx-proxy:test is found, + If one (and only one) container started from image nginxproxy/nginx-proxy:test is found, wait for its log to contain substring "Watching docker events" """ - containers = docker_client.containers.list(filters={"ancestor": "jwilder/nginx-proxy:test"}) + containers = docker_client.containers.list(filters={"ancestor": "nginxproxy/nginx-proxy:test"}) if len(containers) != 1: return container = containers[0] @@ -439,7 +439,7 @@ def nginxproxy(): def pytest_runtest_logreport(report): if report.failed: if isinstance(report.longrepr, ReprExceptionInfo): - test_containers = docker_client.containers.list(all=True, filters={"ancestor": "jwilder/nginx-proxy:test"}) + test_containers = docker_client.containers.list(all=True, filters={"ancestor": "nginxproxy/nginx-proxy:test"}) for container in test_containers: report.longrepr.addsection('nginx-proxy logs', container.logs()) report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container)) @@ -465,9 +465,9 @@ def pytest_runtest_setup(item): ############################################################################### try: - docker_client.images.get('jwilder/nginx-proxy:test') + docker_client.images.get('nginxproxy/nginx-proxy:test') except docker.errors.ImageNotFound: - pytest.exit("The docker image 'jwilder/nginx-proxy:test' is missing") + pytest.exit("The docker image 'nginxproxy/nginx-proxy:test' is missing") if docker.__version__ != "2.1.0": pytest.exit("This test suite is meant to work with the python docker module v2.1.0") diff --git a/test/stress_tests/test_deleted_cert/docker-compose.yml b/test/stress_tests/test_deleted_cert/docker-compose.yml index 06a61b9..33c92a7 100644 --- a/test/stress_tests/test_deleted_cert/docker-compose.yml +++ b/test/stress_tests/test_deleted_cert/docker-compose.yml @@ -8,7 +8,7 @@ web: reverseproxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test container_name: reverseproxy environment: DEBUG: "true" diff --git a/test/stress_tests/test_unreachable_network/README.md b/test/stress_tests/test_unreachable_network/README.md index aa09c4d..550b289 100644 --- a/test/stress_tests/test_unreachable_network/README.md +++ b/test/stress_tests/test_unreachable_network/README.md @@ -6,7 +6,7 @@ Furthermore, if the nginx-proxy in such state is restarted, the nginx process wi In the generated nginx config file, we can notice the presence of an empty `upstream {}` block. -This can be fixed by merging [PR-585](https://github.com/jwilder/nginx-proxy/pull/585). +This can be fixed by merging [PR-585](https://github.com/nginx-proxy/nginx-proxy/pull/585). ## How to reproduce diff --git a/test/stress_tests/test_unreachable_network/docker-compose.yml b/test/stress_tests/test_unreachable_network/docker-compose.yml index 0ca4f99..9666d29 100644 --- a/test/stress_tests/test_unreachable_network/docker-compose.yml +++ b/test/stress_tests/test_unreachable_network/docker-compose.yml @@ -9,7 +9,7 @@ services: container_name: reverseproxy networks: - netA - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro diff --git a/test/test_DOCKER_HOST_unix_socket.yml b/test/test_DOCKER_HOST_unix_socket.yml index dff75a8..d1aba4b 100644 --- a/test/test_DOCKER_HOST_unix_socket.yml +++ b/test/test_DOCKER_HOST_unix_socket.yml @@ -16,7 +16,7 @@ web2: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/f00.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_composev2.yml b/test/test_composev2.yml index ef4df8d..283e070 100644 --- a/test/test_composev2.yml +++ b/test/test_composev2.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_custom/test_defaults-location.yml b/test/test_custom/test_defaults-location.yml index a5b0c44..3069273 100644 --- a/test/test_custom/test_defaults-location.yml +++ b/test/test_custom/test_defaults-location.yml @@ -1,5 +1,5 @@ nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_custom/test_defaults.yml b/test/test_custom/test_defaults.yml index 2cfddf0..165264c 100644 --- a/test/test_custom/test_defaults.yml +++ b/test/test_custom/test_defaults.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_custom/test_location-per-vhost.yml b/test/test_custom/test_location-per-vhost.yml index 988181c..3622325 100644 --- a/test/test_custom/test_location-per-vhost.yml +++ b/test/test_custom/test_location-per-vhost.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_custom/test_per-vhost.yml b/test/test_custom/test_per-vhost.yml index 61ae02b..256c207 100644 --- a/test/test_custom/test_per-vhost.yml +++ b/test/test_custom/test_per-vhost.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_custom/test_proxy-wide.yml b/test/test_custom/test_proxy-wide.yml index 602f344..1715b8b 100644 --- a/test/test_custom/test_proxy-wide.yml +++ b/test/test_custom/test_proxy-wide.yml @@ -1,7 +1,7 @@ version: '2' services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_dockergen/test_dockergen_v2.py b/test/test_dockergen/test_dockergen_v2.py index c797d0c..af02649 100644 --- a/test/test_dockergen/test_dockergen_v2.py +++ b/test/test_dockergen/test_dockergen_v2.py @@ -8,13 +8,13 @@ import pytest def nginx_tmpl(): """ pytest fixture which extracts the the nginx config template from - the jwilder/nginx-proxy:test image + the nginxproxy/nginx-proxy:test image """ script_dir = os.path.dirname(__file__) - logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") + logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test") docker_client = docker.from_env() print(docker_client.containers.run( - image='jwilder/nginx-proxy:test', + image='nginxproxy/nginx-proxy:test', remove=True, volumes=['{current_dir}:{current_dir}'.format(current_dir=script_dir)], entrypoint='sh', diff --git a/test/test_dockergen/test_dockergen_v3.py b/test/test_dockergen/test_dockergen_v3.py index 808949b..453889a 100644 --- a/test/test_dockergen/test_dockergen_v3.py +++ b/test/test_dockergen/test_dockergen_v3.py @@ -31,13 +31,13 @@ pytestmark = pytest.mark.skipif( def nginx_tmpl(): """ pytest fixture which extracts the the nginx config template from - the jwilder/nginx-proxy:test image + the nginxproxy/nginx-proxy:test image """ script_dir = os.path.dirname(__file__) - logging.info("extracting nginx.tmpl from jwilder/nginx-proxy:test") + logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test") docker_client = docker.from_env() print(docker_client.containers.run( - image='jwilder/nginx-proxy:test', + image='nginxproxy/nginx-proxy:test', remove=True, volumes=['{current_dir}:{current_dir}'.format(current_dir=script_dir)], entrypoint='sh', diff --git a/test/test_events.yml b/test/test_events.yml index 87b7c01..dcaaafc 100644 --- a/test/test_events.yml +++ b/test/test_events.yml @@ -1,5 +1,5 @@ nginxproxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_headers/test_http.yml b/test/test_headers/test_http.yml index 8cc2e09..f8069c6 100644 --- a/test/test_headers/test_http.yml +++ b/test/test_headers/test_http.yml @@ -8,7 +8,7 @@ web: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_headers/test_https.yml b/test/test_headers/test_https.yml index 131f61c..406e433 100644 --- a/test/test_headers/test_https.yml +++ b/test/test_headers/test_https.yml @@ -8,7 +8,7 @@ web: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./certs/web.nginx-proxy.tld.crt:/etc/nginx/certs/web.nginx-proxy.tld.crt:ro diff --git a/test/test_ipv6.yml b/test/test_ipv6.yml index a0b504e..8da3347 100644 --- a/test/test_ipv6.yml +++ b/test/test_ipv6.yml @@ -16,7 +16,7 @@ web2: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-hosts.yml b/test/test_multiple-hosts.yml index 70269c8..bdc2804 100644 --- a/test/test_multiple-hosts.yml +++ b/test/test_multiple-hosts.yml @@ -8,7 +8,7 @@ web: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-networks.yml b/test/test_multiple-networks.yml index da3277b..1cc6d30 100644 --- a/test/test_multiple-networks.yml +++ b/test/test_multiple-networks.yml @@ -6,7 +6,7 @@ networks: services: nginx-proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_VIRTUAL_PORT.yml b/test/test_multiple-ports/test_VIRTUAL_PORT.yml index 4eb95ea..3ee2d1a 100644 --- a/test/test_multiple-ports/test_VIRTUAL_PORT.yml +++ b/test/test_multiple-ports/test_VIRTUAL_PORT.yml @@ -9,7 +9,7 @@ web: VIRTUAL_PORT: 90 sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_default-80.yml b/test/test_multiple-ports/test_default-80.yml index f06ccb8..ca61286 100644 --- a/test/test_multiple-ports/test_default-80.yml +++ b/test/test_multiple-ports/test_default-80.yml @@ -8,7 +8,7 @@ web: VIRTUAL_HOST: "web.nginx-proxy.tld" sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_single-port-not-80.yml b/test/test_multiple-ports/test_single-port-not-80.yml index 15f230a..fbb5b6a 100644 --- a/test/test_multiple-ports/test_single-port-not-80.yml +++ b/test/test_multiple-ports/test_single-port-not-80.yml @@ -8,7 +8,7 @@ web: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_nominal.yml b/test/test_nominal.yml index d436499..7c49801 100644 --- a/test/test_nominal.yml +++ b/test/test_nominal.yml @@ -16,7 +16,7 @@ web2: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index 66b1a61..9b29842 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -8,7 +8,7 @@ web5: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test container_name: nginxproxy volumes: - /var/run/docker.sock:/tmp/docker.sock:ro diff --git a/test/test_ssl/test_dhparam_generation.yml b/test/test_ssl/test_dhparam_generation.yml index 35f3067..6df55c1 100644 --- a/test/test_ssl/test_dhparam_generation.yml +++ b/test/test_ssl/test_dhparam_generation.yml @@ -1,5 +1,5 @@ sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test container_name: nginxproxy volumes: - /var/run/docker.sock:/tmp/docker.sock:ro diff --git a/test/test_ssl/test_hsts.py b/test/test_ssl/test_hsts.py index 12bbcc4..16dffd2 100644 --- a/test/test_ssl/test_hsts.py +++ b/test/test_ssl/test_hsts.py @@ -8,7 +8,7 @@ def test_web1_HSTS_default(docker_compose, nginxproxy): assert "max-age=31536000" == r.headers["Strict-Transport-Security"] # Regression test to ensure HSTS is enabled even when the upstream sends an error in response -# Issue #1073 https://github.com/jwilder/nginx-proxy/pull/1073 +# Issue #1073 https://github.com/nginx-proxy/nginx-proxy/pull/1073 def test_web1_HSTS_error(docker_compose, nginxproxy): r = nginxproxy.get("https://web1.nginx-proxy.tld/status/500", allow_redirects=False) assert "Strict-Transport-Security" in r.headers @@ -26,7 +26,7 @@ def test_web3_HSTS_custom(docker_compose, nginxproxy): assert "max-age=86400; includeSubDomains; preload" == r.headers["Strict-Transport-Security"] # Regression test for issue 1080 -# https://github.com/jwilder/nginx-proxy/issues/1080 +# https://github.com/nginx-proxy/nginx-proxy/issues/1080 def test_web4_HSTS_off_noredirect(docker_compose, nginxproxy): r = nginxproxy.get("https://web4.nginx-proxy.tld/port", allow_redirects=False) assert "answer from port 81\n" in r.text diff --git a/test/test_ssl/test_hsts.yml b/test/test_ssl/test_hsts.yml index f6f39a7..779dc07 100644 --- a/test/test_ssl/test_hsts.yml +++ b/test/test_ssl/test_hsts.yml @@ -35,7 +35,7 @@ web4: HTTPS_METHOD: "noredirect" sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_nohttp.yml b/test/test_ssl/test_nohttp.yml index 51d63c2..7a7ea08 100644 --- a/test/test_ssl/test_nohttp.yml +++ b/test/test_ssl/test_nohttp.yml @@ -9,7 +9,7 @@ web2: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_nohttps.yml b/test/test_ssl/test_nohttps.yml index 14140b4..0a6a9a5 100644 --- a/test/test_ssl/test_nohttps.yml +++ b/test/test_ssl/test_nohttps.yml @@ -9,7 +9,7 @@ web: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_noredirect.yml b/test/test_ssl/test_noredirect.yml index 9149a87..9ac7169 100644 --- a/test/test_ssl/test_noredirect.yml +++ b/test/test_ssl/test_noredirect.yml @@ -9,7 +9,7 @@ web3: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_wildcard.yml b/test/test_ssl/test_wildcard.yml index 4c77796..6168084 100644 --- a/test/test_ssl/test_wildcard.yml +++ b/test/test_ssl/test_wildcard.yml @@ -7,7 +7,7 @@ web1: VIRTUAL_HOST: "*.nginx-proxy.tld" sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml b/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml index 20cd1b2..6257aee 100644 --- a/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml +++ b/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml @@ -3,7 +3,7 @@ version: "3" services: proxy: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./certs:/etc/nginx/certs:ro diff --git a/test/test_wildcard_host.yml b/test/test_wildcard_host.yml index 742a8ac..d39dad4 100644 --- a/test/test_wildcard_host.yml +++ b/test/test_wildcard_host.yml @@ -32,7 +32,7 @@ web4: sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From bea149e317224053cb2e1728498c72dfc47d8ef2 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 1 Apr 2021 21:06:33 +0200 Subject: [PATCH 019/126] ci: create dependabot config for Docker ecosystem --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..d99307f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +version: 2 +updates: + + # Maintain dependencies for Docker + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + labels: + - "area/chore" + - "area/dockerfile" From 4a1d5bfc58af35f5e90dcefb47b35a274c903150 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 1 Apr 2021 22:23:37 +0200 Subject: [PATCH 020/126] ci: build and push for arm64 and arm/v7 archs --- .github/workflows/dockerhub.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 8191c26..1bf586a 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -62,7 +62,7 @@ jobs: uses: docker/build-push-action@v2 with: file: Dockerfile - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: | ${{ github.ref != 'refs/heads/master' && steps.docker_meta_debian.outputs.tags || '' }} @@ -74,7 +74,7 @@ jobs: uses: docker/build-push-action@v2 with: file: Dockerfile.alpine - platforms: linux/amd64 + platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: | ${{ github.ref != 'refs/heads/master' && steps.docker_meta_alpine.outputs.tags || '' }} From d120ce9fdebf09a6c7b90ecff7eda0b7d2760ef3 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 2 Apr 2021 00:39:41 +0200 Subject: [PATCH 021/126] ci: push images to jwilder/nginx-proxy --- .github/workflows/dockerhub.yml | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 1bf586a..ddf32d2 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -29,21 +29,28 @@ jobs: - name: Get Docker tags for Debian based image id: docker_meta_debian - uses: crazy-max/ghaction-docker-meta@v1 + uses: crazy-max/ghaction-docker-meta@v2 with: - images: nginxproxy/nginx-proxy - tag-semver: | - {{version}} - {{major}}.{{minor}} + images: | + nginxproxy/nginx-proxy + jwilder/nginx-proxy + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} - name: Get Docker tags for Alpine based image id: docker_meta_alpine - uses: crazy-max/ghaction-docker-meta@v1 + uses: crazy-max/ghaction-docker-meta@v2 with: - images: nginxproxy/nginx-proxy - tag-semver: | - {{version}}-alpine - {{major}}.{{minor}}-alpine + images: | + nginxproxy/nginx-proxy + jwilder/nginx-proxy + tags: | + type=semver,suffix=-alpine,pattern={{version}} + type=semver,suffix=-alpine,pattern={{major}}.{{minor}} + type=raw,value=alpine,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} + flavor: latest=false - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -64,10 +71,8 @@ jobs: file: Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: | - ${{ github.ref != 'refs/heads/master' && steps.docker_meta_debian.outputs.tags || '' }} - ${{ github.ref == 'refs/heads/master' && 'nginxproxy/nginx-proxy:latest' || '' }} - labels: ${{ steps.docker_meta.outputs.labels }} + tags: ${{ steps.docker_meta_debian.outputs.tags }} + labels: ${{ steps.docker_meta_debian.outputs.labels }} - name: Build and push the Alpine based image id: docker_build_alpine @@ -76,10 +81,8 @@ jobs: file: Dockerfile.alpine platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: | - ${{ github.ref != 'refs/heads/master' && steps.docker_meta_alpine.outputs.tags || '' }} - ${{ github.ref == 'refs/heads/master' && 'nginxproxy/nginx-proxy:alpine' || '' }} - labels: ${{ steps.docker_meta.outputs.labels }} + tags: ${{ steps.docker_meta_alpine.outputs.tags }} + labels: ${{ steps.docker_meta_alpine.outputs.labels }} - name: Images digests run: | From c3bb2348715c855ec3e268b5b08eb4dd25ec9413 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 5 Apr 2021 13:13:20 +0200 Subject: [PATCH 022/126] chore: rename default branch master -> main --- .github/workflows/dockerhub.yml | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index ddf32d2..624d30d 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: push: branches: - - master + - main tags: - '*.*.*' paths-ignore: diff --git a/README.md b/README.md index 40f882b..0ca9aed 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) -![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=master)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') +![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=main)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. @@ -166,7 +166,7 @@ $ curl -H "Host: whoami.local" localhost I'm 5b129ab83266 ``` -To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/nginx-proxy/nginx-proxy/blob/master/nginx.tmpl) on your host system. +To run nginx proxy as a separate container you'll need to have [nginx.tmpl](https://github.com/nginx-proxy/nginx-proxy/blob/main/nginx.tmpl) on your host system. First start nginx with a volume: From bdf62b025bcdd44a9bc247dd77deccc2f3dfafe8 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 5 Apr 2021 13:16:40 +0200 Subject: [PATCH 023/126] docs: follow acme-companion name change --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ca9aed..7a295e9 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ This image uses the debian:buster based nginx image. #### nginxproxy/nginx-proxy:alpine -This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using letsencrypt" for more info). +This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using an ACME CA" for more info). $ docker pull nginxproxy/nginx-proxy:alpine @@ -185,9 +185,9 @@ $ docker run --volumes-from nginx \ Finally, start your containers with `VIRTUAL_HOST` environment variables. $ docker run -e VIRTUAL_HOST=foo.bar.com ... -### SSL Support using letsencrypt +### SSL Support using an ACME CA -[letsencrypt-nginx-proxy-companion](https://github.com/nginx-proxy/docker-letsencrypt-nginx-proxy-companion) is a lightweight companion container for the nginx-proxy. It allows the creation/renewal of Let's Encrypt certificates automatically. +[acme-companion](https://github.com/nginx-proxy/acme-companion) is a lightweight companion container for the nginx-proxy. It allows the automated creation/renewal of SSL certificates using the ACME protocol. Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` From 24565440b26f23a149aa60e30d7b9f6d544dcecf Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 5 Apr 2021 13:56:14 +0200 Subject: [PATCH 024/126] docs: update DockerHub shields --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a295e9..813fdda 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) -![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/jwilder/nginx-proxy.svg?branch=main)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/jwilder/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') +![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/nginx/nginx-proxy.svg?branch=main)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. From 9efeb5d8af809ad1479802b9bce532c598116520 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 6 Apr 2021 00:11:53 +0200 Subject: [PATCH 025/126] ci: build the debian and alpine images in parallel --- .github/workflows/dockerhub.yml | 58 +++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 624d30d..9d074f1 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -18,7 +18,7 @@ on: - '*.md' jobs: - multiarch-build: + multiarch-build-debian: runs-on: ubuntu-latest steps: @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - + - name: Get Docker tags for Debian based image id: docker_meta_debian uses: crazy-max/ghaction-docker-meta@v2 @@ -38,7 +38,41 @@ jobs: type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} - + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push the Debian based image + id: docker_build_debian + uses: docker/build-push-action@v2 + with: + file: Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ steps.docker_meta_debian.outputs.tags }} + labels: ${{ steps.docker_meta_debian.outputs.labels }} + + - name: Images digests + run: echo ${{ steps.docker_build_debian.outputs.digest }} + + multiarch-build-alpine: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Get Docker tags for Alpine based image id: docker_meta_alpine uses: crazy-max/ghaction-docker-meta@v2 @@ -54,25 +88,15 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - + - name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push the Debian based image - id: docker_build_debian - uses: docker/build-push-action@v2 - with: - file: Dockerfile - platforms: linux/amd64,linux/arm64,linux/arm/v7 - push: true - tags: ${{ steps.docker_meta_debian.outputs.tags }} - labels: ${{ steps.docker_meta_debian.outputs.labels }} - name: Build and push the Alpine based image id: docker_build_alpine @@ -85,6 +109,4 @@ jobs: labels: ${{ steps.docker_meta_alpine.outputs.labels }} - name: Images digests - run: | - echo ${{ steps.docker_build_debian.outputs.digest }} - echo ${{ steps.docker_build_alpine.outputs.digest }} + run: echo ${{ steps.docker_build_alpine.outputs.digest }} From 6613e272eb41c926605bc0411b7af9f70c2ebeee Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 7 Apr 2021 17:10:37 +0200 Subject: [PATCH 026/126] ci: rebuild and push the latest image on schedule Rebuild and push the last commit of the default branch every monday at 00:00 UTC --- .github/workflows/dockerhub.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 9d074f1..8eaacf7 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -2,6 +2,8 @@ name: DockerHub on: workflow_dispatch: + schedule: + - cron: '0 0 * * 1' push: branches: - main From cfa9cf31d780db068caf751ba958d422b1722be1 Mon Sep 17 00:00:00 2001 From: Tom Wiesing Date: Wed, 21 Apr 2021 21:04:45 +0200 Subject: [PATCH 027/126] Remove Google Forum Link from Issue Template The Google Forum no longer exists. Therefore the link to it in the issue template should be removed. --- .github/ISSUE_TEMPLATE.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index cfaa367..d09ea82 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,9 +1,5 @@ # !!!PLEASE READ!!! -## Questions - -If you have a question, DO NOT SUBMIT a new issue. Please ask the question on the Q&A Group: https://groups.google.com/forum/#!forum/nginx-proxy - ## Bugs or Features If you are logging a bug or feature request, please search the current open issues to see if there is already a bug or feature opened. From f8aa9a16370af8d060ccd380b61d2463dc3a35cf Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 26 Apr 2021 14:55:33 +0200 Subject: [PATCH 028/126] chore: bump docker-gen from 0.7.4 to 0.7.6 --- Dockerfile | 26 ++++++++++++-------------- Dockerfile.alpine | 27 ++++++++++++--------------- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8dfc682..83253c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # setup build arguments for version of dependencies to use -ARG DOCKER_GEN_VERSION=0.7.4 +ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=0.16.1 # Use a specific version of golang to build both binaries @@ -8,19 +8,17 @@ FROM golang:1.15.10 as gobuilder # Build docker-gen from scratch FROM gobuilder as dockergen -# Download the sources for the given version ARG DOCKER_GEN_VERSION -ADD https://github.com/jwilder/docker-gen/archive/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz -# Move the sources into the right directory -RUN tar -xzf sources.tar.gz && \ - mkdir -p /go/src/github.com/jwilder/ && \ - mv docker-gen-* /go/src/github.com/jwilder/docker-gen - -# Install the dependencies and make the docker-gen executable -WORKDIR /go/src/github.com/jwilder/docker-gen -RUN go get -v ./... && \ - CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen +RUN git clone https://github.com/jwilder/docker-gen \ + && cd /go/docker-gen \ + && git -c advice.detachedHead=false checkout $DOCKER_GEN_VERSION \ + && go mod download \ + && CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen \ + && go clean -cache \ + && mv docker-gen /usr/local/bin/ \ + && cd - \ + && rm -rf /go/docker-gen # Build forego from scratch # Because this relies on golang workspaces, we need to use go < 1.8. @@ -42,7 +40,7 @@ RUN go get -v ./... && \ # Build the final image FROM nginx:1.19.3 -LABEL maintainer="Jason Wilder mail@jasonwilder.com" +LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates RUN apt-get update \ @@ -59,7 +57,7 @@ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ # Install Forego + docker-gen COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego -COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen +COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen # Add DOCKER_GEN_VERSION environment variable # Because some external projects rely on it diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 55f3912..5de844c 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,5 +1,5 @@ # setup build arguments for version of dependencies to use -ARG DOCKER_GEN_VERSION=0.7.4 +ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=0.16.1 # Use a specific version of golang to build both binaries @@ -9,22 +9,19 @@ RUN apk add --no-cache git # Build docker-gen from scratch FROM gobuilder as dockergen -# Download the sources for the given version ARG DOCKER_GEN_VERSION -ADD https://github.com/jwilder/docker-gen/archive/${DOCKER_GEN_VERSION}.tar.gz sources.tar.gz -# Move the sources into the right directory -RUN tar -xzf sources.tar.gz && \ - mkdir -p /go/src/github.com/jwilder/ && \ - mv docker-gen-* /go/src/github.com/jwilder/docker-gen - -# Install the dependencies and make the docker-gen executable -WORKDIR /go/src/github.com/jwilder/docker-gen -RUN go get -v ./... && \ - CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen +RUN git clone https://github.com/jwilder/docker-gen \ + && cd /go/docker-gen \ + && git -c advice.detachedHead=false checkout $DOCKER_GEN_VERSION \ + && go mod download \ + && CGO_ENABLED=0 go build -ldflags "-X main.buildVersion=${DOCKER_GEN_VERSION}" ./cmd/docker-gen \ + && go clean -cache \ + && mv docker-gen /usr/local/bin/ \ + && cd - \ + && rm -rf /go/docker-gen # Build forego from scratch -# Because this relies on golang workspaces, we need to use go < 1.8. FROM gobuilder as forego # Download the sources for the given version @@ -43,7 +40,7 @@ RUN go get -v ./... && \ # Build the final image FROM nginx:1.19.3-alpine -LABEL maintainer="Jason Wilder mail@jasonwilder.com" +LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates RUN apk add --no-cache --virtual .run-deps \ @@ -57,7 +54,7 @@ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ # Install Forego + docker-gen COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego -COPY --from=dockergen /go/src/github.com/jwilder/docker-gen/docker-gen /usr/local/bin/docker-gen +COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen # Add DOCKER_GEN_VERSION environment variable # Because some external projects rely on it From 950a28f5eac81a35a23bc6b67b95615fcd046885 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Thu, 18 Mar 2021 22:48:13 +0100 Subject: [PATCH 029/126] chore(ci): :arrow_up: porting python 2.7 code to python 3.9 --- test/conftest.py | 32 ++++++++++--------- .../Dockerfile-nginx-proxy-tester | 2 +- .../test_restart_while_missing_cert.py | 4 +-- test/test_custom/test_location-per-vhost.py | 2 +- test/test_dockergen/test_dockergen_v2.py | 22 +++++++------ test/test_dockergen/test_dockergen_v3.py | 32 +++++++++++-------- test/test_events.py | 2 +- test/test_ssl/test_dhparam.py | 14 ++++---- test/test_ssl/test_dhparam_generation.py | 2 +- .../test_wildcard_cert_nohttps.py | 2 +- 10 files changed, 63 insertions(+), 51 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index a9bead2..0195712 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,4 +1,3 @@ -from __future__ import print_function import contextlib import logging import os @@ -142,7 +141,7 @@ def container_ip(container): return net_info["bridge"]["IPAddress"] # not default bridge network, fallback on first network defined - network_name = net_info.keys()[0] + network_name = list(net_info.keys())[0] return net_info[network_name]["IPAddress"] @@ -155,7 +154,7 @@ def container_ipv6(container): return net_info["bridge"]["GlobalIPv6Address"] # not default bridge network, fallback on first network defined - network_name = net_info.keys()[0] + network_name = list(net_info.keys())[0] return net_info[network_name]["GlobalIPv6Address"] @@ -188,7 +187,7 @@ def docker_container_dns_resolver(domain_name): log = logging.getLogger('DNS') log.debug("docker_container_dns_resolver(%r)" % domain_name) - match = re.search('(^|.+\.)(?P[^.]+)\.container\.docker$', domain_name) + match = re.search(r'(^|.+\.)(?P[^.]+)\.container\.docker$', domain_name) if not match: log.debug("%r does not match" % domain_name) return @@ -253,9 +252,12 @@ def get_nginx_conf_from_container(container): return the nginx /etc/nginx/conf.d/default.conf file content from a container """ import tarfile - from cStringIO import StringIO - strm, stat = container.get_archive('/etc/nginx/conf.d/default.conf') - with tarfile.open(fileobj=StringIO(strm.read())) as tf: + from io import BytesIO + + strm_generator, stat = container.get_archive('/etc/nginx/conf.d/default.conf') + strm_fileobj = BytesIO(b"".join(strm_generator)) + + with tarfile.open(fileobj=strm_fileobj) as tf: conffile = tf.extractfile('default.conf') return conffile.read() @@ -264,7 +266,7 @@ def docker_compose_up(compose_file='docker-compose.yml'): logging.info('docker-compose -f %s up -d' % compose_file) try: subprocess.check_output(shlex.split('docker-compose -f %s up -d' % compose_file), stderr=subprocess.STDOUT) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: pytest.fail("Error while runninng 'docker-compose -f %s up -d':\n%s" % (compose_file, e.output), pytrace=False) @@ -272,7 +274,7 @@ def docker_compose_down(compose_file='docker-compose.yml'): logging.info('docker-compose -f %s down' % compose_file) try: subprocess.check_output(shlex.split('docker-compose -f %s down' % compose_file), stderr=subprocess.STDOUT) - except subprocess.CalledProcessError, e: + except subprocess.CalledProcessError as e: pytest.fail("Error while runninng 'docker-compose -f %s down':\n%s" % (compose_file, e.output), pytrace=False) @@ -286,7 +288,7 @@ def wait_for_nginxproxy_to_be_ready(): return container = containers[0] for line in container.logs(stream=True): - if "Watching docker events" in line: + if b"Watching docker events" in line: logging.debug("nginx-proxy ready") break @@ -337,7 +339,7 @@ def connect_to_network(network): return # figure out our container networks - my_networks = my_container.attrs["NetworkSettings"]["Networks"].keys() + my_networks = list(my_container.attrs["NetworkSettings"]["Networks"].keys()) # make sure our container is connected to the nginx-proxy's network if network not in my_networks: @@ -360,7 +362,7 @@ def disconnect_from_network(network=None): return # figure out our container networks - my_networks_names = my_container.attrs["NetworkSettings"]["Networks"].keys() + my_networks_names = list(my_container.attrs["NetworkSettings"]["Networks"].keys()) # disconnect our container from the given network if network.name in my_networks_names: @@ -378,7 +380,7 @@ def connect_to_all_networks(): return [] else: # find the list of docker networks - networks = filter(lambda network: len(network.containers) > 0 and network.name != 'bridge', docker_client.networks.list()) + networks = [network for network in docker_client.networks.list() if len(network.containers) > 0 and network.name != 'bridge'] return [connect_to_network(network) for network in networks] @@ -388,7 +390,7 @@ def connect_to_all_networks(): # ############################################################################### -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def docker_compose(request): """ pytest fixture providing containers described in a docker compose file. After the tests, remove the created containers @@ -412,7 +414,7 @@ def docker_compose(request): restore_urllib_dns_resolver(original_dns_resolver) -@pytest.yield_fixture() +@pytest.fixture() def nginxproxy(): """ Provides the `nginxproxy` object that can be used in the same way the requests module is: diff --git a/test/requirements/Dockerfile-nginx-proxy-tester b/test/requirements/Dockerfile-nginx-proxy-tester index 27d0538..6c0f060 100644 --- a/test/requirements/Dockerfile-nginx-proxy-tester +++ b/test/requirements/Dockerfile-nginx-proxy-tester @@ -1,4 +1,4 @@ -FROM python:2.7-alpine +FROM python:3.9-alpine # Note: we're using alpine because it has openssl 1.0.2, which we need for testing RUN apk add --update bash openssl curl && rm -rf /var/cache/apk/* diff --git a/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py b/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py index 2b74acd..0ec36c7 100644 --- a/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py +++ b/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py @@ -12,7 +12,7 @@ script_dir = os.path.dirname(__file__) pytestmark = pytest.mark.xfail() # TODO delete this marker once those issues are fixed -@pytest.yield_fixture(scope="module", autouse=True) +@pytest.fixture(scope="module", autouse=True) def certs(): """ pytest fixture that provides cert and key files into the tmp_certs directory @@ -43,7 +43,7 @@ def test_http_web_is_301(docker_compose, nginxproxy): def test_https_web_is_200(docker_compose, nginxproxy): r = nginxproxy.get("https://web.nginx-proxy/port") assert r.status_code == 200 - assert 'answer from port 81\n' in r.text + assert "answer from port 81\n" in r.text @pytest.mark.incremental diff --git a/test/test_custom/test_location-per-vhost.py b/test/test_custom/test_location-per-vhost.py index b99996e..f67b501 100644 --- a/test/test_custom/test_location-per-vhost.py +++ b/test/test_custom/test_location-per-vhost.py @@ -19,4 +19,4 @@ def test_custom_conf_does_not_apply_to_web2(docker_compose, nginxproxy): assert "X-test" not in r.headers def test_custom_block_is_present_in_nginx_generated_conf(docker_compose, nginxproxy): - assert "include /etc/nginx/vhost.d/web1.nginx-proxy.local_location;" in nginxproxy.get_conf() \ No newline at end of file + assert b"include /etc/nginx/vhost.d/web1.nginx-proxy.local_location;" in nginxproxy.get_conf() \ No newline at end of file diff --git a/test/test_dockergen/test_dockergen_v2.py b/test/test_dockergen/test_dockergen_v2.py index af02649..a3f2484 100644 --- a/test/test_dockergen/test_dockergen_v2.py +++ b/test/test_dockergen/test_dockergen_v2.py @@ -4,7 +4,7 @@ import logging import pytest -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def nginx_tmpl(): """ pytest fixture which extracts the the nginx config template from @@ -13,14 +13,18 @@ def nginx_tmpl(): script_dir = os.path.dirname(__file__) logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test") docker_client = docker.from_env() - print(docker_client.containers.run( - image='nginxproxy/nginx-proxy:test', - remove=True, - volumes=['{current_dir}:{current_dir}'.format(current_dir=script_dir)], - entrypoint='sh', - command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format( - current_dir=script_dir), - stderr=True)) + print( + docker_client.containers.run( + image="nginxproxy/nginx-proxy:test", + remove=True, + volumes=["{current_dir}:{current_dir}".format(current_dir=script_dir)], + entrypoint="sh", + command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format( + current_dir=script_dir + ), + stderr=True, + ) + ) yield logging.info("removing nginx.tmpl") os.remove(os.path.join(script_dir, "nginx.tmpl")) diff --git a/test/test_dockergen/test_dockergen_v3.py b/test/test_dockergen/test_dockergen_v3.py index 453889a..1beffeb 100644 --- a/test/test_dockergen/test_dockergen_v3.py +++ b/test/test_dockergen/test_dockergen_v3.py @@ -18,16 +18,18 @@ def versiontuple(v): >>> versiontuple("17.03.0-ce") < (1, 13) False """ - return tuple(map(int, (v.split('-')[0].split(".")))) + return tuple(map(int, (v.split("-")[0].split(".")))) -raw_version = docker.from_env().version()['Version'] +raw_version = docker.from_env().version()["Version"] pytestmark = pytest.mark.skipif( versiontuple(raw_version) < (1, 13), - reason="Docker compose syntax v3 requires docker engine v1.13 or later (got %s)" % raw_version) + reason="Docker compose syntax v3 requires docker engine v1.13 or later (got %s)" + % raw_version, +) -@pytest.yield_fixture(scope="module") +@pytest.fixture(scope="module") def nginx_tmpl(): """ pytest fixture which extracts the the nginx config template from @@ -36,14 +38,18 @@ def nginx_tmpl(): script_dir = os.path.dirname(__file__) logging.info("extracting nginx.tmpl from nginxproxy/nginx-proxy:test") docker_client = docker.from_env() - print(docker_client.containers.run( - image='nginxproxy/nginx-proxy:test', - remove=True, - volumes=['{current_dir}:{current_dir}'.format(current_dir=script_dir)], - entrypoint='sh', - command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format( - current_dir=script_dir), - stderr=True)) + print( + docker_client.containers.run( + image="nginxproxy/nginx-proxy:test", + remove=True, + volumes=["{current_dir}:{current_dir}".format(current_dir=script_dir)], + entrypoint="sh", + command='-xc "cp /app/nginx.tmpl {current_dir} && chmod 777 {current_dir}/nginx.tmpl"'.format( + current_dir=script_dir + ), + stderr=True, + ) + ) yield logging.info("removing nginx.tmpl") os.remove(os.path.join(script_dir, "nginx.tmpl")) @@ -61,6 +67,6 @@ def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy): assert r.text == "I'm %s\n" % whoami_container.id[:12] -if __name__ == '__main__': +if __name__ == "__main__": import doctest doctest.testmod() diff --git a/test/test_events.py b/test/test_events.py index fa97f84..201917f 100644 --- a/test/test_events.py +++ b/test/test_events.py @@ -7,7 +7,7 @@ import pytest from docker.errors import NotFound -@pytest.yield_fixture() +@pytest.fixture() def web1(docker_compose): """ pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81. diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index 40339a1..8899c6a 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -26,7 +26,7 @@ def assert_log_contains(expected_log_line): """ sut_container = docker_client.containers.get("nginxproxy") docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False) - assert expected_log_line in docker_logs + assert bytes(expected_log_line, encoding="utf8") in docker_logs def require_openssl(required_version): @@ -42,7 +42,7 @@ def require_openssl(required_version): """ def versiontuple(v): - clean_v = re.sub("[^\d\.]", "", v) + clean_v = re.sub(r"[^\d\.]", "", v) return tuple(map(int, (clean_v.split(".")))) try: @@ -52,7 +52,7 @@ def require_openssl(required_version): else: if not command_output: raise Exception("Could not get openssl version") - openssl_version = command_output.split()[1] + openssl_version = str(command_output.split()[1]) return pytest.mark.skipif( versiontuple(openssl_version) < versiontuple(required_version), reason="openssl v%s is less than required version %s" % (openssl_version, required_version)) @@ -71,8 +71,8 @@ def test_dhparam_is_not_generated_if_present(docker_compose): assert_log_contains("Custom dhparam.pem file found, generation skipped") # Make sure the dhparam in use is not the default, pre-generated one - default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").split() - current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").split() + default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").output.split() + current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() assert default_checksum[0] != current_checksum[0] @@ -89,5 +89,5 @@ def test_web5_dhparam_is_used(docker_compose): host = "%s:443" % sut_container.attrs["NetworkSettings"]["IPAddress"] r = subprocess.check_output( - "echo '' | openssl s_client -connect %s -cipher 'EDH' | grep 'Server Temp Key'" % host, shell=True) - assert "Server Temp Key: X25519, 253 bits\n" == r + f"echo '' | openssl s_client -connect {host} -cipher 'EDH' | grep 'Server Temp Key'", shell=True) + assert b"Server Temp Key: X25519, 253 bits\n" == r diff --git a/test/test_ssl/test_dhparam_generation.py b/test/test_ssl/test_dhparam_generation.py index 0f5398b..4ba1c53 100644 --- a/test/test_ssl/test_dhparam_generation.py +++ b/test/test_ssl/test_dhparam_generation.py @@ -22,7 +22,7 @@ def assert_log_contains(expected_log_line): """ sut_container = docker_client.containers.get("nginxproxy") docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False) - assert expected_log_line in docker_logs + assert bytes(expected_log_line, encoding="utf8") in docker_logs ############################################################################### diff --git a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py index 2808dee..1946cc0 100644 --- a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py +++ b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py @@ -1,5 +1,5 @@ import pytest -from backports.ssl_match_hostname import CertificateError +from ssl import CertificateError from requests.exceptions import SSLError From eba9ac42610290b93e2ab41dcf367d929bb30140 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Thu, 18 Mar 2021 22:48:49 +0100 Subject: [PATCH 030/126] chore(ci): :arrow_up: update python dependencies to latests release --- test/conftest.py | 4 ++-- test/requirements/python-requirements.txt | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 0195712..0d7a488 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -471,5 +471,5 @@ try: except docker.errors.ImageNotFound: pytest.exit("The docker image 'nginxproxy/nginx-proxy:test' is missing") -if docker.__version__ != "2.1.0": - pytest.exit("This test suite is meant to work with the python docker module v2.1.0") +if docker.__version__ != "4.4.4": + pytest.exit("This test suite is meant to work with the python docker module v4.4.4") diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index ba95455..11f8665 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ -backoff==1.3.2 -docker-compose==1.11.2 -docker==2.1.0 -pytest==3.0.5 -requests==2.11.1 +backoff==1.10.0 +docker-compose==1.28.5 +docker==4.4.4 +pytest==6.2.2 +requests==2.25.1 From 37e85e6e8d8aa413f3d242585c37e98abdbfb018 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 12:12:24 +0100 Subject: [PATCH 031/126] chore(ci): :recycle: convert Python old `%` string to f-strings --- test/conftest.py | 50 +++++++++---------- test/requirements/web/webserver.py | 6 +-- test/test_dockergen/test_dockergen_v2.py | 2 +- test/test_dockergen/test_dockergen_v3.py | 5 +- test/test_ssl/test_dhparam.py | 4 +- test/test_ssl/test_wildcard.py | 8 +-- .../test_wildcard_cert_nohttps.py | 10 ++-- test/test_wildcard_host.py | 6 +-- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 0d7a488..aa398e6 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -132,7 +132,7 @@ def container_ip(container): pytest.skip("This system does not support IPv6") ip = container_ipv6(container) if ip == '': - pytest.skip("Container %s has no IPv6 address" % container.name) + pytest.skip(f"Container {container.name} has no IPv6 address") else: return ip else: @@ -166,15 +166,15 @@ def nginx_proxy_dns_resolver(domain_name): :return: IP or None """ log = logging.getLogger('DNS') - log.debug("nginx_proxy_dns_resolver(%r)" % domain_name) + log.debug(f"nginx_proxy_dns_resolver({domain_name!r})") if 'nginx-proxy' in domain_name: nginxproxy_containers = docker_client.containers.list(filters={"status": "running", "ancestor": "nginxproxy/nginx-proxy:test"}) if len(nginxproxy_containers) == 0: - log.warn("no container found from image nginxproxy/nginx-proxy:test while resolving %r", domain_name) + log.warn(f"no container found from image nginxproxy/nginx-proxy:test while resolving {domain_name!r}") return nginxproxy_container = nginxproxy_containers[0] ip = container_ip(nginxproxy_container) - log.info("resolving domain name %r as IP address %s of nginx-proxy container %s" % (domain_name, ip, nginxproxy_container.name)) + log.info(f"resolving domain name {domain_name!r} as IP address {ip} of nginx-proxy container {nginxproxy_container.name}") return ip def docker_container_dns_resolver(domain_name): @@ -185,24 +185,24 @@ def docker_container_dns_resolver(domain_name): :return: IP or None """ log = logging.getLogger('DNS') - log.debug("docker_container_dns_resolver(%r)" % domain_name) + log.debug(f"docker_container_dns_resolver({domain_name!r})") match = re.search(r'(^|.+\.)(?P[^.]+)\.container\.docker$', domain_name) if not match: - log.debug("%r does not match" % domain_name) + log.debug(f"{domain_name!r} does not match") return container_name = match.group('container') - log.debug("looking for container %r" % container_name) + log.debug(f"looking for container {container_name!r}") try: container = docker_client.containers.get(container_name) except docker.errors.NotFound: - log.warn("container named %r not found while resolving %r" % (container_name, domain_name)) + log.warn(f"container named {container_name!r} not found while resolving {domain_name!r}") return - log.debug("container %r found (%s)" % (container.name, container.short_id)) + log.debug(f"container {container.name!r} found ({container.short_id})") ip = container_ip(container) - log.info("resolving domain name %r as IP address %s of container %s" % (domain_name, ip, container.name)) + log.info(f"resolving domain name {domain_name!r} as IP address {ip} of container {container.name}") return ip @@ -215,7 +215,7 @@ def monkey_patch_urllib_dns_resolver(): prv_getaddrinfo = socket.getaddrinfo dns_cache = {} def new_getaddrinfo(*args): - logging.getLogger('DNS').debug("resolving domain name %s" % repr(args)) + logging.getLogger('DNS').debug(f"resolving domain name {repr(args)}") _args = list(args) # custom DNS resolvers @@ -243,7 +243,7 @@ def remove_all_containers(): for container in docker_client.containers.list(all=True): if I_AM_RUNNING_INSIDE_A_DOCKER_CONTAINER and container.id.startswith(socket.gethostname()): continue # pytest is running within a Docker container, so we do not want to remove that particular container - logging.info("removing container %s" % container.name) + logging.info(f"removing container {container.name}") container.remove(v=True, force=True) @@ -263,19 +263,19 @@ def get_nginx_conf_from_container(container): def docker_compose_up(compose_file='docker-compose.yml'): - logging.info('docker-compose -f %s up -d' % compose_file) + logging.info(f'docker-compose -f {compose_file} up -d') try: - subprocess.check_output(shlex.split('docker-compose -f %s up -d' % compose_file), stderr=subprocess.STDOUT) + subprocess.check_output(shlex.split(f'docker-compose -f {compose_file} up -d'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - pytest.fail("Error while runninng 'docker-compose -f %s up -d':\n%s" % (compose_file, e.output), pytrace=False) + pytest.fail(f"Error while runninng 'docker-compose -f {compose_file} up -d':\n{e.output}", pytrace=False) def docker_compose_down(compose_file='docker-compose.yml'): - logging.info('docker-compose -f %s down' % compose_file) + logging.info(f'docker-compose -f {compose_file} down') try: - subprocess.check_output(shlex.split('docker-compose -f %s down' % compose_file), stderr=subprocess.STDOUT) + subprocess.check_output(shlex.split(f'docker-compose -f {compose_file} down'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - pytest.fail("Error while runninng 'docker-compose -f %s down':\n%s" % (compose_file, e.output), pytrace=False) + pytest.fail(f"Error while runninng 'docker-compose -f {compose_file} down':\n{e.output}", pytrace=False) def wait_for_nginxproxy_to_be_ready(): @@ -309,7 +309,7 @@ def find_docker_compose_file(request): if docker_compose_file_module_variable is not None: docker_compose_file = os.path.join( test_module_dir, docker_compose_file_module_variable) if not os.path.isfile(docker_compose_file): - raise ValueError("docker compose file %r could not be found. Check your test module `docker_compose_file` variable value." % docker_compose_file) + raise ValueError(f"docker compose file {docker_compose_file!r} could not be found. Check your test module `docker_compose_file` variable value.") else: if os.path.isfile(yml_file): docker_compose_file = yml_file @@ -321,7 +321,7 @@ def find_docker_compose_file(request): if not os.path.isfile(docker_compose_file): logging.error("Could not find any docker-compose file named either '{0}.yml', '{0}.yaml' or 'docker-compose.yml'".format(request.module.__name__)) - logging.debug("using docker compose file %s" % docker_compose_file) + logging.debug(f"using docker compose file {docker_compose_file}") return docker_compose_file @@ -335,7 +335,7 @@ def connect_to_network(network): try: my_container = docker_client.containers.get(socket.gethostname()) except docker.errors.NotFound: - logging.warn("container %r not found" % socket.gethostname()) + logging.warn(f"container {socket.gethostname()!r} not found") return # figure out our container networks @@ -343,7 +343,7 @@ def connect_to_network(network): # make sure our container is connected to the nginx-proxy's network if network not in my_networks: - logging.info("Connecting to docker network: %s" % network.name) + logging.info(f"Connecting to docker network: {network.name}") network.connect(my_container) return network @@ -358,7 +358,7 @@ def disconnect_from_network(network=None): try: my_container = docker_client.containers.get(socket.gethostname()) except docker.errors.NotFound: - logging.warn("container %r not found" % socket.gethostname()) + logging.warn(f"container {socket.gethostname()!r} not found") return # figure out our container networks @@ -366,7 +366,7 @@ def disconnect_from_network(network=None): # disconnect our container from the given network if network.name in my_networks_names: - logging.info("Disconnecting from network %s" % network.name) + logging.info(f"Disconnecting from network {network.name}") network.disconnect(my_container) @@ -458,7 +458,7 @@ def pytest_runtest_makereport(item, call): def pytest_runtest_setup(item): previousfailed = getattr(item.parent, "_previousfailed", None) if previousfailed is not None: - pytest.xfail("previous test failed (%s)" % previousfailed.name) + pytest.xfail(f"previous test failed ({previousfailed.name})") ############################################################################### # diff --git a/test/requirements/web/webserver.py b/test/requirements/web/webserver.py index 9334657..b8e81c0 100755 --- a/test/requirements/web/webserver.py +++ b/test/requirements/web/webserver.py @@ -13,13 +13,13 @@ class Handler(http.server.SimpleHTTPRequestHandler): if self.path == "/headers": response_body += self.headers.as_string() elif self.path == "/port": - response_body += "answer from port %s\n" % PORT + response_body += f"answer from port {PORT}\n" elif re.match("/status/(\d+)", self.path): result = re.match("/status/(\d+)", self.path) response_code = int(result.group(1)) - response_body += "answer with response code %s\n" % response_code + response_body += f"answer with response code {response_code}\n" elif self.path == "/": - response_body += "I'm %s\n" % os.environ['HOSTNAME'] + response_body += f"I'm {os.environ['HOSTNAME']}\n" else: response_body += "No route for this path!\n" response_code = 404 diff --git a/test/test_dockergen/test_dockergen_v2.py b/test/test_dockergen/test_dockergen_v2.py index a3f2484..43b1431 100644 --- a/test/test_dockergen/test_dockergen_v2.py +++ b/test/test_dockergen/test_dockergen_v2.py @@ -39,4 +39,4 @@ def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy): r = nginxproxy.get("http://whoami.nginx.container.docker/") assert r.status_code == 200 whoami_container = docker_compose.containers.get("whoami") - assert r.text == "I'm %s\n" % whoami_container.id[:12] + assert r.text == f"I'm {whoami_container.id[:12]}\n" diff --git a/test/test_dockergen/test_dockergen_v3.py b/test/test_dockergen/test_dockergen_v3.py index 1beffeb..358f793 100644 --- a/test/test_dockergen/test_dockergen_v3.py +++ b/test/test_dockergen/test_dockergen_v3.py @@ -24,8 +24,7 @@ def versiontuple(v): raw_version = docker.from_env().version()["Version"] pytestmark = pytest.mark.skipif( versiontuple(raw_version) < (1, 13), - reason="Docker compose syntax v3 requires docker engine v1.13 or later (got %s)" - % raw_version, + reason="Docker compose syntax v3 requires docker engine v1.13 or later (got {raw_version})" ) @@ -64,7 +63,7 @@ def test_forwards_to_whoami(nginx_tmpl, docker_compose, nginxproxy): r = nginxproxy.get("http://whoami.nginx.container.docker/") assert r.status_code == 200 whoami_container = docker_compose.containers.get("whoami") - assert r.text == "I'm %s\n" % whoami_container.id[:12] + assert r.text == f"I'm {whoami_container.id[:12]}\n" if __name__ == "__main__": diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index 8899c6a..acb4269 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -55,7 +55,7 @@ def require_openssl(required_version): openssl_version = str(command_output.split()[1]) return pytest.mark.skipif( versiontuple(openssl_version) < versiontuple(required_version), - reason="openssl v%s is less than required version %s" % (openssl_version, required_version)) + reason=f"openssl v{openssl_version} is less than required version {required_version}") ############################################################################### @@ -87,7 +87,7 @@ def test_web5_dhparam_is_used(docker_compose): sut_container = docker_client.containers.get("nginxproxy") assert sut_container.status == "running" - host = "%s:443" % sut_container.attrs["NetworkSettings"]["IPAddress"] + host = f"{sut_container.attrs['NetworkSettings']['IPAddress']}:443" r = subprocess.check_output( f"echo '' | openssl s_client -connect {host} -cipher 'EDH' | grep 'Server Temp Key'", shell=True) assert b"Server Temp Key: X25519, 253 bits\n" == r diff --git a/test/test_ssl/test_wildcard.py b/test/test_ssl/test_wildcard.py index 9885d94..202ba24 100644 --- a/test/test_ssl/test_wildcard.py +++ b/test/test_ssl/test_wildcard.py @@ -3,21 +3,21 @@ import pytest @pytest.mark.parametrize("subdomain", ["foo", "bar"]) def test_web1_http_redirects_to_https(docker_compose, nginxproxy, subdomain): - r = nginxproxy.get("http://%s.nginx-proxy.tld/" % subdomain, allow_redirects=False) + r = nginxproxy.get(f"http://{subdomain}.nginx-proxy.tld/", allow_redirects=False) assert r.status_code == 301 assert "Location" in r.headers - assert "https://%s.nginx-proxy.tld/" % subdomain == r.headers['Location'] + assert f"https://{subdomain}.nginx-proxy.tld/" == r.headers['Location'] @pytest.mark.parametrize("subdomain", ["foo", "bar"]) def test_web1_https_is_forwarded(docker_compose, nginxproxy, subdomain): - r = nginxproxy.get("https://%s.nginx-proxy.tld/port" % subdomain, allow_redirects=False) + r = nginxproxy.get(f"https://{subdomain}.nginx-proxy.tld/port", allow_redirects=False) assert r.status_code == 200 assert "answer from port 81\n" in r.text @pytest.mark.parametrize("subdomain", ["foo", "bar"]) def test_web1_HSTS_policy_is_active(docker_compose, nginxproxy, subdomain): - r = nginxproxy.get("https://%s.nginx-proxy.tld/port" % subdomain, allow_redirects=False) + r = nginxproxy.get(f"https://{subdomain}.nginx-proxy.tld/port", allow_redirects=False) assert "answer from port 81\n" in r.text assert "Strict-Transport-Security" in r.headers diff --git a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py index 1946cc0..03af625 100644 --- a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py +++ b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py @@ -9,19 +9,19 @@ from requests.exceptions import SSLError (3, False), ]) def test_http_redirects_to_https(docker_compose, nginxproxy, subdomain, should_redirect_to_https): - r = nginxproxy.get("http://%s.web.nginx-proxy.tld/port" % subdomain) + r = nginxproxy.get(f"http://{subdomain}.web.nginx-proxy.tld/port") if should_redirect_to_https: assert len(r.history) > 0 assert r.history[0].is_redirect - assert r.history[0].headers.get("Location") == "https://%s.web.nginx-proxy.tld/port" % subdomain - assert "answer from port 8%s\n" % subdomain == r.text + assert r.history[0].headers.get("Location") == f"https://{subdomain}.web.nginx-proxy.tld/port" + assert f"answer from port 8{subdomain}\n" == r.text @pytest.mark.parametrize("subdomain", [1, 2]) def test_https_get_served(docker_compose, nginxproxy, subdomain): - r = nginxproxy.get("https://%s.web.nginx-proxy.tld/port" % subdomain, allow_redirects=False) + r = nginxproxy.get(f"https://{subdomain}.web.nginx-proxy.tld/port", allow_redirects=False) assert r.status_code == 200 - assert "answer from port 8%s\n" % subdomain == r.text + assert f"answer from port 8{subdomain}\n" == r.text def test_web3_https_is_500_and_SSL_validation_fails(docker_compose, nginxproxy): diff --git a/test/test_wildcard_host.py b/test/test_wildcard_host.py index eb8428e..a5b6633 100644 --- a/test/test_wildcard_host.py +++ b/test/test_wildcard_host.py @@ -18,9 +18,9 @@ import pytest ("web4.whatever.nginx-proxy.regexp", 84), ]) def test_wildcard_prefix(docker_compose, nginxproxy, host, expected_port): - r = nginxproxy.get("http://%s/port" % host) + r = nginxproxy.get(f"http://{host}/port") assert r.status_code == 200 - assert r.text == "answer from port %s\n" % expected_port + assert r.text == f"answer from port {expected_port}\n" @pytest.mark.parametrize("host", [ @@ -28,5 +28,5 @@ def test_wildcard_prefix(docker_compose, nginxproxy, host, expected_port): "web4.whatever.nginx-proxy.regexp-to-infinity-and-beyond" ]) def test_non_matching_host_is_503(docker_compose, nginxproxy, host): - r = nginxproxy.get("http://%s/port" % host) + r = nginxproxy.get(f"http://{host}/port") assert r.status_code == 503, r.text From 6fd3cfb38f134e4741136d5013c14f76c9e80783 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 12:32:35 +0100 Subject: [PATCH 032/126] fix(ci): :wrench: add markers on pytest.ini to fix warnings --- test/pytest.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/pytest.ini b/test/pytest.ini index 30f3e19..9ca7667 100644 --- a/test/pytest.ini +++ b/test/pytest.ini @@ -1,3 +1,5 @@ [pytest] # disable the creation of the `.cache` folders -addopts = -p no:cacheprovider --ignore=requirements --ignore=certs -r s -v \ No newline at end of file +addopts = -p no:cacheprovider --ignore=requirements --ignore=certs -r s -v +markers = + incremental: mark a test as incremental. \ No newline at end of file From 0c60d5703150be43abc1200da0644fbeeacd24b8 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 2 Apr 2021 01:03:19 +0200 Subject: [PATCH 033/126] fix(ci): fix test_dhparam_is_generated_if_missing --- test/test_ssl/test_dhparam_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_ssl/test_dhparam_generation.py b/test/test_ssl/test_dhparam_generation.py index 4ba1c53..ec1c90e 100644 --- a/test/test_ssl/test_dhparam_generation.py +++ b/test/test_ssl/test_dhparam_generation.py @@ -35,10 +35,10 @@ def test_dhparam_is_generated_if_missing(docker_compose): sut_container = docker_client.containers.get("nginxproxy") assert sut_container.status == "running" - assert_log_contains("Generating DH parameters") + assert_log_contains("Generating DSA parameters") assert_log_contains("dhparam generation complete, reloading nginx") # Make sure the dhparam in use is not the default, pre-generated one - default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").split() - generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").split() + default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").output.split() + generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() assert default_checksum[0] != generated_checksum[0] From dd7f7e842725b87f8ff2ba6f412ca3358a5d8f19 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Sat, 3 Apr 2021 21:38:49 +0200 Subject: [PATCH 034/126] fix(ci): wrong nginx-proxy image used on default_host test --- test/test_default-host.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_default-host.yml b/test/test_default-host.yml index f195f58..47b8525 100644 --- a/test/test_default-host.yml +++ b/test/test_default-host.yml @@ -10,7 +10,7 @@ web1: # WHEN nginx-proxy runs with DEFAULT_HOST set to web1.tld sut: - image: jwilder/nginx-proxy:test + image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From dd853b25726053cb92dc811900e0d4fe1254fc4f Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 13:46:38 +0100 Subject: [PATCH 035/126] chore(ci): :construction_worker: mv unit test from travis to ga --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b1930a5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test + +on: [push, pull_request] + +jobs: + unit: + name: Unit Test + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + docker_image: [alpine, debian] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r python-requirements.txt + working-directory: test/requirements + + - name: Build Docker web server image + run: make update-dependencies + + - name: Run tests + run: make test-${{ matrix.docker_image }} From 3b1163291b9bf859bd72f76bdb6488b48a1a9db3 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 14:08:54 +0100 Subject: [PATCH 036/126] fix(test): test_dockergen_v3 version comparison --- test/test_dockergen/test_dockergen_v3.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/test/test_dockergen/test_dockergen_v3.py b/test/test_dockergen/test_dockergen_v3.py index 358f793..67561bf 100644 --- a/test/test_dockergen/test_dockergen_v3.py +++ b/test/test_dockergen/test_dockergen_v3.py @@ -3,27 +3,12 @@ import docker import logging import pytest import re - -def versiontuple(v): - """ - >>> versiontuple("1.12.3") - (1, 12, 3) - - >>> versiontuple("1.13.0") - (1, 13, 0) - - >>> versiontuple("17.03.0-ce") - (17, 3, 0) - - >>> versiontuple("17.03.0-ce") < (1, 13) - False - """ - return tuple(map(int, (v.split("-")[0].split(".")))) +from distutils.version import LooseVersion raw_version = docker.from_env().version()["Version"] pytestmark = pytest.mark.skipif( - versiontuple(raw_version) < (1, 13), + LooseVersion(raw_version) < LooseVersion("1.13"), reason="Docker compose syntax v3 requires docker engine v1.13 or later (got {raw_version})" ) From 1591fd7968e9bc2904cc9c052d94addfd583f15f Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 15:12:16 +0100 Subject: [PATCH 037/126] chore(ci): :green_heart: use standard python for nginx-proxy-tester --- test/requirements/Dockerfile-nginx-proxy-tester | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/requirements/Dockerfile-nginx-proxy-tester b/test/requirements/Dockerfile-nginx-proxy-tester index 6c0f060..3c25c0c 100644 --- a/test/requirements/Dockerfile-nginx-proxy-tester +++ b/test/requirements/Dockerfile-nginx-proxy-tester @@ -1,7 +1,4 @@ -FROM python:3.9-alpine - -# Note: we're using alpine because it has openssl 1.0.2, which we need for testing -RUN apk add --update bash openssl curl && rm -rf /var/cache/apk/* +FROM python:3.9 COPY python-requirements.txt /requirements.txt RUN pip install -r /requirements.txt From 39f822dd8bfea95e6e91d2e9b4c46d33b639d13e Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Fri, 19 Mar 2021 16:44:50 +0100 Subject: [PATCH 038/126] refactor(ci): :recycle: refactor makefile and modify its usage on CI --- .github/workflows/test.yml | 10 +++++++--- Makefile | 14 +++++++++----- test/requirements/build.sh | 6 ------ 3 files changed, 16 insertions(+), 14 deletions(-) delete mode 100755 test/requirements/build.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1930a5..cde7ff3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: true matrix: - docker_image: [alpine, debian] + base_docker_image: [alpine, debian] steps: - uses: actions/checkout@v2 @@ -27,7 +27,11 @@ jobs: working-directory: test/requirements - name: Build Docker web server image - run: make update-dependencies + run: make build-webserver + + - name: Build Docker nginx proxy test image + run: make build-nginx-proxy-test-${{ matrix.base_docker_image }} - name: Run tests - run: make test-${{ matrix.docker_image }} + run: pytest + working-directory: test \ No newline at end of file diff --git a/Makefile b/Makefile index d7db2b8..18fcd33 100644 --- a/Makefile +++ b/Makefile @@ -2,15 +2,19 @@ .PHONY : test-debian test-alpine test -update-dependencies: - test/requirements/build.sh +build-webserver: + docker build -t web test/requirements/web -test-debian: update-dependencies +build-nginx-proxy-test-debian: docker build -t nginxproxy/nginx-proxy:test . + +build-nginx-proxy-test-alpine: + docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . + +test-debian: build-webserver build-nginx-proxy-test-debian test/pytest.sh -test-alpine: update-dependencies - docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . +test-alpine: build-webserver build-nginx-proxy-test-alpine test/pytest.sh test: test-debian test-alpine diff --git a/test/requirements/build.sh b/test/requirements/build.sh deleted file mode 100755 index f29897a..0000000 --- a/test/requirements/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -docker build -t web $DIR/web \ No newline at end of file From 1518c39e1bdafb33b03e8e48781078a6bdf0c9c8 Mon Sep 17 00:00:00 2001 From: Kevin Marilleau Date: Mon, 26 Apr 2021 23:15:08 +0200 Subject: [PATCH 039/126] docs: update "how to install/test" parts --- README.md | 21 +++++++-------------- test/README.md | 15 +++++---------- test/requirements/README.md | 2 +- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 813fdda..bc8c3db 100644 --- a/README.md +++ b/README.md @@ -415,22 +415,15 @@ Before submitting pull requests or issues, please check github to make sure an e #### Running Tests Locally -To run tests, you need to prepare the docker image to test which must be tagged `nginxproxy/nginx-proxy:test`: - - docker build -t nginxproxy/nginx-proxy:test . # build the Debian variant image - -and call the [test/pytest.sh](test/pytest.sh) script. - -Then build the Alpine variant of the image: - - docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . # build the Alpline variant image - -and call the [test/pytest.sh](test/pytest.sh) script again. - - -If your system has the `make` command, you can automate those tasks by calling: +To run tests, you just need to run the command below: make test +This commands run tests on two variants of the nginx-proxy docker image: Debian and Alpine. + +You can run the tests for each of these images with their respective commands: + + make test-debian + make test-alpine You can learn more about how the test suite works and how to write new tests in the [test/README.md](test/README.md) file. diff --git a/test/README.md b/test/README.md index c62960a..dd9db44 100644 --- a/test/README.md +++ b/test/README.md @@ -4,9 +4,8 @@ Nginx proxy test suite Install requirements -------------------- -You need [python 2.7](https://www.python.org/) and [pip](https://pip.pypa.io/en/stable/installing/) installed. Then run the commands: +You need [python 3.9](https://www.python.org/) and [pip](https://pip.pypa.io/en/stable/installing/) installed. Then run the commands: - requirements/build.sh pip install -r requirements/python-requirements.txt If you can't install those requirements on your computer, you can alternatively use the _pytest.sh_ script which will run the tests from a Docker container which has those requirements. @@ -15,14 +14,11 @@ If you can't install those requirements on your computer, you can alternatively Prepare the nginx-proxy test image ---------------------------------- - docker build -t nginxproxy/nginx-proxy:test .. + make build-nginx-proxy-test-debian or if you want to test the alpine flavor: - docker build -t nginxproxy/nginx-proxy:test -f Dockerfile.alpine .. - -make sure to tag that test image exactly `nginxproxy/nginx-proxy:test` or the test suite won't work. - + make build-nginx-proxy-test-alpine Run the test suite ------------------ @@ -61,7 +57,7 @@ The fixture will run the _docker-compose_ command with the `-f` option to load t In the case you are running pytest from within a docker container, the `docker_compose` fixture will make sure the container running pytest is attached to all docker networks. That way, your test will be able to reach any of them. -In your tests, you can use the `docker_compose` variable to query and command the docker daemon as it provides you with a [client from the docker python module](https://docker-py.readthedocs.io/en/2.0.2/client.html#client-reference). +In your tests, you can use the `docker_compose` variable to query and command the docker daemon as it provides you with a [client from the docker python module](https://docker-py.readthedocs.io/en/4.4.4/client.html#client-reference). Also this fixture alters the way the python interpreter resolves domain names to IP addresses in the following ways: @@ -99,8 +95,7 @@ Furthermore, the nginxproxy methods accept an additional keyword parameter: `ipv ### The web docker image -When you ran the `requirements/build.sh` script earlier, you built a [`web`](requirements/README.md) docker image which is convenient for running a small web server in a container. This image can produce containers that listens on multiple ports at the same time. - +When you run the `make build-webserver` command, you built a [`web`](requirements/README.md) docker image which is convenient for running a small web server in a container. This image can produce containers that listens on multiple ports at the same time. ### Testing TLS diff --git a/test/requirements/README.md b/test/requirements/README.md index 3a0c389..394c9b1 100644 --- a/test/requirements/README.md +++ b/test/requirements/README.md @@ -2,7 +2,7 @@ This directory contains resources to build Docker images tests depend on # Build images - ./build.sh + make build-webserver # python-requirements.txt From 5e4f00524031df3a63622dc72eea946325892451 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Apr 2021 22:44:46 +0000 Subject: [PATCH 040/126] Bump nginx from 1.19.3 to 1.19.10 Bumps nginx from 1.19.3 to 1.19.10. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 83253c5..063cf62 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN go get -v ./... && \ CGO_ENABLED=0 GOOS=linux go build -o forego . # Build the final image -FROM nginx:1.19.3 +FROM nginx:1.19.10 LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 5de844c..faf8a2b 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -39,7 +39,7 @@ RUN go get -v ./... && \ CGO_ENABLED=0 GOOS=linux go build -o forego . # Build the final image -FROM nginx:1.19.3-alpine +FROM nginx:1.19.10-alpine LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates From 0d2efaee95f29099ea7d5036136e07c9994c73a2 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 27 Apr 2021 01:10:17 +0200 Subject: [PATCH 041/126] docs: update nginx version and CI badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc8c3db..dcfad7b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) -![nginx 1.19.3](https://img.shields.io/badge/nginx-1.19.3-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Build Status](https://travis-ci.org/nginx/nginx-proxy.svg?branch=main)](https://travis-ci.org/jwilder/nginx-proxy) [![](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') +![nginx 1.19.10](https://img.shields.io/badge/nginx-1.19.10-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) [![](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. From f7444094cad54c7750006a58c9c4db3ef709fa9a Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 27 Apr 2021 01:12:28 +0200 Subject: [PATCH 042/126] ci: remove Travis CI --- .travis.yml | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7a1c66f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -dist: trusty -sudo: required - -env: - matrix: - - TEST_TARGET: test-debian - - TEST_TARGET: test-alpine - -before_install: - - sudo apt-get -y remove docker docker-engine docker-ce - - sudo rm /etc/apt/sources.list.d/docker.list - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - - sudo apt-get update - - sudo apt-get -y install docker-ce - - docker version - - docker info - # prepare docker test requirements - - make update-dependencies - -script: - - make $TEST_TARGET From 1f937dd6a520533a442fb474dc5f765902febee7 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 28 Apr 2021 09:58:03 +0200 Subject: [PATCH 043/126] docs: don't mention Docker container based tests Those aren't working yet and are being worked on close #1605 --- test/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index dd9db44..df7c214 100644 --- a/test/README.md +++ b/test/README.md @@ -8,7 +8,6 @@ You need [python 3.9](https://www.python.org/) and [pip](https://pip.pypa.io/en/ pip install -r requirements/python-requirements.txt -If you can't install those requirements on your computer, you can alternatively use the _pytest.sh_ script which will run the tests from a Docker container which has those requirements. Prepare the nginx-proxy test image @@ -99,4 +98,4 @@ When you run the `make build-webserver` command, you built a [`web`](requirement ### Testing TLS -If you need to create server certificates, use the [`certs/create_server_certificate.sh`](certs/) script. Pytest will be able to validate any certificate issued from this script. \ No newline at end of file +If you need to create server certificates, use the [`certs/create_server_certificate.sh`](certs/) script. Pytest will be able to validate any certificate issued from this script. From e3cc439ff00ed98e4dc7642f6ea6f0ed8558d604 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 28 Apr 2021 22:43:40 +0200 Subject: [PATCH 044/126] doc: bring badges in line with acme-companion --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dcfad7b..83b5cf4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ -![latest 0.8.0](https://img.shields.io/badge/latest-0.8.0-green.svg?style=flat) -![nginx 1.19.10](https://img.shields.io/badge/nginx-1.19.10-brightgreen.svg) ![License MIT](https://img.shields.io/badge/license-MIT-blue.svg) [![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) [![](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') +[![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) +[![GitHub release](https://img.shields.io/github/v/release/nginx-proxy/nginx-proxy)](https://github.com/nginx-proxy/nginx-proxy/releases) +![nginx 1.19.10](https://img.shields.io/badge/nginx-1.19.10-brightgreen.svg) +[![Docker Image Size](https://img.shields.io/docker/image-size/nginxproxy/nginx-proxy?sort=semver)](https://hub.docker.com/r/nginxproxy/nginx-proxy "Click to view the image on Docker Hub") +[![Docker stars](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') +[![Docker pulls](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. From 85327a871eaf8762c8560fce0beb6e6b27649b63 Mon Sep 17 00:00:00 2001 From: Chris Heald Date: Mon, 20 Aug 2018 18:35:31 -0700 Subject: [PATCH 045/126] Suffix upstream names to prevent confusion with FQDNs --- nginx.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index f18aa21..1e03182 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -172,7 +172,7 @@ server { {{ $host := trim $host }} {{ $is_regexp := hasPrefix "~" $host }} -{{ $upstream_name := when $is_regexp (sha1 $host) $host }} +{{ $upstream_name := (print (when $is_regexp (sha1 $host) $host) "-upstream") }} # {{ $host }} upstream {{ $upstream_name }} { From cbc6f09d2ac7c19e0ed0cea74c879de44064853b Mon Sep 17 00:00:00 2001 From: Jesse Jarzynka Date: Mon, 8 Apr 2019 23:39:00 -0400 Subject: [PATCH 046/126] Change dhparam positional args to be inherited vars, standardize naming PR #913 added `DHPARAM_GENERATION` as a positional argument to generate-dhparam.sh. However, since it was the second positional argument, `DHPARAM_BITS` would also have to be defined or `DHPARAM_GENERATION` would be read into `DHPARAM_BITS`. This changes the arguments to be inherited variables which do not depend on order, just declaration. Also change instances of `GENERATE_DHPARAM` to `DHPARAM_GENERATION` since it's unnecessary to have another variable. I think `GENERATE_DHPARAM` is actually a better name (verb vs. noun), but `DHPARAM_GENERATION` is already defined and may break someone if changed. Addresses https://github.com/jwilder/nginx-proxy/pull/913#issuecomment-476014691 --- generate-dhparam.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/generate-dhparam.sh b/generate-dhparam.sh index 03b828c..bff6543 100755 --- a/generate-dhparam.sh +++ b/generate-dhparam.sh @@ -1,8 +1,9 @@ #!/bin/bash -e -# The first argument is the bit depth of the dhparam, or 4096 if unspecified -DHPARAM_BITS=${1:-4096} -GENERATE_DHPARAM=${2:-true} +# DHPARAM_BITS is the bit depth of the dhparam, or 4096 if unspecified +DHPARAM_BITS=${DHPARAM_BITS:-4096} +# DHPARAM_GENERATION=false skips dhparam generation +DHPARAM_GENERATION=${DHPARAM_GENERATION:-true} # If a dhparam file is not available, use the pre-generated one and generate a new one in the background. # Note that /etc/nginx/dhparam is a volume, so this dhparam will persist restarts. @@ -26,7 +27,7 @@ if [[ -f $DHPARAM_FILE ]]; then fi fi -if [[ $GENERATE_DHPARAM =~ ^[Ff][Aa][Ll][Ss][Ee]$ ]]; then +if [[ $DHPARAM_GENERATION =~ ^[Ff][Aa][Ll][Ss][Ee]$ ]]; then echo "Skipping Diffie-Hellman parameters generation and Ignoring pre-generated dhparam.pem" exit 0 fi From c327496495e011203728974773cba80ef8292753 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 29 Apr 2021 03:18:04 +0200 Subject: [PATCH 047/126] refactor: do not pass unused positional arguments --- docker-entrypoint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5993212..6e9f7d4 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -15,9 +15,7 @@ if [[ $DOCKER_HOST = unix://* ]]; then fi # Generate dhparam file if required -# Note: if $DHPARAM_BITS is not defined, generate-dhparam.sh will use 4096 as a default -# Note2: if $DHPARAM_GENERATION is set to false in environment variable, dh param generator will skip completely -/app/generate-dhparam.sh $DHPARAM_BITS $DHPARAM_GENERATION +/app/generate-dhparam.sh # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] export RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g') From ab81ff8df234c5421fdce9d66ba482c797c9a536 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Thu, 29 Apr 2021 03:18:40 +0200 Subject: [PATCH 048/126] style: linting with shellcheck --- docker-entrypoint.sh | 8 ++++---- generate-dhparam.sh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 6e9f7d4..279bd18 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,7 +4,7 @@ set -e # Warn if the DOCKER_HOST socket does not exist if [[ $DOCKER_HOST = unix://* ]]; then socket_file=${DOCKER_HOST#unix://} - if ! [ -S $socket_file ]; then + if ! [ -S "$socket_file" ]; then cat >&2 <<-EOT ERROR: you need to share your Docker host socket with a volume at $socket_file Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` @@ -18,14 +18,14 @@ fi /app/generate-dhparam.sh # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] -export RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g') -if [ "x$RESOLVERS" = "x" ]; then +RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS +if [ "$RESOLVERS" = "" ]; then echo "Warning: unable to determine DNS resolvers for nginx" >&2 unset RESOLVERS fi # If the user has run the default command and the socket doesn't exist, fail -if [ "$socketMissing" = 1 -a "$1" = forego -a "$2" = start -a "$3" = '-r' ]; then +if [ "$socketMissing" = 1 ] && [ "$1" = forego ] && [ "$2" = start ] && [ "$3" = '-r' ]; then exit 1 fi diff --git a/generate-dhparam.sh b/generate-dhparam.sh index bff6543..397fab0 100755 --- a/generate-dhparam.sh +++ b/generate-dhparam.sh @@ -15,7 +15,7 @@ GEN_LOCKFILE="/tmp/dhparam_generating.lock" PREGEN_HASH=$(md5sum $PREGEN_DHPARAM_FILE | cut -d" " -f1) if [[ -f $DHPARAM_FILE ]]; then CURRENT_HASH=$(md5sum $DHPARAM_FILE | cut -d" " -f1) - if [[ $PREGEN_HASH != $CURRENT_HASH ]]; then + if [[ $PREGEN_HASH != "$CURRENT_HASH" ]]; then # There is already a dhparam, and it's not the default echo "Custom dhparam.pem file found, generation skipped" exit 0 @@ -44,10 +44,10 @@ touch $GEN_LOCKFILE # Generate a new dhparam in the background in a low priority and reload nginx when finished (grep removes the progress indicator). ( ( - nice -n +5 openssl dhparam -dsaparam -out $DHPARAM_FILE.tmp $DHPARAM_BITS 2>&1 \ + nice -n +5 openssl dhparam -dsaparam -out $DHPARAM_FILE.tmp "$DHPARAM_BITS" 2>&1 \ && mv $DHPARAM_FILE.tmp $DHPARAM_FILE \ && echo "dhparam generation complete, reloading nginx" \ && nginx -s reload ) | grep -vE '^[\.+]+' rm $GEN_LOCKFILE -) &disown +) & disown From a9cfdc843e6b079631b2917a421669fa7244cfc7 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Sat, 1 May 2021 22:30:57 +0200 Subject: [PATCH 049/126] docs: fix broken link --- test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index df7c214..99d16db 100644 --- a/test/README.md +++ b/test/README.md @@ -38,7 +38,7 @@ Run one single test module Write a test module ------------------- -This test suite uses [pytest](http://doc.pytest.org/en/latest/). The [conftest.py](conftest.py) file will be automatically loaded by pytest and will provide you with two useful pytest [fixtures](http://doc.pytest.org/en/latest/fixture.html#fixture): +This test suite uses [pytest](http://doc.pytest.org/en/latest/). The [conftest.py](conftest.py) file will be automatically loaded by pytest and will provide you with two useful pytest [fixtures](https://docs.pytest.org/en/latest/explanation/fixtures.html): - docker_compose - nginxproxy From 09d30cf1a60f9e6edbd741819ab73e64397e7f9e Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Sat, 1 May 2021 22:37:01 +0200 Subject: [PATCH 050/126] ci: don't run tests on docs only change --- .github/workflows/test.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cde7ff3..7a7134c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,10 +1,18 @@ -name: Test +name: Tests -on: [push, pull_request] +on: + push: + paths-ignore: + - 'LICENSE' + - '**.md' + pull_request: + paths-ignore: + - 'LICENSE' + - '**.md' jobs: unit: - name: Unit Test + name: Unit Tests runs-on: ubuntu-latest strategy: @@ -34,4 +42,4 @@ jobs: - name: Run tests run: pytest - working-directory: test \ No newline at end of file + working-directory: test From 70b95b17088e72cb2bc411bda6ac658002636680 Mon Sep 17 00:00:00 2001 From: Laurynas Alekna Date: Tue, 11 May 2021 10:22:56 +0100 Subject: [PATCH 051/126] Fix create_server_certificate.sh Docker image nginx:1.14.1 has no openssl installed. Therefore upgrading to nginx:1.19.10 --- test/certs/create_server_certificate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/certs/create_server_certificate.sh b/test/certs/create_server_certificate.sh index ae51280..bcbfdca 100755 --- a/test/certs/create_server_certificate.sh +++ b/test/certs/create_server_certificate.sh @@ -24,7 +24,7 @@ fi # Create a nginx container (which conveniently provides the `openssl` command) ############################################################################### -CONTAINER=$(docker run -d -v $DIR:/work -w /work -e SAN="$ALTERNATE_DOMAINS" nginx:1.14.1) +CONTAINER=$(docker run -d -v $DIR:/work -w /work -e SAN="$ALTERNATE_DOMAINS" nginx:1.19.10) # Configure openssl docker exec $CONTAINER bash -c ' mkdir -p /ca/{certs,crl,private,newcerts} 2>/dev/null From fb7a11212fee18438359e94e6f6d06cfee2980ac Mon Sep 17 00:00:00 2001 From: Laurynas Alekna Date: Mon, 10 May 2021 22:35:53 +0100 Subject: [PATCH 052/126] Make server_tokens configurable per virtual-host --- README.md | 4 ++ nginx.tmpl | 17 +++++ test/conftest.py | 25 +++++-- .../web-server-tokens-off.nginx-proxy.tld.crt | 71 +++++++++++++++++++ .../web-server-tokens-off.nginx-proxy.tld.key | 27 +++++++ test/test_headers/test_http.py | 24 ++++++- test/test_headers/test_http.yml | 9 +++ test/test_headers/test_https.py | 25 +++++-- test/test_headers/test_https.yml | 13 ++++ 9 files changed, 204 insertions(+), 11 deletions(-) create mode 100644 test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.crt create mode 100644 test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.key diff --git a/README.md b/README.md index af93cdb..9b13463 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,10 @@ If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=e If you want most of your virtual hosts to use a default single `location` block configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default_location` file. This file will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}_location` file associated with it. +#### Per-VIRTUAL_HOST `server_tokens` configuration +Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details. + + ### Contributing Before submitting pull requests or issues, please check github to make sure an existing issue or pull request is not already open. diff --git a/nginx.tmpl b/nginx.tmpl index d6a1661..9d90241 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -143,6 +143,7 @@ proxy_set_header Proxy ""; {{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }} server { server_name _; # This is just an invalid value which will never trigger on a real hostname. + server_tokens off; listen {{ $external_http_port }}; {{ if $enable_ipv6 }} listen [::]:{{ $external_http_port }}; @@ -154,6 +155,7 @@ server { {{ if (and (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }} server { server_name _; # This is just an invalid value which will never trigger on a real hostname. + server_tokens off; listen {{ $external_https_port }} ssl http2; {{ if $enable_ipv6 }} listen [::]:{{ $external_https_port }} ssl http2; @@ -210,6 +212,9 @@ upstream {{ $upstream_name }} { {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}} {{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }} +{{/* Get the SERVER_TOKENS defined by containers w/ the same vhost, falling back to "" */}} +{{ $server_tokens := trim (or (first (groupByKeys $containers "Env.SERVER_TOKENS")) "") }} + {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}} {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }} @@ -246,6 +251,9 @@ upstream {{ $upstream_name }} { {{ if eq $https_method "redirect" }} server { server_name {{ $host }}; + {{ if $server_tokens }} + server_tokens {{ $server_tokens }}; + {{ end }} listen {{ $external_http_port }} {{ $default_server }}; {{ if $enable_ipv6 }} listen [::]:{{ $external_http_port }} {{ $default_server }}; @@ -270,6 +278,9 @@ server { server { server_name {{ $host }}; + {{ if $server_tokens }} + server_tokens {{ $server_tokens }}; + {{ end }} listen {{ $external_https_port }} ssl http2 {{ $default_server }}; {{ if $enable_ipv6 }} listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }}; @@ -342,6 +353,9 @@ server { server { server_name {{ $host }}; + {{ if $server_tokens }} + server_tokens {{ $server_tokens }}; + {{ end }} listen {{ $external_http_port }} {{ $default_server }}; {{ if $enable_ipv6 }} listen [::]:80 {{ $default_server }}; @@ -387,6 +401,9 @@ server { {{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }} server { server_name {{ $host }}; + {{ if $server_tokens }} + server_tokens {{ $server_tokens }}; + {{ end }} listen {{ $external_https_port }} ssl http2 {{ $default_server }}; {{ if $enable_ipv6 }} listen [::]:{{ $external_https_port }} ssl http2 {{ $default_server }}; diff --git a/test/conftest.py b/test/conftest.py index aa398e6..b738c83 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,17 +1,19 @@ import contextlib import logging import os +import re import shlex import socket import subprocess import time -import re +from typing import List import backoff import docker import pytest import requests from _pytest._code.code import ReprExceptionInfo +from docker.models.containers import Container from requests.packages.urllib3.util.connection import HAS_IPV6 logging.basicConfig(level=logging.INFO) @@ -63,17 +65,32 @@ class requests_for_docker(object): if os.path.isfile(CA_ROOT_CERTIFICATE): self.session.verify = CA_ROOT_CERTIFICATE - def get_conf(self): + @staticmethod + def get_nginx_proxy_containers() -> List[Container]: """ - Return the nginx config file + Return list of containers """ nginx_proxy_containers = docker_client.containers.list(filters={"ancestor": "nginxproxy/nginx-proxy:test"}) if len(nginx_proxy_containers) > 1: pytest.fail("Too many running nginxproxy/nginx-proxy:test containers", pytrace=False) elif len(nginx_proxy_containers) == 0: pytest.fail("No running nginxproxy/nginx-proxy:test container", pytrace=False) + return nginx_proxy_containers + + def get_conf(self): + """ + Return the nginx config file + """ + nginx_proxy_containers = self.get_nginx_proxy_containers() return get_nginx_conf_from_container(nginx_proxy_containers[0]) + def get_ip(self) -> str: + """ + Return the nginx container ip address + """ + nginx_proxy_containers = self.get_nginx_proxy_containers() + return container_ip(nginx_proxy_containers[0]) + def get(self, *args, **kwargs): with ipv6(kwargs.pop('ipv6', False)): @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None) @@ -120,7 +137,7 @@ class requests_for_docker(object): return getattr(requests, name) -def container_ip(container): +def container_ip(container: Container): """ return the IP address of a container. diff --git a/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.crt b/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.crt new file mode 100644 index 0000000..a96109a --- /dev/null +++ b/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.crt @@ -0,0 +1,71 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 4096 (0x1000) + Signature Algorithm: sha256WithRSAEncryption + Issuer: O=nginx-proxy test suite, CN=www.nginx-proxy.tld + Validity + Not Before: May 11 18:25:49 2021 GMT + Not After : Sep 26 18:25:49 2048 GMT + Subject: CN=web-server-tokens-off.nginx-proxy.tld + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (2048 bit) + Modulus: + 00:b4:fa:9d:8a:74:3f:17:ea:99:1c:45:71:18:90: + eb:92:35:38:d7:90:21:81:0a:91:05:41:cf:b5:87: + 34:bd:d8:7b:7f:7d:06:33:f8:94:67:8e:e4:07:54: + 7f:b7:62:c5:76:6c:7f:7c:19:25:19:2c:36:9a:26: + 54:8e:2d:97:02:78:31:c6:13:d3:ad:f3:31:62:e6: + cf:96:ae:63:37:dd:bd:73:cb:4e:fb:3f:9b:65:67: + 97:d8:5a:5d:0e:72:b1:11:ab:0e:d7:23:a9:b7:22: + de:23:74:7e:88:7c:28:98:a9:6e:00:f4:be:8c:69: + ea:3f:33:8b:19:97:da:1b:a6:65:b5:5a:92:01:3c: + 3a:13:6b:00:02:e1:98:78:d3:da:ea:a6:9c:33:b0: + 1d:9f:02:c4:f1:d0:d6:de:7a:f7:42:12:4b:31:fb: + ed:e9:d7:d8:15:e8:4e:18:91:7c:9d:bf:0f:b0:12: + d6:e2:80:8b:7a:ef:17:70:51:f4:3c:b7:43:cb:56: + 61:af:61:7a:4e:9d:6c:5e:d8:27:0c:3b:d7:a4:1d: + 2f:0d:a0:99:8f:b5:71:93:21:b4:87:be:b4:1c:77: + a0:b9:cd:91:bd:9c:d0:b9:81:50:12:63:d2:0a:a9: + 61:05:91:19:27:f7:ea:9d:8e:48:65:2e:1a:e7:fd: + f1:b7 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Subject Alternative Name: + DNS:web-server-tokens-off.nginx-proxy.tld + Signature Algorithm: sha256WithRSAEncryption + 5b:b7:74:ad:07:08:65:3c:8e:02:50:a9:b6:f4:8d:47:95:6f: + e0:ba:5a:8c:ae:5c:32:88:8b:45:04:48:ce:3d:72:45:d7:7e: + 1e:d7:75:17:30:98:90:21:4c:67:e2:57:1d:c9:fa:03:f4:81: + 64:cf:d2:b3:85:71:be:53:b9:2a:fd:89:04:a6:b1:88:0a:0a: + f1:5c:93:9b:fb:4f:86:0e:c5:4d:6a:ff:54:7b:07:f1:7e:d1: + 8a:6b:fa:3b:f3:5c:d2:1b:2c:86:05:4c:e0:b4:04:0d:c7:db: + 0b:89:b4:33:09:b6:1a:f0:cb:d4:ae:2c:05:63:a4:18:19:52: + c7:15:21:ac:ae:9e:15:b9:b0:58:0c:96:df:7b:77:46:ef:59: + a7:96:56:da:f6:f6:81:9f:10:7d:5a:48:68:0c:28:02:5d:7b: + 69:4d:89:41:e2:88:6d:c6:22:45:6a:34:1b:ba:9b:6f:d6:2d: + c2:55:b1:73:b4:bb:f5:06:d6:5f:ed:01:d1:3c:51:8b:e2:6c: + 31:d7:6b:a5:bd:05:e3:9a:97:15:40:bf:bb:8f:81:e5:bf:bc: + 06:66:47:84:fe:f7:06:fb:5d:35:9e:04:26:0d:aa:3d:b5:92: + 6b:90:c2:1c:17:ac:c1:95:d9:6b:f1:5d:0a:09:9f:a7:a6:ca: + 3b:45:a4:59 +-----BEGIN CERTIFICATE----- +MIIDHzCCAgegAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwPzEfMB0GA1UECgwWbmdp +bngtcHJveHkgdGVzdCBzdWl0ZTEcMBoGA1UEAwwTd3d3Lm5naW54LXByb3h5LnRs +ZDAeFw0yMTA1MTExODI1NDlaFw00ODA5MjYxODI1NDlaMDAxLjAsBgNVBAMMJXdl +Yi1zZXJ2ZXItdG9rZW5zLW9mZi5uZ2lueC1wcm94eS50bGQwggEiMA0GCSqGSIb3 +DQEBAQUAA4IBDwAwggEKAoIBAQC0+p2KdD8X6pkcRXEYkOuSNTjXkCGBCpEFQc+1 +hzS92Ht/fQYz+JRnjuQHVH+3YsV2bH98GSUZLDaaJlSOLZcCeDHGE9Ot8zFi5s+W +rmM33b1zy077P5tlZ5fYWl0OcrERqw7XI6m3It4jdH6IfCiYqW4A9L6Maeo/M4sZ +l9obpmW1WpIBPDoTawAC4Zh409rqppwzsB2fAsTx0NbeevdCEksx++3p19gV6E4Y +kXydvw+wEtbigIt67xdwUfQ8t0PLVmGvYXpOnWxe2CcMO9ekHS8NoJmPtXGTIbSH +vrQcd6C5zZG9nNC5gVASY9IKqWEFkRkn9+qdjkhlLhrn/fG3AgMBAAGjNDAyMDAG +A1UdEQQpMCeCJXdlYi1zZXJ2ZXItdG9rZW5zLW9mZi5uZ2lueC1wcm94eS50bGQw +DQYJKoZIhvcNAQELBQADggEBAFu3dK0HCGU8jgJQqbb0jUeVb+C6WoyuXDKIi0UE +SM49ckXXfh7XdRcwmJAhTGfiVx3J+gP0gWTP0rOFcb5TuSr9iQSmsYgKCvFck5v7 +T4YOxU1q/1R7B/F+0Ypr+jvzXNIbLIYFTOC0BA3H2wuJtDMJthrwy9SuLAVjpBgZ +UscVIayunhW5sFgMlt97d0bvWaeWVtr29oGfEH1aSGgMKAJde2lNiUHiiG3GIkVq +NBu6m2/WLcJVsXO0u/UG1l/tAdE8UYvibDHXa6W9BeOalxVAv7uPgeW/vAZmR4T+ +9wb7XTWeBCYNqj21kmuQwhwXrMGV2WvxXQoJn6emyjtFpFk= +-----END CERTIFICATE----- diff --git a/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.key b/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.key new file mode 100644 index 0000000..4e87ba8 --- /dev/null +++ b/test/test_headers/certs/web-server-tokens-off.nginx-proxy.tld.key @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEowIBAAKCAQEAtPqdinQ/F+qZHEVxGJDrkjU415AhgQqRBUHPtYc0vdh7f30G +M/iUZ47kB1R/t2LFdmx/fBklGSw2miZUji2XAngxxhPTrfMxYubPlq5jN929c8tO ++z+bZWeX2FpdDnKxEasO1yOptyLeI3R+iHwomKluAPS+jGnqPzOLGZfaG6ZltVqS +ATw6E2sAAuGYeNPa6qacM7AdnwLE8dDW3nr3QhJLMfvt6dfYFehOGJF8nb8PsBLW +4oCLeu8XcFH0PLdDy1Zhr2F6Tp1sXtgnDDvXpB0vDaCZj7VxkyG0h760HHeguc2R +vZzQuYFQEmPSCqlhBZEZJ/fqnY5IZS4a5/3xtwIDAQABAoIBAAaBi/BSRYJimKZ/ +iJVNgGp9J1H4iHvPGW+K8iCgf7Dje20V3Yc4xH0EkgYBb6X0Ew0y0VJwxPimsj/Q +aPHDic446/Em/VEfkQLxMT1Ff6OegRUMlgZKPxfiJX9NoFLIpLzx3VK2oX9H7Zxw +r6vQatUyIhY+tiruE9G51KJS5zBfN388ErfRUI8ByBaDGH0huA6kTBcNffhCfZr5 +9naWSIIcuBe8v7z6nAaeYL00q1q3vuWPmuQduSgsmef7QuN71CIxuOAqXTJl8koS +LYNbj8yvIy3nOF90D+uZD/Pa2Y0kB6aum09hbUP15K0QFKulbKLRQ60IuvRcw3Qv +MM177OECgYEA5Rw3qUcoTDfsx+nu2BxECj62uyNVZfX/QMf7dvzCqjXuOhij+KBB +U9xnNfuLc4HfCXx/rMg5dGExEBbD2iHAo0nvnCSxzLJmF6i66Uves0VWISXcv2Au +L0TWMhhsbDFoqkWuxXr69oNwKyl9yFRFWEY3p3G+aBAEqWZ1lOkU8O0CgYEAyjhC +bN4mJJYhvX+cXhv+89Z+JIDAvtvQ5Vy7kxvhQUTx2By6rWKKrBPdTnzsxBGKqQwv +lXzfgj/MlIr6A6QDReGwU3ZXTJqSGEuT8Ra9SbjczQgaGOrPCrWhnbeZ18iM67pJ +LPfLgdRdkh3XgbOOKcDhpg2KybbbyXx6Q2xb7LMCgYEAzKHKWUh0BreApgIcUSvV +3ayr+zOQ5/Oy24KC6IDTwcFPmNY/RiakkqluCfo1UKKzuj5XrtRa9MaGUs9yeJbi +/zVfbQAdSi4hH4qV/x/Dtiz8w7iUlN3sAk4iXjYQSQZMbKC2fC3ej2VQP0zcypvy +H+j/dnASV9HOyBr6dFlGWfUCgYB3gfYntsXd+2fnQOJdb7glzM5xrjG62dfDpSEp +mGFwHFm8+YWNcF45weeZOhUG7sL+krgQZWMF68RwyQ1mV2ijxPRa7uY63GKYvxmo +cmLdjcXX2gDqVuKTFrJzrgzaTKiTq10RmUQI70N5Ve+FtGLA5D+2zewGt+1+TvVG +oWRWJwKBgAUpJ/NXOB82ie9RtwfAeuiD0yDPM3gNFVe0udAyG/71nXyHiW5aHn/w +H+QSliw7gqir4u6bcrprFQMcwiowtCfeDkcXoQCOBx6TvL2zZTrG7J/68yDHfHGg +w3eFN7ac8FsliRpT+UVKM97zJXcWFkai5Q+R7oKsWXRVXQUZZxg9 +-----END RSA PRIVATE KEY----- diff --git a/test/test_headers/test_http.py b/test/test_headers/test_http.py index 2799262..5983a10 100644 --- a/test/test_headers/test_http.py +++ b/test/test_headers/test_http.py @@ -1,5 +1,3 @@ -import pytest - def test_arbitrary_headers_are_passed_on(docker_compose, nginxproxy): r = nginxproxy.get("http://web.nginx-proxy.tld/headers", headers={'Foo': 'Bar'}) assert r.status_code == 200 @@ -78,4 +76,24 @@ def test_httpoxy_safe(docker_compose, nginxproxy): r = nginxproxy.get("http://web.nginx-proxy.tld/headers", headers={'Proxy': 'tcp://some.hacker.com'}) assert r.status_code == 200 assert "Proxy:" not in r.text - + + +def test_no_host_server_tokens_off(docker_compose, nginxproxy): + ip = nginxproxy.get_ip() + r = nginxproxy.get(f"http://{ip}/headers") + assert r.status_code == 503 + assert r.headers["Server"] == "nginx" + + +def test_server_tokens_on(docker_compose, nginxproxy): + r = nginxproxy.get("http://web.nginx-proxy.tld/headers") + assert r.status_code == 200 + assert "Host: web.nginx-proxy.tld" in r.text + assert r.headers["Server"].startswith("nginx/") + + +def test_server_tokens_off(docker_compose, nginxproxy): + r = nginxproxy.get("http://web-server-tokens-off.nginx-proxy.tld/headers") + assert r.status_code == 200 + assert "Host: web-server-tokens-off.nginx-proxy.tld" in r.text + assert r.headers["Server"] == "nginx" diff --git a/test/test_headers/test_http.yml b/test/test_headers/test_http.yml index f8069c6..0e3880d 100644 --- a/test/test_headers/test_http.yml +++ b/test/test_headers/test_http.yml @@ -6,6 +6,15 @@ web: WEB_PORTS: 80 VIRTUAL_HOST: web.nginx-proxy.tld +web-server-tokens-off: + image: web + expose: + - "80" + environment: + WEB_PORTS: 80 + VIRTUAL_HOST: web-server-tokens-off.nginx-proxy.tld + SERVER_TOKENS: "off" + sut: image: nginxproxy/nginx-proxy:test diff --git a/test/test_headers/test_https.py b/test/test_headers/test_https.py index a1d434a..9aa967a 100644 --- a/test/test_headers/test_https.py +++ b/test/test_headers/test_https.py @@ -1,6 +1,3 @@ -import pytest - - def test_arbitrary_headers_are_passed_on(docker_compose, nginxproxy): r = nginxproxy.get("https://web.nginx-proxy.tld/headers", headers={'Foo': 'Bar'}) assert r.status_code == 200 @@ -79,4 +76,24 @@ def test_httpoxy_safe(docker_compose, nginxproxy): r = nginxproxy.get("https://web.nginx-proxy.tld/headers", headers={'Proxy': 'tcp://some.hacker.com'}) assert r.status_code == 200 assert "Proxy:" not in r.text - + + +def test_no_host_server_tokens_off(docker_compose, nginxproxy): + ip = nginxproxy.get_ip() + r = nginxproxy.get(f"https://{ip}/headers", verify=False) + assert r.status_code == 503 + assert r.headers["Server"] == "nginx" + + +def test_server_tokens_on(docker_compose, nginxproxy): + r = nginxproxy.get("https://web.nginx-proxy.tld/headers", verify=False) + assert r.status_code == 200 + assert "Host: web.nginx-proxy.tld" in r.text + assert r.headers["Server"].startswith("nginx/") + + +def test_server_tokens_off(docker_compose, nginxproxy): + r = nginxproxy.get("https://web-server-tokens-off.nginx-proxy.tld/headers") + assert r.status_code == 200 + assert "Host: web-server-tokens-off.nginx-proxy.tld" in r.text + assert r.headers["Server"] == "nginx" diff --git a/test/test_headers/test_https.yml b/test/test_headers/test_https.yml index 406e433..c0c67b4 100644 --- a/test/test_headers/test_https.yml +++ b/test/test_headers/test_https.yml @@ -6,11 +6,24 @@ web: WEB_PORTS: 80 VIRTUAL_HOST: web.nginx-proxy.tld +web-server-tokens-off: + image: web + expose: + - "80" + environment: + WEB_PORTS: 80 + VIRTUAL_HOST: web-server-tokens-off.nginx-proxy.tld + SERVER_TOKENS: "off" + sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs/web.nginx-proxy.tld.crt:/etc/nginx/certs/default.crt:ro + - ./certs/web.nginx-proxy.tld.key:/etc/nginx/certs/default.key:ro - ./certs/web.nginx-proxy.tld.crt:/etc/nginx/certs/web.nginx-proxy.tld.crt:ro - ./certs/web.nginx-proxy.tld.key:/etc/nginx/certs/web.nginx-proxy.tld.key:ro + - ./certs/web-server-tokens-off.nginx-proxy.tld.crt:/etc/nginx/certs/web-server-tokens-off.nginx-proxy.tld.crt:ro + - ./certs/web-server-tokens-off.nginx-proxy.tld.key:/etc/nginx/certs/web-server-tokens-off.nginx-proxy.tld.key:ro - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From 97a5dec57a6e33a3d4dd93ab22a52c0fffcc0872 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 28 May 2021 00:04:43 +0200 Subject: [PATCH 053/126] Honor VIRTUAL_PORT + DEBUG flag + fallback entry The VIRTUAL_PORT environment variable should always be honored. Even when the related port is not exposed. Fix for nging-proxy/nginx-proxy#1132. This commit also add the DEBUG environment variable which enables more verbose comments in the nginx comfiguration file to help troubleshooting unreachable containers. Finaly it fixes nging-proxy/nginx-proxy#1105 as well by defining only one fallback entry per upstream block. --- README.md | 45 ++++++++++++++++++++++++++++++++++++++------- nginx.tmpl | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 9b13463..a03b5e2 100644 --- a/README.md +++ b/README.md @@ -82,17 +82,21 @@ NginX does not support scoped IPv6 resolvers. In [docker-entrypoint.sh](./docker By default, docker uses IPv6-to-IPv4 NAT. This means all client connections from IPv6 addresses will show docker's internal IPv4 host address. To see true IPv6 client IP addresses, you must [enable IPv6](https://docs.docker.com/config/daemon/ipv6/) and use [ipv6nat](https://github.com/robbertkl/docker-ipv6nat). You must also disable the userland proxy by adding `"userland-proxy": false` to `/etc/docker/daemon.json` and restarting the daemon. -### Multiple Ports - -If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected. - - [1]: https://github.com/jwilder/docker-gen - [2]: http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/ - ### Multiple Hosts If you need to support multiple virtual hosts for a container, you can separate each entry with commas. For example, `foo.bar.com,baz.bar.com,bar.com` and each host will be setup the same. +### Virtual Ports + +When your container exposes only one port, nginx-proxy will default to this port, else to port 80. + +If you need to specify a different port, you can set a `VIRTUAL_PORT` env var to select a different one. This variable cannot be set to more than one port. + +For each host defined into `VIRTUAL_HOST`, the associated virtual port is retrieved by order of precedence: +1. From the `VIRTUAL_PORT` environment variable +1. From the container's exposed port if there is only one +1. From the default port 80 when none of the above methods apply + ### Wildcard Hosts You can also use wildcards at the beginning and the end of host name, like `*.bar.com` or `foo.bar.*`. Or even a regular expression, which can be very useful in conjunction with a wildcard DNS service like [xip.io](http://xip.io), using `~^foo\.bar\..*\.xip\.io` will match `foo.bar.127.0.0.1.xip.io`, `foo.bar.10.0.2.2.xip.io` and all other given IPs. More information about this topic can be found in the nginx documentation about [`server_names`](http://nginx.org/en/docs/http/server_names.html). @@ -424,6 +428,33 @@ will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRT #### Per-VIRTUAL_HOST `server_tokens` configuration Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details. +### Troubleshooting + +In case you can't access your VIRTUAL_HOST, set `DEBUG=true` in the client container's environment and have a look at the generated nginx configuration file `/etc/nginx/conf.d/default`: + +``` +$ docker exec cat /etc/nginx/conf.d/default +``` +Especially at `upstream` definition blocks which should look like: + +``` +# foo.example.com +upstream foo.example.com { + ## Can be connected with "my_network" network + # Exposed ports: [{ tcp } { tcp } ...] + # Default virtual port: + # VIRTUAL_PORT: + # foo + server 172.18.0.9:; + # Fallback entry + server 127.0.0.1 down; +} +``` + +The effective `Port` is retrieved by order of precedence: +1. From the `VIRTUAL_PORT` environment variable +1. From the container's exposed port if there is only one +1. From the default port 80 when none of the above methods apply ### Contributing diff --git a/nginx.tmpl b/nginx.tmpl index 9d90241..66f346c 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -2,24 +2,25 @@ {{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }} {{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }} +{{ $debug_all := $.Env.DEBUG }} {{ define "upstream" }} {{ if .Address }} {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}} {{ if and .Container.Node.ID .Address.HostPort }} - # {{ .Container.Node.Name }}/{{ .Container.Name }} + # {{ .Container.Node.Name }}/{{ .Container.Name }} server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }}; {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} {{ else if .Network }} - # {{ .Container.Name }} - server {{ .Network.IP }}:{{ .Address.Port }}; + # {{ .Container.Name }} + server {{ .Network.IP }}:{{ .Address.Port }}; {{ end }} {{ else if .Network }} - # {{ .Container.Name }} + # {{ .Container.Name }} {{ if .Network.IP }} - server {{ .Network.IP }} down; + server {{ .Network.IP }}:{{ .VirtualPort }}; {{ else }} - server 127.0.0.1 down; + # /!\ No IP for this network! {{ end }} {{ end }} @@ -180,29 +181,32 @@ server { upstream {{ $upstream_name }} { {{ range $container := $containers }} - {{ $addrLen := len $container.Addresses }} - + {{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }} + {{/* If only 1 port exposed, use that as a default, else 80 */}} + {{ $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }} {{ range $knownNetwork := $CurrentContainer.Networks }} {{ range $containerNetwork := $container.Networks }} {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} - ## Can be connected with "{{ $containerNetwork.Name }}" network - - {{/* If only 1 port exposed, use that */}} - {{ if eq $addrLen 1 }} - {{ $address := index $container.Addresses 0 }} - {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} - {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}} - {{ else }} - {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }} - {{ $address := where $container.Addresses "Port" $port | first }} - {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} + ## Can be connected with "{{ $containerNetwork.Name }}" network + {{ $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }} + {{ $address := where $container.Addresses "Port" $port | first }} + {{ if $debug }} + # Exposed ports: {{ $container.Addresses }} + # Default virtual port: {{ $defaultPort }} + # VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }} + {{ if not $address }} + # /!\ Virtual port not exposed + {{ end }} {{ end }} + {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork "VirtualPort" $port) }} {{ else }} - # Cannot connect to network of this container - server 127.0.0.1 down; + # Cannot connect to network '{{ $containerNetwork.Name }}' of this container {{ end }} {{ end }} {{ end }} + {{/* nginx-proxy/nginx-proxy#1105 */}} + # Fallback entry + server 127.0.0.1 down; {{ end }} } From 3785649eb60f2f6fc6f793ae66edc15737b2a539 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 28 May 2021 00:03:43 +0200 Subject: [PATCH 054/126] test: VIRTUAL_PORT != single exposed port --- ...TUAL_PORT-single-different-from-single-port.py | 8 ++++++++ ...UAL_PORT-single-different-from-single-port.yml | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.py create mode 100644 test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml diff --git a/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.py b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.py new file mode 100644 index 0000000..4008166 --- /dev/null +++ b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.py @@ -0,0 +1,8 @@ +import pytest +import re + + +def test_answer_is_served_from_virtual_port_which_is_ureachable(docker_compose, nginxproxy): + r = nginxproxy.get("http://web.nginx-proxy.tld/port") + assert r.status_code == 502 + assert re.search(r"\n\s+server \d+\.\d+\.\d+\.\d+:90;\n", nginxproxy.get_conf().decode('ASCII')) diff --git a/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml new file mode 100644 index 0000000..e28a481 --- /dev/null +++ b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml @@ -0,0 +1,15 @@ +web: + image: web + expose: + - "81" + environment: + WEB_PORTS: "81" + VIRTUAL_HOST: "web.nginx-proxy.tld" + VIRTUAL_PORT: "90" + + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From 2bb53bd303765159abfa24a57fe96f41459c9e65 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 28 May 2021 01:52:01 +0200 Subject: [PATCH 055/126] test: add tests for the DEBUG flag --- test/test_debug/test_proxy-debug-flag.py | 12 ++++++++++ test/test_debug/test_proxy-debug-flag.yml | 27 ++++++++++++++++++++++ test/test_debug/test_server-debug-flag.py | 8 +++++++ test/test_debug/test_server-debug-flag.yml | 26 +++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 test/test_debug/test_proxy-debug-flag.py create mode 100644 test/test_debug/test_proxy-debug-flag.yml create mode 100644 test/test_debug/test_server-debug-flag.py create mode 100644 test/test_debug/test_server-debug-flag.yml diff --git a/test/test_debug/test_proxy-debug-flag.py b/test/test_debug/test_proxy-debug-flag.py new file mode 100644 index 0000000..b99ccef --- /dev/null +++ b/test/test_debug/test_proxy-debug-flag.py @@ -0,0 +1,12 @@ +import pytest +import re + +def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \}\]", conf) or \ + re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \}\]", conf) + assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+82\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+83\s+tcp \}\]", conf) or \ + re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+83\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+82\s+tcp \}\]", conf) + assert "# Default virtual port: 80" in conf + assert "# VIRTUAL_PORT: 82" in conf + assert conf.count("# /!\ Virtual port not exposed") == 1 diff --git a/test/test_debug/test_proxy-debug-flag.yml b/test/test_debug/test_proxy-debug-flag.yml new file mode 100644 index 0000000..e7af54c --- /dev/null +++ b/test/test_debug/test_proxy-debug-flag.yml @@ -0,0 +1,27 @@ +web1: + image: web + expose: + - "80" + - "81" + environment: + WEB_PORTS: "80 81" + VIRTUAL_HOST: "web1.nginx-proxy.tld" + VIRTUAL_PORT: "82" + +web2: + image: web + expose: + - "82" + - "83" + environment: + WEB_PORTS: "82 83" + VIRTUAL_HOST: "web2.nginx-proxy.tld" + VIRTUAL_PORT: "82" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + environment: + DEBUG: "true" diff --git a/test/test_debug/test_server-debug-flag.py b/test/test_debug/test_server-debug-flag.py new file mode 100644 index 0000000..50ae737 --- /dev/null +++ b/test/test_debug/test_server-debug-flag.py @@ -0,0 +1,8 @@ +import pytest +import re + +def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + assert re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \}\]", conf) or \ + re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+81\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+80\s+tcp \}\]", conf) + assert conf.count("# Exposed ports: [{") == 1 diff --git a/test/test_debug/test_server-debug-flag.yml b/test/test_debug/test_server-debug-flag.yml new file mode 100644 index 0000000..0256cf8 --- /dev/null +++ b/test/test_debug/test_server-debug-flag.yml @@ -0,0 +1,26 @@ +web1: + image: web + expose: + - "80" + - "81" + environment: + WEB_PORTS: "80 81" + VIRTUAL_HOST: "web1.nginx-proxy.tld" + VIRTUAL_PORT: "82" + DEBUG: "true" + +web2: + image: web + expose: + - "82" + - "83" + environment: + WEB_PORTS: "82 83" + VIRTUAL_HOST: "web2.nginx-proxy.tld" + VIRTUAL_PORT: "82" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From 242caf9e695137aa6291707eba3dbb8077fb7dd9 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 27 Apr 2021 00:56:47 +0200 Subject: [PATCH 056/126] chore: switch to go mod compatible fork of forego --- Dockerfile | 25 +++++++++++-------------- Dockerfile.alpine | 27 ++++++++++++--------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index 83253c5..918e591 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ # setup build arguments for version of dependencies to use ARG DOCKER_GEN_VERSION=0.7.6 -ARG FOREGO_VERSION=0.16.1 +ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries FROM golang:1.15.10 as gobuilder @@ -21,22 +21,19 @@ RUN git clone https://github.com/jwilder/docker-gen \ && rm -rf /go/docker-gen # Build forego from scratch -# Because this relies on golang workspaces, we need to use go < 1.8. FROM gobuilder as forego -# Download the sources for the given version ARG FOREGO_VERSION -ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz -# Move the sources into the right directory -RUN tar -xzf sources.tar.gz && \ - mkdir -p /go/src/github.com/ddollar/ && \ - mv forego-* /go/src/github.com/ddollar/forego - -# Install the dependencies and make the forego executable -WORKDIR /go/src/github.com/ddollar/forego/ -RUN go get -v ./... && \ - CGO_ENABLED=0 GOOS=linux go build -o forego . +RUN git clone https://github.com/nginx-proxy/forego/ \ + && cd /go/forego \ + && git -c advice.detachedHead=false checkout $FOREGO_VERSION \ + && go mod download \ + && CGO_ENABLED=0 GOOS=linux go build -o forego . \ + && go clean -cache \ + && mv forego /usr/local/bin/ \ + && cd - \ + && rm -rf /go/forego # Build the final image FROM nginx:1.19.3 @@ -56,7 +53,7 @@ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf # Install Forego + docker-gen -COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego +COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen # Add DOCKER_GEN_VERSION environment variable diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 5de844c..e219cb9 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,10 +1,10 @@ # setup build arguments for version of dependencies to use ARG DOCKER_GEN_VERSION=0.7.6 -ARG FOREGO_VERSION=0.16.1 +ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries FROM golang:1.15.10-alpine as gobuilder -RUN apk add --no-cache git +RUN apk add --no-cache git musl-dev # Build docker-gen from scratch FROM gobuilder as dockergen @@ -24,19 +24,17 @@ RUN git clone https://github.com/jwilder/docker-gen \ # Build forego from scratch FROM gobuilder as forego -# Download the sources for the given version ARG FOREGO_VERSION -ADD https://github.com/jwilder/forego/archive/v${FOREGO_VERSION}.tar.gz sources.tar.gz -# Move the sources into the right directory -RUN tar -xzf sources.tar.gz && \ - mkdir -p /go/src/github.com/ddollar/ && \ - mv forego-* /go/src/github.com/ddollar/forego - -# Install the dependencies and make the forego executable -WORKDIR /go/src/github.com/ddollar/forego/ -RUN go get -v ./... && \ - CGO_ENABLED=0 GOOS=linux go build -o forego . +RUN git clone https://github.com/nginx-proxy/forego/ \ + && cd /go/forego \ + && git -c advice.detachedHead=false checkout $FOREGO_VERSION \ + && go mod download \ + && CGO_ENABLED=0 go build -o forego . \ + && go clean -cache \ + && mv forego /usr/local/bin/ \ + && cd - \ + && rm -rf /go/forego # Build the final image FROM nginx:1.19.3-alpine @@ -47,13 +45,12 @@ RUN apk add --no-cache --virtual .run-deps \ ca-certificates bash wget openssl \ && update-ca-certificates - # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf # Install Forego + docker-gen -COPY --from=forego /go/src/github.com/ddollar/forego/forego /usr/local/bin/forego +COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen # Add DOCKER_GEN_VERSION environment variable From ae5623916b06d09e8c552779f40af0c752fd90db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Jun 2021 23:28:15 +0000 Subject: [PATCH 057/126] chore(deps): bump nginx from 1.19.10 to 1.21.0 Bumps nginx from 1.19.10 to 1.21.0. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 03b5bf1..3c78ba0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.19.10 +FROM nginx:1.21.0 LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 4214baa..9277300 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -37,7 +37,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.19.10-alpine +FROM nginx:1.21.0-alpine LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates From 1967ca2a57bd6032bb50f70148ad3da3c1a18b38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Jun 2021 23:28:24 +0000 Subject: [PATCH 058/126] chore(deps): bump golang from 1.15.10 to 1.16.5 Bumps golang from 1.15.10 to 1.16.5. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 03b5bf1..5813c52 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.15.10 as gobuilder +FROM golang:1.16.5 as gobuilder # Build docker-gen from scratch FROM gobuilder as dockergen diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 4214baa..c6a04e3 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.15.10-alpine as gobuilder +FROM golang:1.16.5-alpine as gobuilder RUN apk add --no-cache git musl-dev # Build docker-gen from scratch From 9f069a42ac44e7e166d26e652c677050c4c01cea Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Wed, 9 Jun 2021 20:51:08 +0100 Subject: [PATCH 059/126] Improve logging Currently its almost impossible to know which host actually handled the request, this extra variable logs the upstream server too --- nginx.tmpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index 66f346c..a4adcfa 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -108,7 +108,8 @@ gzip_types text/plain text/css application/javascript application/json applicati log_format vhost '$host $remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' - '"$http_referer" "$http_user_agent"'; + '"$http_referer" "$http_user_agent" ' + '"$upstream_addr"'; access_log off; From e9ab13781dfaea38c18ef405b1e081f5c5940700 Mon Sep 17 00:00:00 2001 From: Scott Dutton Date: Wed, 9 Jun 2021 20:51:51 +0100 Subject: [PATCH 060/126] Fix spacing --- nginx.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index a4adcfa..1dfbaba 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -109,7 +109,7 @@ gzip_types text/plain text/css application/javascript application/json applicati log_format vhost '$host $remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' - '"$upstream_addr"'; + '"$upstream_addr"'; access_log off; From b9e301d76927041b26966576685bf2d6cd3ea554 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 14 Jun 2021 15:17:23 +0200 Subject: [PATCH 061/126] docs: update nginx version badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a03b5e2..c596e1a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) [![GitHub release](https://img.shields.io/github/v/release/nginx-proxy/nginx-proxy)](https://github.com/nginx-proxy/nginx-proxy/releases) -![nginx 1.19.10](https://img.shields.io/badge/nginx-1.19.10-brightgreen.svg) +![nginx 1.21.0](https://img.shields.io/badge/nginx-1.21.0-brightgreen.svg) [![Docker Image Size](https://img.shields.io/docker/image-size/nginxproxy/nginx-proxy?sort=semver)](https://hub.docker.com/r/nginxproxy/nginx-proxy "Click to view the image on Docker Hub") [![Docker stars](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![Docker pulls](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') From d1cf6b57d7bc1637b83aba03e52352a02037d1d9 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 15 Jun 2021 00:00:50 +0200 Subject: [PATCH 062/126] docs: custom external HTTP/HTTPS ports --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index c596e1a..5e12190 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,12 @@ $ docker network connect my-other-network my-nginx-proxy In this example, the `my-nginx-proxy` container will be connected to `my-network` and `my-other-network` and will be able to proxy to other containers attached to those networks. +### Custom external HTTP/HTTPS ports + +If you want to use `nginx-proxy` with different external ports that the default ones of `80` for `HTTP` traffic and `443` for `HTTPS` traffic, you'll have to use the environment variable(s) `HTTP_PORT` and/or `HTTPS_PORT` in addition to the changes to the Docker port mapping. Typical usage, here with the custom ports `1080` and `10443`: + + $ docker run -d -p 1080:1080 -p 10443:10443 -e HTTP_PORT=1080 -e HTTPS_PORT=10443 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy + ### Internet vs. Local Network Access If you allow traffic from the public internet to access your `nginx-proxy` container, you may want to restrict some containers to the internal network only, so they cannot be accessed from the public internet. On containers that should be restricted to the internal network, you should set the environment variable `NETWORK_ACCESS=internal`. By default, the *internal* network is defined as `127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16`. To change the list of networks considered internal, mount a file on the `nginx-proxy` at `/etc/nginx/network_internal.conf` with these contents, edited to suit your needs: From 6bb7c376059e5bbd63d8c111316dbac44cf1a2e7 Mon Sep 17 00:00:00 2001 From: John Stucklen Date: Tue, 15 Jun 2021 00:13:06 +0200 Subject: [PATCH 063/126] test: custom HTTP port --- test/test_http_port.py | 8 ++++++++ test/test_http_port.yml | 15 +++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/test_http_port.py create mode 100644 test/test_http_port.yml diff --git a/test/test_http_port.py b/test/test_http_port.py new file mode 100644 index 0000000..26302c5 --- /dev/null +++ b/test/test_http_port.py @@ -0,0 +1,8 @@ +import pytest + + +@pytest.mark.parametrize("subdomain", ["foo", "bar"]) +def test_web1_http_custom_port(docker_compose, nginxproxy, subdomain): + r = nginxproxy.get("http://%s.nginx-proxy.tld:8080/port" % subdomain, allow_redirects=False) + assert r.status_code == 200 + assert "answer from port 81\n" in r.text \ No newline at end of file diff --git a/test/test_http_port.yml b/test/test_http_port.yml new file mode 100644 index 0000000..a7fa0eb --- /dev/null +++ b/test/test_http_port.yml @@ -0,0 +1,15 @@ +web1: + image: web + expose: + - "81" + environment: + WEB_PORTS: "81" + VIRTUAL_HOST: "*.nginx-proxy.tld" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + environment: + HTTP_PORT: 8080 \ No newline at end of file From fa8b0d7bad7727dd115c356a0f96f6e3c7af1a6e Mon Sep 17 00:00:00 2001 From: John Stucklen Date: Tue, 15 Jun 2021 00:22:17 +0200 Subject: [PATCH 064/126] fix: HTTPS redirection with custom HTTPS port --- README.md | 2 +- nginx.tmpl | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e12190..8d007d2 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ In this example, the `my-nginx-proxy` container will be connected to `my-network ### Custom external HTTP/HTTPS ports -If you want to use `nginx-proxy` with different external ports that the default ones of `80` for `HTTP` traffic and `443` for `HTTPS` traffic, you'll have to use the environment variable(s) `HTTP_PORT` and/or `HTTPS_PORT` in addition to the changes to the Docker port mapping. Typical usage, here with the custom ports `1080` and `10443`: +If you want to use `nginx-proxy` with different external ports that the default ones of `80` for `HTTP` traffic and `443` for `HTTPS` traffic, you'll have to use the environment variable(s) `HTTP_PORT` and/or `HTTPS_PORT` in addition to the changes to the Docker port mapping. If you change the `HTTPS` port, the redirect for `HTTPS` traffic will also be configured to redirect to the custom port. Typical usage, here with the custom ports `1080` and `10443`: $ docker run -d -p 1080:1080 -p 10443:10443 -e HTTP_PORT=1080 -e HTTPS_PORT=10443 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy diff --git a/nginx.tmpl b/nginx.tmpl index 1dfbaba..ce55b72 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -276,7 +276,11 @@ server { } location / { + {{ if eq $external_https_port "443" }} return 301 https://$host$request_uri; + {{ else }} + return 301 https://$host:{{ $external_https_port }}$request_uri; + {{ end }} } } {{ end }} From 790785f1abdf8076913cbdb894ca06a7cb0f94de Mon Sep 17 00:00:00 2001 From: John Stucklen Date: Tue, 15 Jun 2021 00:38:32 +0200 Subject: [PATCH 065/126] test: custom HTTPS port and redirection --- test/test_ssl/test_https_port.py | 14 ++++++++++++++ test/test_ssl/test_https_port.yml | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/test_ssl/test_https_port.py create mode 100644 test/test_ssl/test_https_port.yml diff --git a/test/test_ssl/test_https_port.py b/test/test_ssl/test_https_port.py new file mode 100644 index 0000000..214d4d9 --- /dev/null +++ b/test/test_ssl/test_https_port.py @@ -0,0 +1,14 @@ +import pytest + +@pytest.mark.parametrize("subdomain", ["foo", "bar"]) +def test_web1_http_redirects_to_https(docker_compose, nginxproxy, subdomain): + r = nginxproxy.get("http://%s.nginx-proxy.tld:8080/" % subdomain, allow_redirects=False) + assert r.status_code == 301 + assert "Location" in r.headers + assert "https://%s.nginx-proxy.tld:8443/" % subdomain == r.headers['Location'] + +@pytest.mark.parametrize("subdomain", ["foo", "bar"]) +def test_web1_https_is_forwarded(docker_compose, nginxproxy, subdomain): + r = nginxproxy.get("https://%s.nginx-proxy.tld:8443/port" % subdomain, allow_redirects=False) + assert r.status_code == 200 + assert "answer from port 81\n" in r.text \ No newline at end of file diff --git a/test/test_ssl/test_https_port.yml b/test/test_ssl/test_https_port.yml new file mode 100644 index 0000000..adcf2a8 --- /dev/null +++ b/test/test_ssl/test_https_port.yml @@ -0,0 +1,17 @@ +web1: + image: web + expose: + - "81" + environment: + WEB_PORTS: "81" + VIRTUAL_HOST: "*.nginx-proxy.tld" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + - ./certs:/etc/nginx/certs:ro + environment: + HTTP_PORT: 8080 + HTTPS_PORT: 8443 \ No newline at end of file From 84ae8355825d57dfe1e6bf8ff1388a4d3b5ae82b Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 15 Jun 2021 00:51:00 +0200 Subject: [PATCH 066/126] docs: fix markdown link error --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8d007d2..19ae9c0 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ [![Docker pulls](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') -nginx-proxy sets up a container running nginx and [docker-gen][1]. docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. +nginx-proxy sets up a container running nginx and [docker-gen](https://github.com/nginx-proxy/docker-gen). docker-gen generates reverse proxy configs for nginx and reloads nginx when containers are started and stopped. -See [Automated Nginx Reverse Proxy for Docker][2] for why you might want to use this. +See [Automated Nginx Reverse Proxy for Docker](http://jasonwilder.com/blog/2014/03/25/automated-nginx-reverse-proxy-for-docker/) for why you might want to use this. ### Usage From 98fe68432ac4c7f6edcd49102c8c0057d9365952 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 15 Jun 2021 23:32:38 +0200 Subject: [PATCH 067/126] ci: update Dependabot labels --- .github/dependabot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d99307f..f826c1d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,5 @@ updates: schedule: interval: "daily" labels: - - "area/chore" - - "area/dockerfile" + - "type/build" + - "scope/dockerfile" From fca248a9655c40bbf46ed6d0a009734d15f4045b Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Tue, 15 Jun 2021 23:54:24 +0200 Subject: [PATCH 068/126] fix: server 127.0.0.1 down entry only when required --- nginx.tmpl | 63 ++++++++++--------- test/test_server-down/test_no-server-down.py | 8 +++ test/test_server-down/test_no-server-down.yml | 13 ++++ test/test_server-down/test_server-down.py | 7 +++ test/test_server-down/test_server-down.yml | 14 +++++ 5 files changed, 74 insertions(+), 31 deletions(-) create mode 100644 test/test_server-down/test_no-server-down.py create mode 100644 test/test_server-down/test_no-server-down.yml create mode 100644 test/test_server-down/test_server-down.py create mode 100644 test/test_server-down/test_server-down.yml diff --git a/nginx.tmpl b/nginx.tmpl index 66f346c..ac36967 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -4,28 +4,6 @@ {{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }} {{ $debug_all := $.Env.DEBUG }} -{{ define "upstream" }} - {{ if .Address }} - {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}} - {{ if and .Container.Node.ID .Address.HostPort }} - # {{ .Container.Node.Name }}/{{ .Container.Name }} - server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }}; - {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} - {{ else if .Network }} - # {{ .Container.Name }} - server {{ .Network.IP }}:{{ .Address.Port }}; - {{ end }} - {{ else if .Network }} - # {{ .Container.Name }} - {{ if .Network.IP }} - server {{ .Network.IP }}:{{ .VirtualPort }}; - {{ else }} - # /!\ No IP for this network! - {{ end }} - {{ end }} - -{{ end }} - {{ define "ssl_policy" }} {{ if eq .ssl_policy "Mozilla-Modern" }} ssl_protocols TLSv1.3; @@ -184,29 +162,52 @@ upstream {{ $upstream_name }} { {{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }} {{/* If only 1 port exposed, use that as a default, else 80 */}} {{ $defaultPort := (when (eq (len $container.Addresses) 1) (first $container.Addresses) (dict "Port" "80")).Port }} + {{ $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }} + {{ $address := where $container.Addresses "Port" $port | first }} + {{ if $debug }} + # Exposed ports: {{ $container.Addresses }} + # Default virtual port: {{ $defaultPort }} + # VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }} + {{ if not $address }} + # /!\ Virtual port not exposed + {{ end }} + {{ end }} + {{ $server_found := "false" }} {{ range $knownNetwork := $CurrentContainer.Networks }} {{ range $containerNetwork := $container.Networks }} {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} ## Can be connected with "{{ $containerNetwork.Name }}" network - {{ $port := (coalesce $container.Env.VIRTUAL_PORT $defaultPort) }} - {{ $address := where $container.Addresses "Port" $port | first }} - {{ if $debug }} - # Exposed ports: {{ $container.Addresses }} - # Default virtual port: {{ $defaultPort }} - # VIRTUAL_PORT: {{ $container.Env.VIRTUAL_PORT }} - {{ if not $address }} - # /!\ Virtual port not exposed + {{ if $address }} + {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}} + {{ if and $container.Node.ID $address.HostPort }} + {{ $server_found = "true" }} + # {{ $container.Node.Name }}/{{ $container.Name }} + server {{ $container.Node.Address.IP }}:{{ $address.HostPort }}; + {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} + {{ else if $containerNetwork }} + {{ $server_found = "true" }} + # {{ $container.Name }} + server {{ $containerNetwork.IP }}:{{ $address.Port }}; + {{ end }} + {{ else if $containerNetwork }} + # {{ $container.Name }} + {{ if $containerNetwork.IP }} + {{ $server_found = "true" }} + server {{ $containerNetwork.IP }}:{{ $port }}; + {{ else }} + # /!\ No IP for this network! {{ end }} {{ end }} - {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork "VirtualPort" $port) }} {{ else }} # Cannot connect to network '{{ $containerNetwork.Name }}' of this container {{ end }} {{ end }} {{ end }} {{/* nginx-proxy/nginx-proxy#1105 */}} + {{ if (eq $server_found "false") }} # Fallback entry server 127.0.0.1 down; + {{ end }} {{ end }} } diff --git a/test/test_server-down/test_no-server-down.py b/test/test_server-down/test_no-server-down.py new file mode 100644 index 0000000..a98ed56 --- /dev/null +++ b/test/test_server-down/test_no-server-down.py @@ -0,0 +1,8 @@ +import pytest + +def test_web_has_no_server_down(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + r = nginxproxy.get("http://web.nginx-proxy.tld/port") + assert r.status_code == 200 + assert r.text == "answer from port 81\n" + assert conf.count("server 127.0.0.1 down;") == 0 diff --git a/test/test_server-down/test_no-server-down.yml b/test/test_server-down/test_no-server-down.yml new file mode 100644 index 0000000..2f99f05 --- /dev/null +++ b/test/test_server-down/test_no-server-down.yml @@ -0,0 +1,13 @@ +web: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web.nginx-proxy.tld + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_server-down/test_server-down.py b/test/test_server-down/test_server-down.py new file mode 100644 index 0000000..995cd7d --- /dev/null +++ b/test/test_server-down/test_server-down.py @@ -0,0 +1,7 @@ +import pytest + +def test_web_has_server_down(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + r = nginxproxy.get("http://web.nginx-proxy.tld/port") + assert r.status_code in [502, 503] + assert conf.count("server 127.0.0.1 down;") == 1 diff --git a/test/test_server-down/test_server-down.yml b/test/test_server-down/test_server-down.yml new file mode 100644 index 0000000..fc20e85 --- /dev/null +++ b/test/test_server-down/test_server-down.yml @@ -0,0 +1,14 @@ +web: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web.nginx-proxy.tld + net: "none" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From 7c0a4cb0b3b92b2ab94025ee02a6d89ab3a17f13 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Tue, 15 Jun 2021 23:55:31 +0200 Subject: [PATCH 069/126] fix: escape backslash in test --- test/test_debug/test_proxy-debug-flag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_debug/test_proxy-debug-flag.py b/test/test_debug/test_proxy-debug-flag.py index b99ccef..af7f73a 100644 --- a/test/test_debug/test_proxy-debug-flag.py +++ b/test/test_debug/test_proxy-debug-flag.py @@ -9,4 +9,4 @@ def test_debug_info_is_present_in_nginx_generated_conf(docker_compose, nginxprox re.search(r"# Exposed ports: \[\{\d+\.\d+\.\d+\.\d+\s+83\s+tcp \} \{\d+\.\d+\.\d+\.\d+\s+82\s+tcp \}\]", conf) assert "# Default virtual port: 80" in conf assert "# VIRTUAL_PORT: 82" in conf - assert conf.count("# /!\ Virtual port not exposed") == 1 + assert conf.count("# /!\\ Virtual port not exposed") == 1 From f9e58cea9bab382eaf029deda7086456db3198a2 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 16 Jun 2021 01:39:47 +0200 Subject: [PATCH 070/126] ci: allow tests to be manually triggered --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a7134c..aabcf25 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: Tests on: + workflow_dispatch: push: paths-ignore: - 'LICENSE' From 54347a978775aa5f1079996abd8bd9de1f78b937 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Sun, 20 Jun 2021 17:51:09 +0200 Subject: [PATCH 071/126] docs: precision about ports in VIRTUAL_HOST --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 19ae9c0..0e66f87 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdoma The containers being proxied must [expose](https://docs.docker.com/engine/reference/run/#expose-incoming-ports) the port to be proxied, either by using the `EXPOSE` directive in their `Dockerfile` or by using the `--expose` flag to `docker run` or `docker create` and be in the same network. By default, if you don't pass the --net flag when your nginx-proxy container is created, it will only be attached to the default bridge network. This means that it will not be able to connect to containers on networks other than bridge. -Provided your DNS is setup to forward foo.bar.com to the host running nginx-proxy, the request will be routed to a container with the VIRTUAL_HOST env var set. +Provided your DNS is setup to forward foo.bar.com to the host running nginx-proxy, the request will be routed to a container with the `VIRTUAL_HOST` env var set. + +Note: providing a port number in `VIRTUAL_HOST` isn't suported, please see [virtual ports](https://github.com/nginx-proxy/nginx-proxy#virtual-ports) or [custom external HTTP/HTTPS ports](https://github.com/nginx-proxy/nginx-proxy#virtual-ports) depending on what you want to achieve. ### Image variants From a637b399b84b0748adf15b35a785fc04d4c8886e Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Sun, 20 Jun 2021 16:57:55 +0200 Subject: [PATCH 072/126] test: add test_server-down/test_load-balancing Check that when multiple containers have the same WIRTUAL_HOST and one of them is unreachable, the resulting `upstream` block has no `server 127.0.0.1 down;` entry. --- test/test_server-down/test_load-balancing.py | 8 +++++ test/test_server-down/test_load-balancing.yml | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/test_server-down/test_load-balancing.py create mode 100644 test/test_server-down/test_load-balancing.yml diff --git a/test/test_server-down/test_load-balancing.py b/test/test_server-down/test_load-balancing.py new file mode 100644 index 0000000..b65d0a1 --- /dev/null +++ b/test/test_server-down/test_load-balancing.py @@ -0,0 +1,8 @@ +import pytest + +def test_web_has_no_server_down(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + r = nginxproxy.get("http://web.nginx-proxy.tld/port") + assert r.status_code == 200 + assert (r.text == "answer from port 81\n") or (r.text == "answer from port 82\n") + assert conf.count("server 127.0.0.1 down;") == 0 diff --git a/test/test_server-down/test_load-balancing.yml b/test/test_server-down/test_load-balancing.yml new file mode 100644 index 0000000..b7162d1 --- /dev/null +++ b/test/test_server-down/test_load-balancing.yml @@ -0,0 +1,30 @@ +web1: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web.nginx-proxy.tld + +web2: + image: web + expose: + - "82" + environment: + WEB_PORTS: 83 + VIRTUAL_HOST: web.nginx-proxy.tld + +web3: + image: web + expose: + - "83" + environment: + WEB_PORTS: 83 + VIRTUAL_HOST: web.nginx-proxy.tld + net: "none" + +sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From dfc84558a5951c366fd7945f6e3a650fb34aa68f Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Sun, 20 Jun 2021 17:00:36 +0200 Subject: [PATCH 073/126] fix: upstream fallback entry with load balancing --- nginx.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index 6603e6d..7c36e70 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -159,6 +159,7 @@ server { # {{ $host }} upstream {{ $upstream_name }} { +{{ $server_found := "false" }} {{ range $container := $containers }} {{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }} {{/* If only 1 port exposed, use that as a default, else 80 */}} @@ -173,7 +174,6 @@ upstream {{ $upstream_name }} { # /!\ Virtual port not exposed {{ end }} {{ end }} - {{ $server_found := "false" }} {{ range $knownNetwork := $CurrentContainer.Networks }} {{ range $containerNetwork := $container.Networks }} {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} @@ -204,11 +204,11 @@ upstream {{ $upstream_name }} { {{ end }} {{ end }} {{ end }} - {{/* nginx-proxy/nginx-proxy#1105 */}} - {{ if (eq $server_found "false") }} +{{ end }} +{{/* nginx-proxy/nginx-proxy#1105 */}} +{{ if (eq $server_found "false") }} # Fallback entry server 127.0.0.1 down; - {{ end }} {{ end }} } From d743160597590668ea0aeb74d8040d7a4c819ac7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Jul 2021 04:11:58 +0000 Subject: [PATCH 074/126] chore(deps): bump nginx from 1.21.0 to 1.21.1 Bumps nginx from 1.21.0 to 1.21.1. --- updated-dependencies: - dependency-name: nginx dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0861869..eeef16e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.21.0 +FROM nginx:1.21.1 LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 835bc6a..f098f2c 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -37,7 +37,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.21.0-alpine +FROM nginx:1.21.1-alpine LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates From d61f25ed3efdc79c7a898936f0c4e451f53c5e48 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 9 Jul 2021 08:12:06 +0200 Subject: [PATCH 075/126] docs: update nginx version badge to 1.21.1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e66f87..3f25b6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) [![GitHub release](https://img.shields.io/github/v/release/nginx-proxy/nginx-proxy)](https://github.com/nginx-proxy/nginx-proxy/releases) -![nginx 1.21.0](https://img.shields.io/badge/nginx-1.21.0-brightgreen.svg) +![nginx 1.21.1](https://img.shields.io/badge/nginx-1.21.0-brightgreen.svg) [![Docker Image Size](https://img.shields.io/docker/image-size/nginxproxy/nginx-proxy?sort=semver)](https://hub.docker.com/r/nginxproxy/nginx-proxy "Click to view the image on Docker Hub") [![Docker stars](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![Docker pulls](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') From 785141c7a0c22cc36036333b95ff613a1cbef81e Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 9 Jul 2021 08:13:06 +0200 Subject: [PATCH 076/126] docs: update nginx version badge to 1.21.1 (typo) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f25b6c..a48fc1d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Test](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml/badge.svg)](https://github.com/nginx-proxy/nginx-proxy/actions/workflows/test.yml) [![GitHub release](https://img.shields.io/github/v/release/nginx-proxy/nginx-proxy)](https://github.com/nginx-proxy/nginx-proxy/releases) -![nginx 1.21.1](https://img.shields.io/badge/nginx-1.21.0-brightgreen.svg) +![nginx 1.21.1](https://img.shields.io/badge/nginx-1.21.1-brightgreen.svg) [![Docker Image Size](https://img.shields.io/docker/image-size/nginxproxy/nginx-proxy?sort=semver)](https://hub.docker.com/r/nginxproxy/nginx-proxy "Click to view the image on Docker Hub") [![Docker stars](https://img.shields.io/docker/stars/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') [![Docker pulls](https://img.shields.io/docker/pulls/nginxproxy/nginx-proxy.svg)](https://hub.docker.com/r/nginxproxy/nginx-proxy 'DockerHub') From 0b735897cb2bd704dffb8f2f6c497a2fe2bf6714 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 15 Jul 2021 04:11:52 +0000 Subject: [PATCH 077/126] chore(deps): bump golang from 1.16.5 to 1.16.6 Bumps golang from 1.16.5 to 1.16.6. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index eeef16e..b5bb1c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.16.5 as gobuilder +FROM golang:1.16.6 as gobuilder # Build docker-gen from scratch FROM gobuilder as dockergen diff --git a/Dockerfile.alpine b/Dockerfile.alpine index f098f2c..b71a58d 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.6 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.16.5-alpine as gobuilder +FROM golang:1.16.6-alpine as gobuilder RUN apk add --no-cache git musl-dev # Build docker-gen from scratch From 4e3e518936d27d22e5e5e5552d41097d11bb727c Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 19 Jul 2021 21:24:28 +0200 Subject: [PATCH 078/126] docs: update issue template w/ link to discussions --- .github/ISSUE_TEMPLATE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index d09ea82..99d688b 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1,11 @@ # !!!PLEASE READ!!! +## Questions + +If you have a question, DO NOT SUBMIT a new issue. + +Please ask the question on the Discussions section: https://github.com/nginx-proxy/nginx-proxy/discussions + ## Bugs or Features If you are logging a bug or feature request, please search the current open issues to see if there is already a bug or feature opened. From b01d6dd9cc097fa10584212aab0a07623b66c191 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 12:46:45 +0200 Subject: [PATCH 079/126] ci: enable Dependabot checks for Python --- .github/dependabot.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f826c1d..9056ae1 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,11 @@ updates: labels: - "type/build" - "scope/dockerfile" + + # Maintain Python dependencies (test suite) + - package-ecosystem: "pip" + directory: "/test/requirements" + schedule: + interval: "daily" + labels: + - "type/ci" From eefea9daec824a29bd645cf0faf402b47786bab2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Aug 2021 10:47:08 +0000 Subject: [PATCH 080/126] chore(deps): bump requests from 2.25.1 to 2.26.0 in /test/requirements Bumps [requests](https://github.com/psf/requests) from 2.25.1 to 2.26.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/master/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.25.1...v2.26.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 11f8665..4a2645f 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -2,4 +2,4 @@ backoff==1.10.0 docker-compose==1.28.5 docker==4.4.4 pytest==6.2.2 -requests==2.25.1 +requests==2.26.0 From 9855571616a5ccb833cd39807947afec02fb9e2b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Aug 2021 10:55:56 +0000 Subject: [PATCH 081/126] chore(deps): bump backoff from 1.10.0 to 1.11.1 in /test/requirements Bumps [backoff](https://github.com/litl/backoff) from 1.10.0 to 1.11.1. - [Release notes](https://github.com/litl/backoff/releases) - [Changelog](https://github.com/litl/backoff/blob/master/CHANGELOG.md) - [Commits](https://github.com/litl/backoff/compare/v1.10.0...v1.11.1) --- updated-dependencies: - dependency-name: backoff dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 4a2645f..2ff1a8b 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,4 +1,4 @@ -backoff==1.10.0 +backoff==1.11.1 docker-compose==1.28.5 docker==4.4.4 pytest==6.2.2 From 1ba594cc4d2a26525ccc0d36fea952de1d192e33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Aug 2021 11:05:37 +0000 Subject: [PATCH 082/126] chore(deps): bump pytest from 6.2.2 to 6.2.4 in /test/requirements Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.2 to 6.2.4. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.2...6.2.4) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 2ff1a8b..bdeb4f0 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ backoff==1.11.1 docker-compose==1.28.5 docker==4.4.4 -pytest==6.2.2 +pytest==6.2.4 requests==2.26.0 From ce4ce0676a94e2a7089b8f8a584699deaa05a1c9 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 14:44:21 +0200 Subject: [PATCH 083/126] ci: update docker and docker-compose pip packages --- test/requirements/python-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index bdeb4f0..35bdb2b 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ backoff==1.11.1 -docker-compose==1.28.5 -docker==4.4.4 +docker-compose==1.29.2 +docker==5.0.0 pytest==6.2.4 requests==2.26.0 From 90a7218622c9104ea811f90c4fe77c9f52acccf4 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 14:48:40 +0200 Subject: [PATCH 084/126] ci: update contest.py --- test/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index b738c83..b460135 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -488,5 +488,5 @@ try: except docker.errors.ImageNotFound: pytest.exit("The docker image 'nginxproxy/nginx-proxy:test' is missing") -if docker.__version__ != "4.4.4": - pytest.exit("This test suite is meant to work with the python docker module v4.4.4") +if docker.__version__ != "5.0.0": + pytest.exit("This test suite is meant to work with the python docker module v5.0.0") From 795e0acda7d46fdb82623cc6fbe5eb0c530606ad Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 18:09:34 +0200 Subject: [PATCH 085/126] ci: remove InsecureRequestWarning from urllib3 --- test/test_headers/test_https.py | 6 +++++- .../wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_headers/test_https.py b/test/test_headers/test_https.py index 9aa967a..c5457c4 100644 --- a/test/test_headers/test_https.py +++ b/test/test_headers/test_https.py @@ -1,3 +1,6 @@ +import pytest + + def test_arbitrary_headers_are_passed_on(docker_compose, nginxproxy): r = nginxproxy.get("https://web.nginx-proxy.tld/headers", headers={'Foo': 'Bar'}) assert r.status_code == 200 @@ -78,6 +81,7 @@ def test_httpoxy_safe(docker_compose, nginxproxy): assert "Proxy:" not in r.text +@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning') def test_no_host_server_tokens_off(docker_compose, nginxproxy): ip = nginxproxy.get_ip() r = nginxproxy.get(f"https://{ip}/headers", verify=False) @@ -86,7 +90,7 @@ def test_no_host_server_tokens_off(docker_compose, nginxproxy): def test_server_tokens_on(docker_compose, nginxproxy): - r = nginxproxy.get("https://web.nginx-proxy.tld/headers", verify=False) + r = nginxproxy.get("https://web.nginx-proxy.tld/headers") assert r.status_code == 200 assert "Host: web.nginx-proxy.tld" in r.text assert r.headers["Server"].startswith("nginx/") diff --git a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py index 03af625..68b0329 100644 --- a/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py +++ b/test/test_ssl/wildcard_cert_and_nohttps/test_wildcard_cert_nohttps.py @@ -23,7 +23,7 @@ def test_https_get_served(docker_compose, nginxproxy, subdomain): assert r.status_code == 200 assert f"answer from port 8{subdomain}\n" == r.text - +@pytest.mark.filterwarnings('ignore::urllib3.exceptions.InsecureRequestWarning') def test_web3_https_is_500_and_SSL_validation_fails(docker_compose, nginxproxy): with pytest.raises( (CertificateError, SSLError) ) as excinfo: nginxproxy.get("https://3.web.nginx-proxy.tld/port") From d3fc5c506a6532763eb4f79551146f7205ba2b5b Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 18:33:35 +0200 Subject: [PATCH 086/126] ci: enable Docker IPv6 on tests that require it --- test/test_ipv6.yml | 58 +++++++++++++++++++++++++++---------------- test/test_nominal.yml | 54 ++++++++++++++++++++++++++-------------- 2 files changed, 72 insertions(+), 40 deletions(-) diff --git a/test/test_ipv6.yml b/test/test_ipv6.yml index 8da3347..c98c17e 100644 --- a/test/test_ipv6.yml +++ b/test/test_ipv6.yml @@ -1,24 +1,40 @@ -web1: - image: web - expose: - - "81" - environment: - WEB_PORTS: 81 - VIRTUAL_HOST: web1.nginx-proxy.tld +version: '2' -web2: - image: web - expose: - - "82" - environment: - WEB_PORTS: 82 - VIRTUAL_HOST: web2.nginx-proxy.tld +networks: + net1: + enable_ipv6: true + ipam: + config: + - subnet: fd00:1::/80 + +services: + web1: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web1.nginx-proxy.tld + networks: + - net1 + + web2: + image: web + expose: + - "82" + environment: + WEB_PORTS: 82 + VIRTUAL_HOST: web2.nginx-proxy.tld + networks: + - net1 -sut: - image: nginxproxy/nginx-proxy:test - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - environment: - ENABLE_IPV6: "true" + sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + environment: + ENABLE_IPV6: "true" + networks: + - net1 diff --git a/test/test_nominal.yml b/test/test_nominal.yml index 7c49801..2b62d04 100644 --- a/test/test_nominal.yml +++ b/test/test_nominal.yml @@ -1,22 +1,38 @@ -web1: - image: web - expose: - - "81" - environment: - WEB_PORTS: 81 - VIRTUAL_HOST: web1.nginx-proxy.tld +version: '2' -web2: - image: web - expose: - - "82" - environment: - WEB_PORTS: 82 - VIRTUAL_HOST: web2.nginx-proxy.tld +networks: + net1: + enable_ipv6: true + ipam: + config: + - subnet: fd00:1::/80 + +services: + web1: + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: web1.nginx-proxy.tld + networks: + - net1 + + web2: + image: web + expose: + - "82" + environment: + WEB_PORTS: 82 + VIRTUAL_HOST: web2.nginx-proxy.tld + networks: + - net1 -sut: - image: nginxproxy/nginx-proxy:test - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + networks: + - net1 From 10a4db50672ca8ca644005cbb0681f6b5203680e Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 19:08:06 +0200 Subject: [PATCH 087/126] ci: remove xfail from tests that were fixed --- .../test_deleted_cert/test_restart_while_missing_cert.py | 2 -- .../test_unreachable_network/test_unreachable_net.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py b/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py index 0ec36c7..0c5565b 100644 --- a/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py +++ b/test/stress_tests/test_deleted_cert/test_restart_while_missing_cert.py @@ -9,8 +9,6 @@ from requests import ConnectionError script_dir = os.path.dirname(__file__) -pytestmark = pytest.mark.xfail() # TODO delete this marker once those issues are fixed - @pytest.fixture(scope="module", autouse=True) def certs(): diff --git a/test/stress_tests/test_unreachable_network/test_unreachable_net.py b/test/stress_tests/test_unreachable_network/test_unreachable_net.py index dbcfb14..4c09da2 100644 --- a/test/stress_tests/test_unreachable_network/test_unreachable_net.py +++ b/test/stress_tests/test_unreachable_network/test_unreachable_net.py @@ -3,8 +3,6 @@ from time import sleep import pytest import requests -pytestmark = pytest.mark.xfail() # TODO delete this marker once #585 is merged - def test_default_nginx_welcome_page_should_not_be_served(docker_compose, nginxproxy): r = nginxproxy.get("http://whatever.nginx-proxy/", allow_redirects=False) From df638c3fe62fad0e0776e738f1cc8afb841cb418 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Mon, 2 Aug 2021 19:31:36 +0200 Subject: [PATCH 088/126] ci: cleanup left over volumes after tests --- test/conftest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index b460135..bacdaef 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -288,11 +288,11 @@ def docker_compose_up(compose_file='docker-compose.yml'): def docker_compose_down(compose_file='docker-compose.yml'): - logging.info(f'docker-compose -f {compose_file} down') + logging.info(f'docker-compose -f {compose_file} down -v') try: - subprocess.check_output(shlex.split(f'docker-compose -f {compose_file} down'), stderr=subprocess.STDOUT) + subprocess.check_output(shlex.split(f'docker-compose -f {compose_file} down -v'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - pytest.fail(f"Error while runninng 'docker-compose -f {compose_file} down':\n{e.output}", pytrace=False) + pytest.fail(f"Error while runninng 'docker-compose -f {compose_file} down -v':\n{e.output}", pytrace=False) def wait_for_nginxproxy_to_be_ready(): From 897e4135d3e48d64a3294ca8a463747f7c0074f8 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 4 Aug 2021 08:48:25 +0200 Subject: [PATCH 089/126] build: docker-gen 0.7.6 -> 0.7.7 --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b5bb1c1..fbe9f7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # setup build arguments for version of dependencies to use -ARG DOCKER_GEN_VERSION=0.7.6 +ARG DOCKER_GEN_VERSION=0.7.7 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries diff --git a/Dockerfile.alpine b/Dockerfile.alpine index b71a58d..221b0ae 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,5 +1,5 @@ # setup build arguments for version of dependencies to use -ARG DOCKER_GEN_VERSION=0.7.6 +ARG DOCKER_GEN_VERSION=0.7.7 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries From 8526d918ed6661c8bdc5b7e4652f4e19c697a250 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 4 Aug 2021 08:49:23 +0200 Subject: [PATCH 090/126] style: Dockerfiles linting --- Dockerfile | 14 +++++++------- Dockerfile.alpine | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index fbe9f7f..5b1801c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,17 +41,17 @@ LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates RUN apt-get update \ - && apt-get install -y -q --no-install-recommends \ - ca-certificates \ - wget \ - && apt-get clean \ - && rm -r /var/lib/apt/lists/* + && apt-get install -y -q --no-install-recommends \ + ca-certificates \ + wget \ + && apt-get clean \ + && rm -r /var/lib/apt/lists/* # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ - && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ - && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf + && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf # Install Forego + docker-gen COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 221b0ae..40177e0 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -42,13 +42,13 @@ LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates RUN apk add --no-cache --virtual .run-deps \ - ca-certificates bash wget openssl \ - && update-ca-certificates + ca-certificates bash wget openssl \ + && update-ca-certificates # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ - && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ - && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf + && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf # Install Forego + docker-gen COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego From ba86bc04f6f05811a3dd24deab144de5bb505f05 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 4 Aug 2021 22:25:55 +0200 Subject: [PATCH 091/126] tests: check for raw IPv4/6 used as VIRTUAL_HOST --- test/test_raw-ip-vhost.py | 15 ++++++++++++ test/test_raw-ip-vhost.yml | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/test_raw-ip-vhost.py create mode 100644 test/test_raw-ip-vhost.yml diff --git a/test/test_raw-ip-vhost.py b/test/test_raw-ip-vhost.py new file mode 100644 index 0000000..aaff852 --- /dev/null +++ b/test/test_raw-ip-vhost.py @@ -0,0 +1,15 @@ +import pytest + + +def test_raw_ipv4_vhost_forwards_to_web1(docker_compose, nginxproxy): + r = nginxproxy.get("http://172.20.0.4") + assert r.status_code == 200 + web1_container = docker_compose.containers.get("web1") + assert r.text == f"I'm {web1_container.id[:12]}\n" + + +def test_raw_ipv6_vhost_forwards_to_web2(docker_compose, nginxproxy): + r = nginxproxy.get("http://[fd00::4]", ipv6=True) + assert r.status_code == 200 + web2_container = docker_compose.containers.get("web2") + assert r.text == f"I'm {web2_container.id[:12]}\n" diff --git a/test/test_raw-ip-vhost.yml b/test/test_raw-ip-vhost.yml new file mode 100644 index 0000000..e265d74 --- /dev/null +++ b/test/test_raw-ip-vhost.yml @@ -0,0 +1,48 @@ +version: '2' + +networks: + net1: + enable_ipv6: true + ipam: + config: + - subnet: 172.20.0.0/16 + - subnet: fd00::/80 + +services: + web1: + container_name: web1 + image: web + expose: + - "81" + environment: + WEB_PORTS: 81 + VIRTUAL_HOST: "172.20.0.4" + networks: + net1: + ipv4_address: 172.20.0.2 + ipv6_address: fd00::2 + + web2: + container_name: web2 + image: web + expose: + - "82" + environment: + WEB_PORTS: 82 + VIRTUAL_HOST: "[fd00::4]" + networks: + net1: + ipv4_address: 172.20.0.3 + ipv6_address: fd00::3 + + sut: + image: nginxproxy/nginx-proxy:test + environment: + ENABLE_IPV6: "true" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + networks: + net1: + ipv4_address: 172.20.0.4 + ipv6_address: fd00::4 From 89d37882b63ac68fe2b0a39d1e59020800d501c4 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 4 Aug 2021 22:28:00 +0200 Subject: [PATCH 092/126] fix: always use sha1 of hostname as upstream name --- nginx.tmpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index 7c36e70..6df80f6 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -153,8 +153,7 @@ server { {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} {{ $host := trim $host }} -{{ $is_regexp := hasPrefix "~" $host }} -{{ $upstream_name := (print (when $is_regexp (sha1 $host) $host) "-upstream") }} +{{ $upstream_name := sha1 $host }} # {{ $host }} upstream {{ $upstream_name }} { From c36633320eb8a83e8ca0f3e8133054315ced6090 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 6 Aug 2021 04:11:55 +0000 Subject: [PATCH 093/126] chore(deps): bump golang from 1.16.6 to 1.16.7 Bumps golang from 1.16.6 to 1.16.7. --- updated-dependencies: - dependency-name: golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5b1801c..97c0cc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.7 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.16.6 as gobuilder +FROM golang:1.16.7 as gobuilder # Build docker-gen from scratch FROM gobuilder as dockergen diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 40177e0..c08dcc3 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -3,7 +3,7 @@ ARG DOCKER_GEN_VERSION=0.7.7 ARG FOREGO_VERSION=v0.17.0 # Use a specific version of golang to build both binaries -FROM golang:1.16.6-alpine as gobuilder +FROM golang:1.16.7-alpine as gobuilder RUN apk add --no-cache git musl-dev # Build docker-gen from scratch From eb3bb2ab078d93c3851915155de49ea3c567c6f0 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 17 Aug 2021 11:13:31 +0200 Subject: [PATCH 094/126] docs: fix line feeds --- README.md | 125 ++++++++++++++---------------------------------------- 1 file changed, 31 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index a48fc1d..8e66762 100644 --- a/README.md +++ b/README.md @@ -150,15 +150,11 @@ If you would like the reverse proxy to connect to your backend using HTTPS inste ### uWSGI Backends -If you would like to connect to uWSGI backend, set `VIRTUAL_PROTO=uwsgi` on the -backend container. Your backend container should then listen on a port rather -than a socket and expose that port. +If you would like to connect to uWSGI backend, set `VIRTUAL_PROTO=uwsgi` on the backend container. Your backend container should then listen on a port rather than a socket and expose that port. ### FastCGI Backends -If you would like to connect to FastCGI backend, set `VIRTUAL_PROTO=fastcgi` on the -backend container. Your backend container should then listen on a port rather -than a socket and expose that port. +If you would like to connect to FastCGI backend, set `VIRTUAL_PROTO=fastcgi` on the backend container. Your backend container should then listen on a port rather than a socket and expose that port. ### FastCGI File Root Directory @@ -177,8 +173,7 @@ nginx-proxy will then redirect all requests to a container where `VIRTUAL_HOST` ### Separate Containers -nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) -image and the official [nginx](https://registry.hub.docker.com/_/nginx/) image. +nginx-proxy can also be run as two separate containers using the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image and the official [nginx](https://registry.hub.docker.com/_/nginx/) image. You may want to do this to prevent having the docker socket bound to a publicly exposed container service. @@ -209,125 +204,71 @@ $ docker run --volumes-from nginx \ Finally, start your containers with `VIRTUAL_HOST` environment variables. $ docker run -e VIRTUAL_HOST=foo.bar.com ... + ### SSL Support using an ACME CA [acme-companion](https://github.com/nginx-proxy/acme-companion) is a lightweight companion container for the nginx-proxy. It allows the automated creation/renewal of SSL certificates using the ACME protocol. -Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. -The default value is `true` +Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` $ docker run -e DHPARAM_GENERATION=false .... + ### SSL Support -SSL is supported using single host, wildcard and SNI certificates using naming conventions for -certificates or optionally specifying a cert name (for SNI) as an environment variable. +SSL is supported using single host, wildcard and SNI certificates using naming conventions for certificates or optionally specifying a cert name (for SNI) as an environment variable. To enable SSL: $ docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy -The contents of `/path/to/certs` should contain the certificates and private keys for any virtual -hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and -`.key` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a -`foo.bar.com.crt` and `foo.bar.com.key` file in the certs directory. +The contents of `/path/to/certs` should contain the certificates and private keys for any virtual hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and `.key` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.crt` and `foo.bar.com.key` file in the certs directory. -If you are running the container in a virtualized environment (Hyper-V, VirtualBox, etc...), -/path/to/certs must exist in that environment or be made accessible to that environment. -By default, Docker is not able to mount directories on the host machine to containers running in a virtual machine. +If you are running the container in a virtualized environment (Hyper-V, VirtualBox, etc...), /path/to/certs must exist in that environment or be made accessible to that environment. By default, Docker is not able to mount directories on the host machine to containers running in a virtual machine. #### Diffie-Hellman Groups -Diffie-Hellman groups are enabled by default, with a pregenerated key in `/etc/nginx/dhparam/dhparam.pem`. -You can mount a different `dhparam.pem` file at that location to override the default cert. -To use custom `dhparam.pem` files per-virtual-host, the files should be named after the virtual host with a -`dhparam` suffix and `.pem` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` -should have a `foo.bar.com.dhparam.pem` file in the `/etc/nginx/certs` directory. +Diffie-Hellman groups are enabled by default, with a pregenerated key in `/etc/nginx/dhparam/dhparam.pem`. You can mount a different `dhparam.pem` file at that location to override the default cert. To use custom `dhparam.pem` files per-virtual-host, the files should be named after the virtual host with a `dhparam` suffix and `.pem` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.dhparam.pem` file in the `/etc/nginx/certs` directory. -> NOTE: If you don't mount a `dhparam.pem` file at `/etc/nginx/dhparam/dhparam.pem`, one will be generated -at startup. Since it can take minutes to generate a new `dhparam.pem`, it is done at low priority in the -background. Once generation is complete, the `dhparam.pem` is saved on a persistent volume and nginx -is reloaded. This generation process only occurs the first time you start `nginx-proxy`. +> NOTE: If you don't mount a `dhparam.pem` file at `/etc/nginx/dhparam/dhparam.pem`, one will be generated at startup. Since it can take minutes to generate a new `dhparam.pem`, it is done at low priority in the background. Once generation is complete, the `dhparam.pem` is saved on a persistent volume and nginx is reloaded. This generation process only occurs the first time you start `nginx-proxy`. -> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some -> older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these -> clients, you must either provide your own `dhparam.pem`, or tell `nginx-proxy` to generate a 1024-bit -> key on startup by passing `-e DHPARAM_BITS=1024`. +> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these clients, you must either provide your own `dhparam.pem`, or tell `nginx-proxy` to generate a 1024-bit key on startup by passing `-e DHPARAM_BITS=1024`. -In the separate container setup, no pregenerated key will be available and neither the -[jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image nor the offical -[nginx](https://registry.hub.docker.com/_/nginx/) image will generate one. If you still want A+ security -in a separate container setup, you'll have to generate a 2048 or 4096 bits DH key file manually and mount it on the -nginx container, at `/etc/nginx/dhparam/dhparam.pem`. +In the separate container setup, no pregenerated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will generate one. If you still want A+ security in a separate container setup, you'll have to generate a 2048 or 4096 bits DH key file manually and mount it on the nginx container, at `/etc/nginx/dhparam/dhparam.pem`. #### Wildcard Certificates -Wildcard certificates and keys should be named after the domain name with a `.crt` and `.key` extension. -For example `VIRTUAL_HOST=foo.bar.com` would use cert name `bar.com.crt` and `bar.com.key`. +Wildcard certificates and keys should be named after the domain name with a `.crt` and `.key` extension. For example `VIRTUAL_HOST=foo.bar.com` would use cert name `bar.com.crt` and `bar.com.key`. #### SNI -If your certificate(s) supports multiple domain names, you can start a container with `CERT_NAME=` -to identify the certificate to be used. For example, a certificate for `*.foo.com` and `*.bar.com` -could be named `shared.crt` and `shared.key`. A container running with `VIRTUAL_HOST=foo.bar.com` -and `CERT_NAME=shared` will then use this shared cert. +If your certificate(s) supports multiple domain names, you can start a container with `CERT_NAME=` to identify the certificate to be used. For example, a certificate for `*.foo.com` and `*.bar.com` could be named `shared.crt` and `shared.key`. A container running with `VIRTUAL_HOST=foo.bar.com` and `CERT_NAME=shared` will then use this shared cert. #### OCSP Stapling -To enable OCSP Stapling for a domain, `nginx-proxy` looks for a PEM certificate containing the trusted -CA certificate chain at `/etc/nginx/certs/.chain.pem`, where `` is the domain name in -the `VIRTUAL_HOST` directive. The format of this file is a concatenation of the public PEM CA -certificates starting with the intermediate CA most near the SSL certificate, down to the root CA. This is -often referred to as the "SSL Certificate Chain". If found, this filename is passed to the NGINX -[`ssl_trusted_certificate` directive](http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_trusted_certificate) -and OCSP Stapling is enabled. + +To enable OCSP Stapling for a domain, `nginx-proxy` looks for a PEM certificate containing the trusted CA certificate chain at `/etc/nginx/certs/.chain.pem`, where `` is the domain name in the `VIRTUAL_HOST` directive. The format of this file is a concatenation of the public PEM CA certificates starting with the intermediate CA most near the SSL certificate, down to the root CA. This is often referred to as the "SSL Certificate Chain". If found, this filename is passed to the NGINX [`ssl_trusted_certificate` directive](http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_trusted_certificate) and OCSP Stapling is enabled. #### How SSL Support Works -The default SSL cipher configuration is based on the [Mozilla intermediate profile](https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28recommended.29) version 5.0 which -should provide compatibility with clients back to Firefox 27, Android 4.4.2, Chrome 31, Edge, IE 11 on Windows 7, -Java 8u31, OpenSSL 1.0.1, Opera 20, and Safari 9. Note that the DES-based TLS ciphers were removed for security. -The configuration also enables HSTS, PFS, OCSP stapling and SSL session caches. Currently TLS 1.2 and 1.3 -are supported. +The default SSL cipher configuration is based on the [Mozilla intermediate profile](https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28recommended.29) version 5.0 which should provide compatibility with clients back to Firefox 27, Android 4.4.2, Chrome 31, Edge, IE 11 on Windows 7, Java 8u31, OpenSSL 1.0.1, Opera 20, and Safari 9. Note that the DES-based TLS ciphers were removed for security. The configuration also enables HSTS, PFS, OCSP stapling and SSL session caches. Currently TLS 1.2 and 1.3 are supported. -If you don't require backward compatibility, you can use the [Mozilla modern profile](https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility) -profile instead by including the environment variable `SSL_POLICY=Mozilla-Modern` to the nginx-proxy container or to your container. -This profile is compatible with clients back to Firefox 63, Android 10.0, Chrome 70, Edge 75, Java 11, -OpenSSL 1.1.1, Opera 57, and Safari 12.1. Note that this profile is **not** compatible with any version of Internet Explorer. +If you don't require backward compatibility, you can use the [Mozilla modern profile](https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility) profile instead by including the environment variable `SSL_POLICY=Mozilla-Modern` to the nginx-proxy container or to your container. This profile is compatible with clients back to Firefox 63, Android 10.0, Chrome 70, Edge 75, Java 11, OpenSSL 1.1.1, Opera 57, and Safari 12.1. Note that this profile is **not** compatible with any version of Internet Explorer. -Other policies available through the `SSL_POLICY` environment variable are [`Mozilla-Old`](https://wiki.mozilla.org/Security/Server_Side_TLS#Old_backward_compatibility) -and the [AWS ELB Security Policies](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html) -`AWS-TLS-1-2-2017-01`, `AWS-TLS-1-1-2017-01`, `AWS-2016-08`, `AWS-2015-05`, `AWS-2015-03` and `AWS-2015-02`. +Other policies available through the `SSL_POLICY` environment variable are [`Mozilla-Old`](https://wiki.mozilla.org/Security/Server_Side_TLS#Old_backward_compatibility) and the [AWS ELB Security Policies](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html) `AWS-TLS-1-2-2017-01`, `AWS-TLS-1-1-2017-01`, `AWS-2016-08`, `AWS-2015-05`, `AWS-2015-03` and `AWS-2015-02`. -Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container generates -a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing -this, either globally or per virtual-host. +Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container generates a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing this, either globally or per virtual-host. The default behavior for the proxy when port 80 and 443 are exposed is as follows: -* If a container has a usable cert, port 80 will redirect to 443 for that container so that HTTPS -is always preferred when available. +* If a container has a usable cert, port 80 will redirect to 443 for that container so that HTTPS is always preferred when available. * If the container does not have a usable cert, a 503 will be returned. -Note that in the latter case, a browser may get an connection error as no certificate is available -to establish a connection. A self-signed or generic cert named `default.crt` and `default.key` -will allow a client browser to make a SSL connection (likely w/ a warning) and subsequently receive -a 500. +Note that in the latter case, a browser may get an connection error as no certificate is available to establish a connection. A self-signed or generic cert named `default.crt` and `default.key` will allow a client browser to make a SSL connection (likely w/ a warning) and subsequently receive a 500. -To serve traffic in both SSL and non-SSL modes without redirecting to SSL, you can include the -environment variable `HTTPS_METHOD=noredirect` (the default is `HTTPS_METHOD=redirect`). You can also -disable the non-SSL site entirely with `HTTPS_METHOD=nohttp`, or disable the HTTPS site with -`HTTPS_METHOD=nohttps`. `HTTPS_METHOD` can be specified on each container for which you want to -override the default behavior or on the proxy container to set it globally. If `HTTPS_METHOD=noredirect` is used, Strict Transport Security (HSTS) -is disabled to prevent HTTPS users from being redirected by the client. If you cannot get to the HTTP -site after changing this setting, your browser has probably cached the HSTS policy and is automatically -redirecting you back to HTTPS. You will need to clear your browser's HSTS cache or use an incognito -window / different browser. +To serve traffic in both SSL and non-SSL modes without redirecting to SSL, you can include the environment variable `HTTPS_METHOD=noredirect` (the default is `HTTPS_METHOD=redirect`). You can also disable the non-SSL site entirely with `HTTPS_METHOD=nohttp`, or disable the HTTPS site with `HTTPS_METHOD=nohttps`. `HTTPS_METHOD` can be specified on each container for which you want to override the default behavior or on the proxy container to set it globally. If `HTTPS_METHOD=noredirect` is used, Strict Transport Security (HSTS) is disabled to prevent HTTPS users from being redirected by the client. If you cannot get to the HTTP site after changing this setting, your browser has probably cached the HSTS policy and is automatically redirecting you back to HTTPS. You will need to clear your browser's HSTS cache or use an incognito window / different browser. -By default, [HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) -is enabled with `max-age=31536000` for HTTPS sites. You can disable HSTS with the environment variable -`HSTS=off` or use a custom HSTS configuration like `HSTS=max-age=31536000; includeSubDomains; preload`. -*WARNING*: HSTS will force your users to visit the HTTPS version of your site for the `max-age` time - -even if they type in `http://` manually. The only way to get to an HTTP site after receiving an HSTS -response is to clear your browser's HSTS cache. +By default, [HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security) is enabled with `max-age=31536000` for HTTPS sites. You can disable HSTS with the environment variable `HSTS=off` or use a custom HSTS configuration like `HSTS=max-age=31536000; includeSubDomains; preload`. + +*WARNING*: HSTS will force your users to visit the HTTPS version of your site for the `max-age` time - even if they type in `http://` manually. The only way to get to an HTTP site after receiving an HSTS response is to clear your browser's HSTS cache. ### Basic Authentication Support @@ -350,8 +291,7 @@ If you need to configure Nginx beyond what is possible using environment variabl #### Replacing default proxy settings -If you want to replace the default proxy settings for the nginx container, add a configuration file at `/etc/nginx/proxy.conf`. A file with the default settings would -look like this: +If you want to replace the default proxy settings for the nginx container, add a configuration file at `/etc/nginx/proxy.conf`. A file with the default settings would look like this: ```Nginx # HTTP 1.1 support @@ -410,13 +350,11 @@ If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=e #### Per-VIRTUAL_HOST default configuration -If you want most of your virtual hosts to use a default single configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default` file. This file -will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}` file associated with it. +If you want most of your virtual hosts to use a default single configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default` file. This file will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}` file associated with it. #### Per-VIRTUAL_HOST location configuration -To add settings to the "location" block on a per-`VIRTUAL_HOST` basis, add your configuration file under `/etc/nginx/vhost.d` -just like the previous section except with the suffix `_location`. +To add settings to the "location" block on a per-`VIRTUAL_HOST` basis, add your configuration file under `/etc/nginx/vhost.d` just like the previous section except with the suffix `_location`. For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows: @@ -430,8 +368,7 @@ If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=e #### Per-VIRTUAL_HOST location default configuration -If you want most of your virtual hosts to use a default single `location` block configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default_location` file. This file -will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}_location` file associated with it. +If you want most of your virtual hosts to use a default single `location` block configuration and then override on a few specific ones, add those settings to the `/etc/nginx/vhost.d/default_location` file. This file will be used on any virtual host which does not have a `/etc/nginx/vhost.d/{VIRTUAL_HOST}_location` file associated with it. #### Per-VIRTUAL_HOST `server_tokens` configuration Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details. From ded3cfc168ca2fefbec028881f452320c509bbdc Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 17 Aug 2021 11:29:21 +0200 Subject: [PATCH 095/126] docs: don't prefix copy pastable commands with $ + other small markdown fixes --- README.md | 124 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 8e66762..779affa 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,15 @@ See [Automated Nginx Reverse Proxy for Docker](http://jasonwilder.com/blog/2014/ To run it: - $ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` Then start any containers you want proxied with an env var `VIRTUAL_HOST=subdomain.youdomain.com` - $ docker run -e VIRTUAL_HOST=foo.bar.com ... +```console +docker run -e VIRTUAL_HOST=foo.bar.com ... +``` The containers being proxied must [expose](https://docs.docker.com/engine/reference/run/#expose-incoming-ports) the port to be proxied, either by using the `EXPOSE` directive in their `Dockerfile` or by using the `--expose` flag to `docker run` or `docker create` and be in the same network. By default, if you don't pass the --net flag when your nginx-proxy container is created, it will only be attached to the default bridge network. This means that it will not be able to connect to containers on networks other than bridge. @@ -34,13 +38,17 @@ The nginx-proxy images are available in two flavors. This image uses the debian:buster based nginx image. - $ docker pull nginxproxy/nginx-proxy:latest +```console +docker pull nginxproxy/nginx-proxy:latest +``` #### nginxproxy/nginx-proxy:alpine This image is based on the nginx:alpine image. Use this image to fully support HTTP/2 (including ALPN required by recent Chrome versions). A valid certificate is required as well (see eg. below "SSL Support using an ACME CA" for more info). - $ docker pull nginxproxy/nginx-proxy:alpine +```console +docker pull nginxproxy/nginx-proxy:alpine +``` ### Docker Compose @@ -64,9 +72,13 @@ services: - VIRTUAL_PORT=8000 ``` -```shell -$ docker-compose up -$ curl -H "Host: whoami.local" localhost +```console +docker-compose up +curl -H "Host: whoami.local" localhost +``` + +Example output: +```console I'm 5b129ab83266 ``` @@ -74,7 +86,9 @@ I'm 5b129ab83266 You can activate the IPv6 support for the nginx-proxy container by passing the value `true` to the `ENABLE_IPV6` environment variable: - $ docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 80:80 -e ENABLE_IPV6=true -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` #### Scoped IPv6 Resolvers @@ -110,9 +124,9 @@ With the addition of [overlay networking](https://docs.docker.com/engine/usergui If you want your `nginx-proxy` container to be attached to a different network, you must pass the `--net=my-network` option in your `docker create` or `docker run` command. At the time of this writing, only a single network can be specified at container creation time. To attach to other networks, you can use the `docker network connect` command after your container is created: ```console -$ docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \ +docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro \ --name my-nginx-proxy --net my-network nginxproxy/nginx-proxy -$ docker network connect my-other-network my-nginx-proxy +docker network connect my-other-network my-nginx-proxy ``` In this example, the `my-nginx-proxy` container will be connected to `my-network` and `my-other-network` and will be able to proxy to other containers attached to those networks. @@ -121,13 +135,15 @@ In this example, the `my-nginx-proxy` container will be connected to `my-network If you want to use `nginx-proxy` with different external ports that the default ones of `80` for `HTTP` traffic and `443` for `HTTPS` traffic, you'll have to use the environment variable(s) `HTTP_PORT` and/or `HTTPS_PORT` in addition to the changes to the Docker port mapping. If you change the `HTTPS` port, the redirect for `HTTPS` traffic will also be configured to redirect to the custom port. Typical usage, here with the custom ports `1080` and `10443`: - $ docker run -d -p 1080:1080 -p 10443:10443 -e HTTP_PORT=1080 -e HTTPS_PORT=10443 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 1080:1080 -p 10443:10443 -e HTTP_PORT=1080 -e HTTPS_PORT=10443 -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` ### Internet vs. Local Network Access If you allow traffic from the public internet to access your `nginx-proxy` container, you may want to restrict some containers to the internal network only, so they cannot be accessed from the public internet. On containers that should be restricted to the internal network, you should set the environment variable `NETWORK_ACCESS=internal`. By default, the *internal* network is defined as `127.0.0.0/8, 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16`. To change the list of networks considered internal, mount a file on the `nginx-proxy` at `/etc/nginx/network_internal.conf` with these contents, edited to suit your needs: -``` +```Nginx # These networks are considered "internal" allow 127.0.0.0/8; allow 10.0.0.0/8; @@ -165,11 +181,15 @@ If you use fastcgi,you can set `VIRTUAL_ROOT=xxx` for your root directory To set the default host for nginx use the env var `DEFAULT_HOST=foo.bar.com` for example - $ docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 80:80 -e DEFAULT_HOST=foo.bar.com -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` nginx-proxy will then redirect all requests to a container where `VIRTUAL_HOST` is set to `DEFAULT_HOST`, if they don't match any (other) `VIRTUAL_HOST`. Using the example above requests without matching `VIRTUAL_HOST` will be redirected to a plain nginx instance after running the following command: - $ docker run -d -e VIRTUAL_HOST=foo.bar.com nginx +```console +docker run -d -e VIRTUAL_HOST=foo.bar.com nginx +``` ### Separate Containers @@ -180,8 +200,12 @@ You may want to do this to prevent having the docker socket bound to a publicly You can demo this pattern with docker-compose: ```console -$ docker-compose --file docker-compose-separate-containers.yml up -$ curl -H "Host: whoami.local" localhost +docker-compose --file docker-compose-separate-containers.yml up +curl -H "Host: whoami.local" localhost +``` + +Example output: +```console I'm 5b129ab83266 ``` @@ -190,12 +214,14 @@ To run nginx proxy as a separate container you'll need to have [nginx.tmpl](http First start nginx with a volume: - $ docker run -d -p 80:80 --name nginx -v /tmp/nginx:/etc/nginx/conf.d -t nginx +```console +docker run -d -p 80:80 --name nginx -v /tmp/nginx:/etc/nginx/conf.d -t nginx +``` Then start the docker-gen container with the shared volume and template: -``` -$ docker run --volumes-from nginx \ +```console +docker run --volumes-from nginx \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ -v $(pwd):/etc/docker-gen/templates \ -t jwilder/docker-gen -notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf @@ -203,7 +229,9 @@ $ docker run --volumes-from nginx \ Finally, start your containers with `VIRTUAL_HOST` environment variables. - $ docker run -e VIRTUAL_HOST=foo.bar.com ... +```console +docker run -e VIRTUAL_HOST=foo.bar.com ... +``` ### SSL Support using an ACME CA @@ -211,7 +239,9 @@ Finally, start your containers with `VIRTUAL_HOST` environment variables. Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` - $ docker run -e DHPARAM_GENERATION=false .... +```console +docker run -e DHPARAM_GENERATION=false .... +``` ### SSL Support @@ -219,7 +249,9 @@ SSL is supported using single host, wildcard and SNI certificates using naming c To enable SSL: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 80:80 -p 443:443 -v /path/to/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` The contents of `/path/to/certs` should contain the certificates and private keys for any virtual hosts in use. The certificate and keys should be named after the virtual host with a `.crt` and `.key` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.crt` and `foo.bar.com.key` file in the certs directory. @@ -275,8 +307,8 @@ By default, [HTTP Strict Transport Security (HSTS)](https://developer.mozilla.or In order to be able to secure your virtual host, you have to create a file named as its equivalent VIRTUAL_HOST variable on directory /etc/nginx/htpasswd/$VIRTUAL_HOST -``` -$ docker run -d -p 80:80 -p 443:443 \ +```console +docker run -d -p 80:80 -p 443:443 \ -v /path/to/htpasswd:/etc/nginx/htpasswd \ -v /path/to/certs:/etc/nginx/certs \ -v /var/run/docker.sock:/tmp/docker.sock:ro \ @@ -330,7 +362,9 @@ RUN { \ Or it can be done by mounting in your custom configuration in your `docker run` command: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +```console +docker run -d -p 80:80 -p 443:443 -v /path/to/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +``` #### Per-VIRTUAL_HOST @@ -340,13 +374,17 @@ In order to allow virtual hosts to be dynamically configured as backends are add For example, if you have a virtual host named `app.example.com`, you could provide a custom configuration for that host as follows: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy - $ { echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/app.example.com +```console +docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +{ echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/app.example.com +``` If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink: - $ { echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/www.example.com - $ ln -s /path/to/vhost.d/www.example.com /path/to/vhost.d/example.com +```console +{ echo 'server_tokens off;'; echo 'client_max_body_size 100m;'; } > /path/to/vhost.d/www.example.com +ln -s /path/to/vhost.d/www.example.com /path/to/vhost.d/example.com +``` #### Per-VIRTUAL_HOST default configuration @@ -358,13 +396,17 @@ To add settings to the "location" block on a per-`VIRTUAL_HOST` basis, add your For example, if you have a virtual host named `app.example.com` and you have configured a proxy_cache `my-cache` in another custom file, you could tell it to use a proxy cache as follows: - $ docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy - $ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location +```console +docker run -d -p 80:80 -p 443:443 -v /path/to/vhost.d:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro nginxproxy/nginx-proxy +{ echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location +``` If you are using multiple hostnames for a single container (e.g. `VIRTUAL_HOST=example.com,www.example.com`), the virtual host configuration file must exist for each hostname. If you would like to use the same configuration for multiple virtual host names, you can use a symlink: - $ { echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location - $ ln -s /path/to/vhost.d/www.example.com /path/to/vhost.d/example.com +```console +{ echo 'proxy_cache my-cache;'; echo 'proxy_cache_valid 200 302 60m;'; echo 'proxy_cache_valid 404 1m;' } > /path/to/vhost.d/app.example.com_location +ln -s /path/to/vhost.d/www.example.com /path/to/vhost.d/example.com +``` #### Per-VIRTUAL_HOST location default configuration @@ -377,12 +419,12 @@ Per virtual-host `servers_tokens` directive can be configured by passing appropr In case you can't access your VIRTUAL_HOST, set `DEBUG=true` in the client container's environment and have a look at the generated nginx configuration file `/etc/nginx/conf.d/default`: -``` -$ docker exec cat /etc/nginx/conf.d/default +```console +docker exec cat /etc/nginx/conf.d/default ``` Especially at `upstream` definition blocks which should look like: -``` +```Nginx # foo.example.com upstream foo.example.com { ## Can be connected with "my_network" network @@ -409,13 +451,17 @@ Before submitting pull requests or issues, please check github to make sure an e To run tests, you just need to run the command below: - make test +```console +make test +``` This commands run tests on two variants of the nginx-proxy docker image: Debian and Alpine. You can run the tests for each of these images with their respective commands: - make test-debian - make test-alpine +```console +make test-debian +make test-alpine +``` You can learn more about how the test suite works and how to write new tests in the [test/README.md](test/README.md) file. From d10531e9259791b8f6f416240c0781f229d3b67c Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 17 Aug 2021 21:34:50 +0200 Subject: [PATCH 096/126] tests: predictable upstream names --- .../test_predictable-name.py | 7 +++++++ .../test_predictable-name.yml | 16 ++++++++++++++++ test/test_upstream-name/test_sha1-name.py | 12 ++++++++++++ test/test_upstream-name/test_sha1-name.yml | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 test/test_upstream-name/test_predictable-name.py create mode 100644 test/test_upstream-name/test_predictable-name.yml create mode 100644 test/test_upstream-name/test_sha1-name.py create mode 100644 test/test_upstream-name/test_sha1-name.yml diff --git a/test/test_upstream-name/test_predictable-name.py b/test/test_upstream-name/test_predictable-name.py new file mode 100644 index 0000000..7e19646 --- /dev/null +++ b/test/test_upstream-name/test_predictable-name.py @@ -0,0 +1,7 @@ +import pytest +import re + + +def test_predictable_upstream_is_present_in_nginx_generated_conf(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + assert re.search(r"upstream web\.nginx-proxy\.tld \{", conf) diff --git a/test/test_upstream-name/test_predictable-name.yml b/test/test_upstream-name/test_predictable-name.yml new file mode 100644 index 0000000..1265230 --- /dev/null +++ b/test/test_upstream-name/test_predictable-name.yml @@ -0,0 +1,16 @@ +version: '2' + +services: + web: + image: web + expose: + - "80" + environment: + WEB_PORTS: 80 + VIRTUAL_HOST: web.nginx-proxy.tld + + sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_upstream-name/test_sha1-name.py b/test/test_upstream-name/test_sha1-name.py new file mode 100644 index 0000000..663ca28 --- /dev/null +++ b/test/test_upstream-name/test_sha1-name.py @@ -0,0 +1,12 @@ +import pytest +import re + + +def test_sha1_upstream_is_present_in_nginx_generated_conf(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + assert re.search(r"upstream 3e837201a6255962094cd6d8f61e22b07d3cc8ed \{", conf) + +def test_sha1_upstream_forwards_correctly(docker_compose, nginxproxy): + r = nginxproxy.get("http://web.nginx-proxy.tld/port") + assert r.status_code == 200 + assert r.text == "answer from port 80\n" diff --git a/test/test_upstream-name/test_sha1-name.yml b/test/test_upstream-name/test_sha1-name.yml new file mode 100644 index 0000000..d2095f3 --- /dev/null +++ b/test/test_upstream-name/test_sha1-name.yml @@ -0,0 +1,18 @@ +version: '2' + +services: + web: + image: web + expose: + - "80" + environment: + WEB_PORTS: 80 + VIRTUAL_HOST: web.nginx-proxy.tld + + sut: + image: nginxproxy/nginx-proxy:test + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + environment: + SHA1_UPSTREAM_NAME: "true" From e748ffdce4d4927b19939b0dc4dff686be68d6b7 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 17 Aug 2021 21:51:09 +0200 Subject: [PATCH 097/126] feat: sha1 upstream names --- nginx.tmpl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index 6df80f6..e79f790 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -3,6 +3,7 @@ {{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }} {{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }} {{ $debug_all := $.Env.DEBUG }} +{{ $sha1_upstream_name := parseBool (coalesce $.Env.SHA1_UPSTREAM_NAME "false") }} {{ define "ssl_policy" }} {{ if eq .ssl_policy "Mozilla-Modern" }} @@ -153,7 +154,8 @@ server { {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} {{ $host := trim $host }} -{{ $upstream_name := sha1 $host }} +{{ $is_regexp := hasPrefix "~" $host }} +{{ $upstream_name := when (or $is_regexp $sha1_upstream_name) (sha1 $host) $host }} # {{ $host }} upstream {{ $upstream_name }} { From a33af34361e312497fea8701296920cc0c4d4e09 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 17 Aug 2021 21:51:29 +0200 Subject: [PATCH 098/126] docs: predictable vs SHA1 upstream names --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 779affa..1ade89a 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,12 @@ If you want most of your virtual hosts to use a default single `location` block #### Per-VIRTUAL_HOST `server_tokens` configuration Per virtual-host `servers_tokens` directive can be configured by passing appropriate value to the `SERVER_TOKENS` environment variable. Please see the [nginx http_core module configuration](https://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens) for more details. +### Unhashed vs SHA1 upstream names + +By default the nginx configuration `upstream` blocks will use this block's corresponding hostname as a predictable name. However, this can cause issues in some setups (see [this issue](https://github.com/nginx-proxy/nginx-proxy/issues/1162)). In those cases you might want to switch to SHA1 names for the `upstream` blocks by setting the `SHA1_UPSTREAM_NAME` environment variable to `true` on the nginx-proxy container. + +Please note that using regular expressions in `VIRTUAL_HOST` will always result in a corresponding `upstream` block with an SHA1 name. + ### Troubleshooting In case you can't access your VIRTUAL_HOST, set `DEBUG=true` in the client container's environment and have a look at the generated nginx configuration file `/etc/nginx/conf.d/default`: From 7dfee13b56e41718053b4a18c47f078785f96dea Mon Sep 17 00:00:00 2001 From: Nahin Khan Date: Mon, 30 Aug 2021 06:44:52 +0300 Subject: [PATCH 099/126] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ade89a..16ac020 100644 --- a/README.md +++ b/README.md @@ -237,7 +237,7 @@ docker run -e VIRTUAL_HOST=foo.bar.com ... [acme-companion](https://github.com/nginx-proxy/acme-companion) is a lightweight companion container for the nginx-proxy. It allows the automated creation/renewal of SSL certificates using the ACME protocol. -Set `DHPARAM_GENERATION` environment variable to `false` to disabled Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` +Set `DHPARAM_GENERATION` environment variable to `false` to disable Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` ```console docker run -e DHPARAM_GENERATION=false .... From 308df38b147dbe93965ccf93a0dd3d2c73144c0e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 31 Aug 2021 04:22:47 +0000 Subject: [PATCH 100/126] chore(deps): bump pytest from 6.2.4 to 6.2.5 in /test/requirements Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.4 to 6.2.5. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.2.4...6.2.5) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 35bdb2b..072ef08 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ backoff==1.11.1 docker-compose==1.29.2 docker==5.0.0 -pytest==6.2.4 +pytest==6.2.5 requests==2.26.0 From 86c194e181f0c96cf15530470b1917056c6dc2ca Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 1 Sep 2021 09:16:14 +0200 Subject: [PATCH 101/126] CI: disable fail-fast --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aabcf25..6be93bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,6 @@ jobs: runs-on: ubuntu-latest strategy: - fail-fast: true matrix: base_docker_image: [alpine, debian] From a1ff28cec80c146172fad1bc50a8f9a87f0552d4 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 1 Sep 2021 09:31:02 +0200 Subject: [PATCH 102/126] CI: ease version check on python docker module --- test/conftest.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index bacdaef..3e0f3af 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -13,6 +13,7 @@ import docker import pytest import requests from _pytest._code.code import ReprExceptionInfo +from distutils.version import LooseVersion from docker.models.containers import Container from requests.packages.urllib3.util.connection import HAS_IPV6 @@ -488,5 +489,5 @@ try: except docker.errors.ImageNotFound: pytest.exit("The docker image 'nginxproxy/nginx-proxy:test' is missing") -if docker.__version__ != "5.0.0": - pytest.exit("This test suite is meant to work with the python docker module v5.0.0") +if LooseVersion(docker.__version__) < LooseVersion("5.0.0"): + pytest.exit("This test suite is meant to work with the python docker module v5.0.0 or later") From 083d86a79d7cf9a88ebe123e8cbe44591ea24c5e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Sep 2021 04:18:54 +0000 Subject: [PATCH 103/126] chore(deps): bump docker from 5.0.0 to 5.0.2 in /test/requirements Bumps [docker](https://github.com/docker/docker-py) from 5.0.0 to 5.0.2. - [Release notes](https://github.com/docker/docker-py/releases) - [Commits](https://github.com/docker/docker-py/compare/5.0.0...5.0.2) --- updated-dependencies: - dependency-name: docker dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 072ef08..2f231f8 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ backoff==1.11.1 docker-compose==1.29.2 -docker==5.0.0 +docker==5.0.2 pytest==6.2.5 requests==2.26.0 From 7b489159b3b664c4a1ffb34252e8f809e6b9415d Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 8 Sep 2021 14:25:56 +0200 Subject: [PATCH 104/126] Use path context --- .github/workflows/dockerhub.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 8eaacf7..5d4cfba 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -57,6 +57,7 @@ jobs: id: docker_build_debian uses: docker/build-push-action@v2 with: + context: . file: Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true @@ -104,6 +105,7 @@ jobs: id: docker_build_alpine uses: docker/build-push-action@v2 with: + context: . file: Dockerfile.alpine platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true From 583c71ec3df557dc7fcfe556fbcede9234037651 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Sep 2021 04:12:34 +0000 Subject: [PATCH 105/126] chore(deps): bump nginx from 1.21.1 to 1.21.3 Bumps nginx from 1.21.1 to 1.21.3. --- updated-dependencies: - dependency-name: nginx dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- Dockerfile.alpine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97c0cc9..1be78d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -36,7 +36,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.21.1 +FROM nginx:1.21.3 LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates diff --git a/Dockerfile.alpine b/Dockerfile.alpine index c08dcc3..ad12ae0 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -37,7 +37,7 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ && rm -rf /go/forego # Build the final image -FROM nginx:1.21.1-alpine +FROM nginx:1.21.3-alpine LABEL maintainer="Nicolas Duchon (@buchdag)" # Install wget and install/updates certificates From dc9876b6c248044ef3f7be7f141fc3773bbde5f9 Mon Sep 17 00:00:00 2001 From: kevinnls <57634663+kevinnls@users.noreply.github.com> Date: Fri, 10 Sep 2021 19:27:33 +0530 Subject: [PATCH 106/126] fix anchor --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16ac020..9e411f0 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The containers being proxied must [expose](https://docs.docker.com/engine/refere Provided your DNS is setup to forward foo.bar.com to the host running nginx-proxy, the request will be routed to a container with the `VIRTUAL_HOST` env var set. -Note: providing a port number in `VIRTUAL_HOST` isn't suported, please see [virtual ports](https://github.com/nginx-proxy/nginx-proxy#virtual-ports) or [custom external HTTP/HTTPS ports](https://github.com/nginx-proxy/nginx-proxy#virtual-ports) depending on what you want to achieve. +Note: providing a port number in `VIRTUAL_HOST` isn't suported, please see [virtual ports](https://github.com/nginx-proxy/nginx-proxy#virtual-ports) or [custom external HTTP/HTTPS ports](https://github.com/nginx-proxy/nginx-proxy#custom-external-httphttps-ports) depending on what you want to achieve. ### Image variants From ac066a73e46e363f48c6628e0fa8cadc35ff6546 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:14:46 +1300 Subject: [PATCH 107/126] feat: Replace generated DH params with RFC 7919 standardized DHE groups - While the anonymous VOLUME can be dropped from Dockerfile, the path needs to be valid at run-time, might as well ensure it's available by creating the dhparam folder at build. - Generation logic no longer necessary, dropped. - Standardized RFC 7919 groups added (2048, 3072, 4096), with 4096-bit remaining the default size. The DH logic can live in the entrypoint script as well. - Third-party supplied pre-generated DH params removed as they're not considered trustworthy compared to RFC 7919 groups. --- Dockerfile | 5 ++-- Dockerfile.alpine | 5 ++-- README.md | 16 ++++--------- dhparam.pem.default | 8 ------- dhparam/ffdhe2048.pem | 8 +++++++ dhparam/ffdhe3072.pem | 11 +++++++++ dhparam/ffdhe4096.pem | 13 +++++++++++ docker-entrypoint.sh | 34 +++++++++++++++++++++++++-- generate-dhparam.sh | 53 ------------------------------------------- 9 files changed, 75 insertions(+), 78 deletions(-) delete mode 100644 dhparam.pem.default create mode 100644 dhparam/ffdhe2048.pem create mode 100644 dhparam/ffdhe3072.pem create mode 100644 dhparam/ffdhe4096.pem delete mode 100755 generate-dhparam.sh diff --git a/Dockerfile b/Dockerfile index 97c0cc9..5642e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,8 @@ RUN apt-get update \ # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ - && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf \ + && mkdir -p '/etc/nginx/dhparam' # Install Forego + docker-gen COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego @@ -69,7 +70,7 @@ WORKDIR /app/ ENV DOCKER_HOST unix:///tmp/docker.sock -VOLUME ["/etc/nginx/certs", "/etc/nginx/dhparam"] +VOLUME ["/etc/nginx/certs"] ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine index c08dcc3..546de81 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -48,7 +48,8 @@ RUN apk add --no-cache --virtual .run-deps \ # Configure Nginx and apply fix for very long server names RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ && sed -i 's/worker_processes 1/worker_processes auto/' /etc/nginx/nginx.conf \ - && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf + && sed -i 's/worker_connections 1024/worker_connections 10240/' /etc/nginx/nginx.conf \ + && mkdir -p '/etc/nginx/dhparam' # Install Forego + docker-gen COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego @@ -66,7 +67,7 @@ WORKDIR /app/ ENV DOCKER_HOST unix:///tmp/docker.sock -VOLUME ["/etc/nginx/certs", "/etc/nginx/dhparam"] +VOLUME ["/etc/nginx/certs"] ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] diff --git a/README.md b/README.md index 9e411f0..2177056 100644 --- a/README.md +++ b/README.md @@ -237,12 +237,6 @@ docker run -e VIRTUAL_HOST=foo.bar.com ... [acme-companion](https://github.com/nginx-proxy/acme-companion) is a lightweight companion container for the nginx-proxy. It allows the automated creation/renewal of SSL certificates using the ACME protocol. -Set `DHPARAM_GENERATION` environment variable to `false` to disable Diffie-Hellman parameters completely. This will also ignore auto-generation made by `nginx-proxy`. The default value is `true` - -```console -docker run -e DHPARAM_GENERATION=false .... -``` - ### SSL Support SSL is supported using single host, wildcard and SNI certificates using naming conventions for certificates or optionally specifying a cert name (for SNI) as an environment variable. @@ -259,13 +253,13 @@ If you are running the container in a virtualized environment (Hyper-V, VirtualB #### Diffie-Hellman Groups -Diffie-Hellman groups are enabled by default, with a pregenerated key in `/etc/nginx/dhparam/dhparam.pem`. You can mount a different `dhparam.pem` file at that location to override the default cert. To use custom `dhparam.pem` files per-virtual-host, the files should be named after the virtual host with a `dhparam` suffix and `.pem` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.dhparam.pem` file in the `/etc/nginx/certs` directory. +[RFC7919 groups](https://datatracker.ietf.org/doc/html/rfc7919#appendix-A) with key lengths of 2048, 3072, and 4096 bits are [provided by `nginx-proxy`](https://github.com/nginx-proxy/nginx-proxy/dhparam). The ENV `DHPARAM_BITS` can be set to `2048` or `3072` to change from the default 4096-bit key. The DH key file will be located in the container at `/etc/nginx/dhparam/dhparam.pem`. Mounting a different `dhparam.pem` file at that location will override the RFC7919 key. -> NOTE: If you don't mount a `dhparam.pem` file at `/etc/nginx/dhparam/dhparam.pem`, one will be generated at startup. Since it can take minutes to generate a new `dhparam.pem`, it is done at low priority in the background. Once generation is complete, the `dhparam.pem` is saved on a persistent volume and nginx is reloaded. This generation process only occurs the first time you start `nginx-proxy`. +To use custom `dhparam.pem` files per-virtual-host, the files should be named after the virtual host with a `dhparam` suffix and `.pem` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.dhparam.pem` file in the `/etc/nginx/certs` directory. -> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these clients, you must either provide your own `dhparam.pem`, or tell `nginx-proxy` to generate a 1024-bit key on startup by passing `-e DHPARAM_BITS=1024`. +> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these clients, you must either provide your own `dhparam.pem`. -In the separate container setup, no pregenerated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will generate one. If you still want A+ security in a separate container setup, you'll have to generate a 2048 or 4096 bits DH key file manually and mount it on the nginx container, at `/etc/nginx/dhparam/dhparam.pem`. +In the separate container setup, no pre-generated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image, nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will provide one. If you still want A+ security in a separate container setup, you should mount an RFC7919 DH key file to the nginx container at `/etc/nginx/dhparam/dhparam.pem`. #### Wildcard Certificates @@ -287,7 +281,7 @@ If you don't require backward compatibility, you can use the [Mozilla modern pro Other policies available through the `SSL_POLICY` environment variable are [`Mozilla-Old`](https://wiki.mozilla.org/Security/Server_Side_TLS#Old_backward_compatibility) and the [AWS ELB Security Policies](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-security-policy-table.html) `AWS-TLS-1-2-2017-01`, `AWS-TLS-1-1-2017-01`, `AWS-2016-08`, `AWS-2015-05`, `AWS-2015-03` and `AWS-2015-02`. -Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container generates a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing this, either globally or per virtual-host. +Note that the `Mozilla-Old` policy should use a 1024 bits DH key for compatibility but this container provides a 4096 bits key. The [Diffie-Hellman Groups](#diffie-hellman-groups) section details different methods of bypassing this, either globally or per virtual-host. The default behavior for the proxy when port 80 and 443 are exposed is as follows: diff --git a/dhparam.pem.default b/dhparam.pem.default deleted file mode 100644 index 8548c34..0000000 --- a/dhparam.pem.default +++ /dev/null @@ -1,8 +0,0 @@ ------BEGIN DH PARAMETERS----- -MIIBCAKCAQEAzB2nIGzpVq7afJnKBm1X0d64avwOlP2oneiKwxRHdDI/5+6TpH1P -F8ipodGuZBUMmupoB3D34pu2Qq5boNW983sm18ww9LMz2i/pxhSdB+mYAew+A6h6 -ltQ5pNtyn4NaKw1SDFkqvde3GNPhaWoPDbZDJhpHGblR3w1b/ag+lTLZUvVwcD8L -jYS9f9YWAC6T7WxAxh4zvu1Z0I1EKde8KYBxrreZNheXpXHqMNyJYZCaY2Hb/4oI -EL65qZq1GCWezpWMjhk6pOnV5gbvqfhoazCv/4OdRv6RoWOIYBNs9BmGho4AtXqV -FYLdYDhOvN4aVs9Ir+G8ouwiRnix24+UewIBAg== ------END DH PARAMETERS----- diff --git a/dhparam/ffdhe2048.pem b/dhparam/ffdhe2048.pem new file mode 100644 index 0000000..088f967 --- /dev/null +++ b/dhparam/ffdhe2048.pem @@ -0,0 +1,8 @@ +-----BEGIN DH PARAMETERS----- +MIIBCAKCAQEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz ++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a +87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 +YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi +7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD +ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== +-----END DH PARAMETERS----- \ No newline at end of file diff --git a/dhparam/ffdhe3072.pem b/dhparam/ffdhe3072.pem new file mode 100644 index 0000000..603f529 --- /dev/null +++ b/dhparam/ffdhe3072.pem @@ -0,0 +1,11 @@ +-----BEGIN DH PARAMETERS----- +MIIBiAKCAYEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz ++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a +87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 +YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi +7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD +ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3 +7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32 +nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZsYu +N///////////AgEC +-----END DH PARAMETERS----- \ No newline at end of file diff --git a/dhparam/ffdhe4096.pem b/dhparam/ffdhe4096.pem new file mode 100644 index 0000000..eed4c41 --- /dev/null +++ b/dhparam/ffdhe4096.pem @@ -0,0 +1,13 @@ +-----BEGIN DH PARAMETERS----- +MIICCAKCAgEA//////////+t+FRYortKmq/cViAnPTzx2LnFg84tNpWp4TZBFGQz ++8yTnc4kmz75fS/jY2MMddj2gbICrsRhetPfHtXV/WVhJDP1H18GbtCFY2VVPe0a +87VXE15/V8k1mE8McODmi3fipona8+/och3xWKE2rec1MKzKT0g6eXq8CrGCsyT7 +YdEIqUuyyOP7uWrat2DX9GgdT0Kj3jlN9K5W7edjcrsZCwenyO4KbXCeAvzhzffi +7MA0BM0oNC9hkXL+nOmFg/+OTxIy7vKBg8P+OxtMb61zO7X8vC7CIAXFjvGDfRaD +ssbzSibBsu/6iGtCOGEfz9zeNVs7ZRkDW7w09N75nAI4YbRvydbmyQd62R0mkff3 +7lmMsPrBhtkcrv4TCYUTknC0EwyTvEN5RPT9RFLi103TZPLiHnH1S/9croKrnJ32 +nuhtK8UiNjoNq8Uhl5sN6todv5pC1cRITgq80Gv6U93vPBsg7j/VnXwl5B0rZp4e +8W5vUsMWTfT7eTDp5OWIV7asfV9C1p9tGHdjzx1VA0AEh/VbpX4xzHpxNciG77Qx +iu1qHgEtnmgyqQdgCpGBMMRtx3j5ca0AOAkpmaMzy4t6Gh25PXFAADwqTs6p+Y0K +zAqCkc3OyX3Pjsm1Wn+IpGtNtahR9EGC4caKAH5eZV9q//////////8CAQI= +-----END DH PARAMETERS----- \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 0e42880..a56d8b8 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,6 +1,37 @@ #!/bin/bash set -e +function _setup_dhparam() { + echo 'Setting up DH Parameters..' + + # DH params will be supplied for nginx here: + DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' + + # DH params may be provided by the user (rarely necessary), + # or use an existing pre-generated group from RFC7919, defaulting to 4096-bit: + if [[ -f ${DHPARAM_FILE} ]] + then + echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 + else + # ENV DHPARAM_BITS - Defines which RFC7919 DHE group to use (default: 4096-bit): + local FFDHE_GROUP="${DHPARAM_BITS:-4096}" + # RFC7919 groups are defined here: + # https://datatracker.ietf.org/doc/html/rfc7919#appendix-A + local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" + + # Only the following pre-generated sizes are supported, + # emit an error and kill the container if provided an invalid value: + if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]] + then + echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}, use 2048, 3072, or 4096 (default)." >&2 + exit 1 + fi + + # Provide the DH params file to nginx: + cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}" + fi +} + # Warn if the DOCKER_HOST socket does not exist if [[ $DOCKER_HOST = unix://* ]]; then socket_file=${DOCKER_HOST#unix://} @@ -14,8 +45,7 @@ if [[ $DOCKER_HOST = unix://* ]]; then fi fi -# Generate dhparam file if required -/app/generate-dhparam.sh +_setup_dhparam # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS diff --git a/generate-dhparam.sh b/generate-dhparam.sh deleted file mode 100755 index 397fab0..0000000 --- a/generate-dhparam.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -e - -# DHPARAM_BITS is the bit depth of the dhparam, or 4096 if unspecified -DHPARAM_BITS=${DHPARAM_BITS:-4096} -# DHPARAM_GENERATION=false skips dhparam generation -DHPARAM_GENERATION=${DHPARAM_GENERATION:-true} - -# If a dhparam file is not available, use the pre-generated one and generate a new one in the background. -# Note that /etc/nginx/dhparam is a volume, so this dhparam will persist restarts. -PREGEN_DHPARAM_FILE="/app/dhparam.pem.default" -DHPARAM_FILE="/etc/nginx/dhparam/dhparam.pem" -GEN_LOCKFILE="/tmp/dhparam_generating.lock" - -# The hash of the pregenerated dhparam file is used to check if the pregen dhparam is already in use -PREGEN_HASH=$(md5sum $PREGEN_DHPARAM_FILE | cut -d" " -f1) -if [[ -f $DHPARAM_FILE ]]; then - CURRENT_HASH=$(md5sum $DHPARAM_FILE | cut -d" " -f1) - if [[ $PREGEN_HASH != "$CURRENT_HASH" ]]; then - # There is already a dhparam, and it's not the default - echo "Custom dhparam.pem file found, generation skipped" - exit 0 - fi - - if [[ -f $GEN_LOCKFILE ]]; then - # Generation is already in progress - exit 0 - fi -fi - -if [[ $DHPARAM_GENERATION =~ ^[Ff][Aa][Ll][Ss][Ee]$ ]]; then - echo "Skipping Diffie-Hellman parameters generation and Ignoring pre-generated dhparam.pem" - exit 0 -fi - -cat >&2 <<-EOT -WARNING: $DHPARAM_FILE was not found. A pre-generated dhparam.pem will be used for now while a new one -is being generated in the background. Once the new dhparam.pem is in place, nginx will be reloaded. -EOT - -# Put the default dhparam file in place so we can start immediately -cp $PREGEN_DHPARAM_FILE $DHPARAM_FILE -touch $GEN_LOCKFILE - -# Generate a new dhparam in the background in a low priority and reload nginx when finished (grep removes the progress indicator). -( - ( - nice -n +5 openssl dhparam -dsaparam -out $DHPARAM_FILE.tmp "$DHPARAM_BITS" 2>&1 \ - && mv $DHPARAM_FILE.tmp $DHPARAM_FILE \ - && echo "dhparam generation complete, reloading nginx" \ - && nginx -s reload - ) | grep -vE '^[\.+]+' - rm $GEN_LOCKFILE -) & disown From 8aacd13241f7bd4e4110bcbf351a0ded422a730a Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 15:36:07 +1200 Subject: [PATCH 108/126] chore: 1/6 - Inline failure at it's cause This change has been split into 6 iterative parts/commits to ease the review process. --- docker-entrypoint.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a56d8b8..95e1fad 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -41,7 +41,11 @@ if [[ $DOCKER_HOST = unix://* ]]; then Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` See the documentation at http://git.io/vZaGJ EOT - socketMissing=1 + + # If the user has run the default command and the socket doesn't exist, fail + if [ "$1" = forego ] && [ "$2" = start ] && [ "$3" = '-r' ]; then + exit 1 + fi fi fi @@ -61,9 +65,4 @@ elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS fi -# If the user has run the default command and the socket doesn't exist, fail -if [ "$socketMissing" = 1 ] && [ "$1" = forego ] && [ "$2" = start ] && [ "$3" = '-r' ]; then - exit 1 -fi - exec "$@" From 2e6d7561a3cc5d50577f94f8b3e5a824d9b1c6b4 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:11:49 +1300 Subject: [PATCH 109/126] chore: 2/6 - Handle CMD check early, wrap init logic into a function --- docker-entrypoint.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 95e1fad..aa7ed96 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -32,6 +32,7 @@ function _setup_dhparam() { fi } +function _init() { # Warn if the DOCKER_HOST socket does not exist if [[ $DOCKER_HOST = unix://* ]]; then socket_file=${DOCKER_HOST#unix://} @@ -41,11 +42,9 @@ if [[ $DOCKER_HOST = unix://* ]]; then Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` See the documentation at http://git.io/vZaGJ EOT - - # If the user has run the default command and the socket doesn't exist, fail - if [ "$1" = forego ] && [ "$2" = start ] && [ "$3" = '-r' ]; then - exit 1 - fi + + exit 1 + fi fi @@ -64,5 +63,11 @@ elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then echo "$RESOLVERS" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2 RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS fi +} + +# Run the init logic if the default CMD was provided +if [[ $* == 'forego start -r' ]]; then + _init +fi exec "$@" From 091dd855afca83b727253d32e347bcf0948a2d56 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 15:47:20 +1200 Subject: [PATCH 110/126] chore: 3/6 - Indent function content This is a white-space only change to ease review diff noise. --- docker-entrypoint.sh | 47 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index aa7ed96..680fdf1 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -33,36 +33,35 @@ function _setup_dhparam() { } function _init() { -# Warn if the DOCKER_HOST socket does not exist -if [[ $DOCKER_HOST = unix://* ]]; then - socket_file=${DOCKER_HOST#unix://} - if ! [ -S "$socket_file" ]; then - cat >&2 <<-EOT - ERROR: you need to share your Docker host socket with a volume at $socket_file - Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` - See the documentation at http://git.io/vZaGJ - EOT - - exit 1 + # Warn if the DOCKER_HOST socket does not exist + if [[ $DOCKER_HOST = unix://* ]]; then + socket_file=${DOCKER_HOST#unix://} + if ! [ -S "$socket_file" ]; then + cat >&2 <<-EOT + ERROR: you need to share your Docker host socket with a volume at $socket_file + Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` + See the documentation at http://git.io/vZaGJ + EOT + exit 1 + fi fi -fi -_setup_dhparam + _setup_dhparam -# Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] -RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS + # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] + RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS -SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]" + SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]" -if [ "$RESOLVERS" = "" ]; then - echo "Warning: unable to determine DNS resolvers for nginx" >&2 - unset RESOLVERS -elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then - echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2 - echo "$RESOLVERS" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2 - RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS -fi + if [ "$RESOLVERS" = "" ]; then + echo "Warning: unable to determine DNS resolvers for nginx" >&2 + unset RESOLVERS + elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then + echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2 + echo "$RESOLVERS" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2 + RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS + fi } # Run the init logic if the default CMD was provided From ed009c0ec85080eff81458fe12f82e012ad08459 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 20:48:41 +1300 Subject: [PATCH 111/126] chore: 4/6 - Extract grouped logic to their own methods --- docker-entrypoint.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 680fdf1..7b21e36 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -32,7 +32,7 @@ function _setup_dhparam() { fi } -function _init() { +function _check_unix_socket() { # Warn if the DOCKER_HOST socket does not exist if [[ $DOCKER_HOST = unix://* ]]; then socket_file=${DOCKER_HOST#unix://} @@ -46,9 +46,9 @@ function _init() { exit 1 fi fi +} - _setup_dhparam - +function _resolvers() { # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS @@ -66,7 +66,11 @@ function _init() { # Run the init logic if the default CMD was provided if [[ $* == 'forego start -r' ]]; then - _init + _check_unix_socket + + _resolvers + + _setup_dhparam fi exec "$@" From 0f330b85b10b05355e4bddd2183e8a3e69d7ad1a Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 20:57:03 +1300 Subject: [PATCH 112/126] chore: 5/6 - Shift dhparam method to the bottom Minor change on error message. --- docker-entrypoint.sh | 62 ++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7b21e36..bcc8f1b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,37 +1,6 @@ #!/bin/bash set -e -function _setup_dhparam() { - echo 'Setting up DH Parameters..' - - # DH params will be supplied for nginx here: - DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' - - # DH params may be provided by the user (rarely necessary), - # or use an existing pre-generated group from RFC7919, defaulting to 4096-bit: - if [[ -f ${DHPARAM_FILE} ]] - then - echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 - else - # ENV DHPARAM_BITS - Defines which RFC7919 DHE group to use (default: 4096-bit): - local FFDHE_GROUP="${DHPARAM_BITS:-4096}" - # RFC7919 groups are defined here: - # https://datatracker.ietf.org/doc/html/rfc7919#appendix-A - local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" - - # Only the following pre-generated sizes are supported, - # emit an error and kill the container if provided an invalid value: - if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]] - then - echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}, use 2048, 3072, or 4096 (default)." >&2 - exit 1 - fi - - # Provide the DH params file to nginx: - cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}" - fi -} - function _check_unix_socket() { # Warn if the DOCKER_HOST socket does not exist if [[ $DOCKER_HOST = unix://* ]]; then @@ -64,6 +33,37 @@ function _resolvers() { fi } +function _setup_dhparam() { + echo 'Setting up DH Parameters..' + + # DH params will be supplied for nginx here: + DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' + + # DH params may be provided by the user (rarely necessary), + # or use an existing pre-generated group from RFC7919, defaulting to 4096-bit: + if [[ -f ${DHPARAM_FILE} ]] + then + echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 + else + # ENV DHPARAM_BITS - Defines which RFC7919 DHE group to use (default: 4096-bit): + local FFDHE_GROUP="${DHPARAM_BITS:-4096}" + # RFC7919 groups are defined here: + # https://datatracker.ietf.org/doc/html/rfc7919#appendix-A + local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" + + # Only the following pre-generated sizes are supported, + # emit an error and kill the container if provided an invalid value: + if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]] + then + echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}, use 2048, 3072, or 4096 (default)." >&2 + exit 1 + fi + + # Provide the DH params file to nginx: + cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}" + fi +} + # Run the init logic if the default CMD was provided if [[ $* == 'forego start -r' ]]; then _check_unix_socket From 6f7eb8bd97de5db8fbe1f22d8291288bc595697e Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 16:06:11 +1200 Subject: [PATCH 113/126] chore: 6/6 - Update shell syntax - `==` for string equality since we're using bash `[[ test ]]` already. - Uppercase `socket_file` variable to be consistent with other internal variables used in the script. - Convert `[ test ]` to `[[ test ]]` for consistency, improving maintenance. Double-bracket (_not posix compatible_) does not require quoted variables, ShellCheck lint knows this is safe too :) - `-z` test for `$RESOLVERS` is native syntax to check for empty string value. - Referenced variables should generally be wrapped like so `"${VAR}"`. - Variable assignments with string values should be double quotes for content with variables, otherwise use single quotes (_no interpolation_). - Converted my if statements to use the same style used in the rest of the file. --- docker-entrypoint.sh | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index bcc8f1b..bbdcdd9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -3,12 +3,13 @@ set -e function _check_unix_socket() { # Warn if the DOCKER_HOST socket does not exist - if [[ $DOCKER_HOST = unix://* ]]; then - socket_file=${DOCKER_HOST#unix://} - if ! [ -S "$socket_file" ]; then + if [[ ${DOCKER_HOST} == unix://* ]]; then + local SOCKET_FILE="${DOCKER_HOST#unix://}" + + if [[ ! -S ${SOCKET_FILE} ]]; then cat >&2 <<-EOT - ERROR: you need to share your Docker host socket with a volume at $socket_file - Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:$socket_file:ro\` + ERROR: you need to share your Docker host socket with a volume at ${SOCKET_FILE} + Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:${SOCKET_FILE}:ro\` See the documentation at http://git.io/vZaGJ EOT @@ -21,15 +22,15 @@ function _resolvers() { # Compute the DNS resolvers for use in the templates - if the IP contains ":", it's IPv6 and must be enclosed in [] RESOLVERS=$(awk '$1 == "nameserver" {print ($2 ~ ":")? "["$2"]": $2}' ORS=' ' /etc/resolv.conf | sed 's/ *$//g'); export RESOLVERS - SCOPED_IPV6_REGEX="\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]" + SCOPED_IPV6_REGEX='\[fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}\]' - if [ "$RESOLVERS" = "" ]; then - echo "Warning: unable to determine DNS resolvers for nginx" >&2 + if [[ -z ${RESOLVERS} ]]; then + echo 'Warning: unable to determine DNS resolvers for nginx' >&2 unset RESOLVERS - elif [[ $RESOLVERS =~ $SCOPED_IPV6_REGEX ]]; then - echo -n "Warning: Scoped IPv6 addresses removed from resolvers: " >&2 - echo "$RESOLVERS" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2 - RESOLVERS=$(echo "$RESOLVERS" | sed -r "s/$SCOPED_IPV6_REGEX//g" | xargs echo -n); export RESOLVERS + elif [[ ${RESOLVERS} =~ ${SCOPED_IPV6_REGEX} ]]; then + echo -n 'Warning: Scoped IPv6 addresses removed from resolvers: ' >&2 + echo "${RESOLVERS}" | grep -Eo "$SCOPED_IPV6_REGEX" | paste -s -d ' ' >&2 + RESOLVERS=$(echo "${RESOLVERS}" | sed -r "s/${SCOPED_IPV6_REGEX}//g" | xargs echo -n); export RESOLVERS fi } @@ -41,8 +42,7 @@ function _setup_dhparam() { # DH params may be provided by the user (rarely necessary), # or use an existing pre-generated group from RFC7919, defaulting to 4096-bit: - if [[ -f ${DHPARAM_FILE} ]] - then + if [[ -f ${DHPARAM_FILE} ]]; then echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 else # ENV DHPARAM_BITS - Defines which RFC7919 DHE group to use (default: 4096-bit): @@ -53,9 +53,8 @@ function _setup_dhparam() { # Only the following pre-generated sizes are supported, # emit an error and kill the container if provided an invalid value: - if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]] - then - echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}, use 2048, 3072, or 4096 (default)." >&2 + if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then + echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default)." >&2 exit 1 fi From a7a2d6e44b8331fc5f1a9f98e2148bbc45ae5e35 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 16:29:03 +1200 Subject: [PATCH 114/126] chore: Use direct URL instead of URL shortener Implicit URL is unnecessary (_and presently relies on Github redirecting from it's original mapped URL_). Use an explicit URL instead to reduce the guesswork/trust of where the shortener was going to redirect to. --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index bbdcdd9..b4dbd2c 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -10,7 +10,7 @@ function _check_unix_socket() { cat >&2 <<-EOT ERROR: you need to share your Docker host socket with a volume at ${SOCKET_FILE} Typically you should run your nginxproxy/nginx-proxy with: \`-v /var/run/docker.sock:${SOCKET_FILE}:ro\` - See the documentation at http://git.io/vZaGJ + See the documentation at: https://github.com/nginx-proxy/nginx-proxy/#usage EOT exit 1 From 004e4a5cda916b3759c89a1e9e201853c49b822b Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sun, 26 Sep 2021 16:51:37 +1300 Subject: [PATCH 115/126] chore: Refactor `_setup_dh()` - `DHPARAM_FILE` is a local var not intended for overriding via ENV. Clarified that with `local` declaration. - `FFDHE_GROUP` var uses default assignment (_`:=4096` instead of only substitute `:-4096`_), so that `DHPARAM_BITS` retains the default 4096 value in subsequent references if no custom size was provided. - Refactored the conditional statements to only handle early failure conditions. Shifting out the RFC7919 support that can run after all checks have passed. - Revised comments. --- docker-entrypoint.sh | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index b4dbd2c..2dba7ea 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -38,29 +38,25 @@ function _setup_dhparam() { echo 'Setting up DH Parameters..' # DH params will be supplied for nginx here: - DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' + local DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' - # DH params may be provided by the user (rarely necessary), - # or use an existing pre-generated group from RFC7919, defaulting to 4096-bit: + # Should be 2048, 3072, or 4096 (default): + local FFDHE_GROUP="${DHPARAM_BITS:=4096}" + + # DH params may be provided by the user (rarely necessary) if [[ -f ${DHPARAM_FILE} ]]; then echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 - else - # ENV DHPARAM_BITS - Defines which RFC7919 DHE group to use (default: 4096-bit): - local FFDHE_GROUP="${DHPARAM_BITS:-4096}" - # RFC7919 groups are defined here: - # https://datatracker.ietf.org/doc/html/rfc7919#appendix-A - local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" - - # Only the following pre-generated sizes are supported, - # emit an error and kill the container if provided an invalid value: - if [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then - echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default)." >&2 - exit 1 - fi - - # Provide the DH params file to nginx: - cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}" + return 0 + elif [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then + echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default)." >&2 + exit 1 fi + + # Use an existing pre-generated DH group from RFC7919 (https://datatracker.ietf.org/doc/html/rfc7919#appendix-A): + local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" + + # Provide the DH params file to nginx: + cp "${RFC7919_DHPARAM_FILE}" "${DHPARAM_FILE}" } # Run the init logic if the default CMD was provided From 9299a2801e694a843e50bb36ac300ed73def7a50 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 17:42:27 +1200 Subject: [PATCH 116/126] tests: Remove dhparam volume No longer necessary for the majority of tests. --- test/test_DOCKER_HOST_unix_socket.yml | 1 - test/test_composev2.yml | 1 - test/test_custom/test_defaults-location.yml | 1 - test/test_custom/test_defaults.yml | 1 - test/test_custom/test_location-per-vhost.yml | 1 - test/test_custom/test_per-vhost.yml | 1 - test/test_custom/test_proxy-wide.yml | 1 - test/test_debug/test_proxy-debug-flag.yml | 1 - test/test_debug/test_server-debug-flag.yml | 1 - test/test_default-host.yml | 1 - test/test_dockergen/test_dockergen_v2.yml | 1 - test/test_dockergen/test_dockergen_v3.yml | 1 - test/test_events.yml | 1 - test/test_headers/test_http.yml | 1 - test/test_headers/test_https.yml | 1 - test/test_http_port.yml | 1 - test/test_ipv6.yml | 1 - test/test_multiple-hosts.yml | 1 - test/test_multiple-networks.yml | 1 - .../test_VIRTUAL_PORT-single-different-from-single-port.yml | 1 - test/test_multiple-ports/test_VIRTUAL_PORT.yml | 1 - test/test_multiple-ports/test_default-80.yml | 1 - test/test_multiple-ports/test_single-port-not-80.yml | 1 - test/test_nominal.yml | 1 - test/test_raw-ip-vhost.yml | 1 - test/test_server-down/test_load-balancing.yml | 1 - test/test_server-down/test_no-server-down.yml | 1 - test/test_server-down/test_server-down.yml | 1 - test/test_ssl/test_hsts.yml | 1 - test/test_ssl/test_https_port.yml | 1 - test/test_ssl/test_nohttp.yml | 1 - test/test_ssl/test_nohttps.yml | 1 - test/test_ssl/test_noredirect.yml | 1 - test/test_ssl/test_wildcard.yml | 1 - test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml | 1 - test/test_upstream-name/test_predictable-name.yml | 1 - test/test_upstream-name/test_sha1-name.yml | 1 - test/test_wildcard_host.yml | 1 - 38 files changed, 38 deletions(-) diff --git a/test/test_DOCKER_HOST_unix_socket.yml b/test/test_DOCKER_HOST_unix_socket.yml index d1aba4b..1563872 100644 --- a/test/test_DOCKER_HOST_unix_socket.yml +++ b/test/test_DOCKER_HOST_unix_socket.yml @@ -19,6 +19,5 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/f00.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: DOCKER_HOST: unix:///f00.sock diff --git a/test/test_composev2.yml b/test/test_composev2.yml index 283e070..4a0c9fa 100644 --- a/test/test_composev2.yml +++ b/test/test_composev2.yml @@ -4,7 +4,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro web: image: web diff --git a/test/test_custom/test_defaults-location.yml b/test/test_custom/test_defaults-location.yml index 3069273..8b185f7 100644 --- a/test/test_custom/test_defaults-location.yml +++ b/test/test_custom/test_defaults-location.yml @@ -2,7 +2,6 @@ nginx-proxy: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/default_location:ro - ./my_custom_proxy_settings_bar.conf:/etc/nginx/vhost.d/web3.nginx-proxy.local_location:ro diff --git a/test/test_custom/test_defaults.yml b/test/test_custom/test_defaults.yml index 165264c..6086f40 100644 --- a/test/test_custom/test_defaults.yml +++ b/test/test_custom/test_defaults.yml @@ -4,7 +4,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./my_custom_proxy_settings.conf:/etc/nginx/proxy.conf:ro web1: diff --git a/test/test_custom/test_location-per-vhost.yml b/test/test_custom/test_location-per-vhost.yml index 3622325..99f31f3 100644 --- a/test/test_custom/test_location-per-vhost.yml +++ b/test/test_custom/test_location-per-vhost.yml @@ -4,7 +4,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/web1.nginx-proxy.local_location:ro web1: diff --git a/test/test_custom/test_per-vhost.yml b/test/test_custom/test_per-vhost.yml index 256c207..5eba9f6 100644 --- a/test/test_custom/test_per-vhost.yml +++ b/test/test_custom/test_per-vhost.yml @@ -4,7 +4,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./my_custom_proxy_settings.conf:/etc/nginx/vhost.d/web1.nginx-proxy.local:ro web1: diff --git a/test/test_custom/test_proxy-wide.yml b/test/test_custom/test_proxy-wide.yml index 1715b8b..0cd6c40 100644 --- a/test/test_custom/test_proxy-wide.yml +++ b/test/test_custom/test_proxy-wide.yml @@ -4,7 +4,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./my_custom_proxy_settings.conf:/etc/nginx/conf.d/my_custom_proxy_settings.conf:ro web1: diff --git a/test/test_debug/test_proxy-debug-flag.yml b/test/test_debug/test_proxy-debug-flag.yml index e7af54c..f930da3 100644 --- a/test/test_debug/test_proxy-debug-flag.yml +++ b/test/test_debug/test_proxy-debug-flag.yml @@ -22,6 +22,5 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: DEBUG: "true" diff --git a/test/test_debug/test_server-debug-flag.yml b/test/test_debug/test_server-debug-flag.yml index 0256cf8..89bb6b5 100644 --- a/test/test_debug/test_server-debug-flag.yml +++ b/test/test_debug/test_server-debug-flag.yml @@ -23,4 +23,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_default-host.yml b/test/test_default-host.yml index 47b8525..2cb94d9 100644 --- a/test/test_default-host.yml +++ b/test/test_default-host.yml @@ -13,6 +13,5 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: DEFAULT_HOST: web1.tld diff --git a/test/test_dockergen/test_dockergen_v2.yml b/test/test_dockergen/test_dockergen_v2.yml index 0fc8af5..919461d 100644 --- a/test/test_dockergen/test_dockergen_v2.yml +++ b/test/test_dockergen/test_dockergen_v2.yml @@ -6,7 +6,6 @@ services: container_name: nginx volumes: - /etc/nginx/conf.d - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro dockergen: image: jwilder/docker-gen diff --git a/test/test_dockergen/test_dockergen_v3.yml b/test/test_dockergen/test_dockergen_v3.yml index fad145a..5bc4bff 100644 --- a/test/test_dockergen/test_dockergen_v3.yml +++ b/test/test_dockergen/test_dockergen_v3.yml @@ -5,7 +5,6 @@ services: container_name: nginx volumes: - nginx_conf:/etc/nginx/conf.d - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro dockergen: image: jwilder/docker-gen diff --git a/test/test_events.yml b/test/test_events.yml index dcaaafc..260529e 100644 --- a/test/test_events.yml +++ b/test/test_events.yml @@ -2,4 +2,3 @@ nginxproxy: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_headers/test_http.yml b/test/test_headers/test_http.yml index 0e3880d..93795dc 100644 --- a/test/test_headers/test_http.yml +++ b/test/test_headers/test_http.yml @@ -20,4 +20,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_headers/test_https.yml b/test/test_headers/test_https.yml index c0c67b4..49dcec4 100644 --- a/test/test_headers/test_https.yml +++ b/test/test_headers/test_https.yml @@ -26,4 +26,3 @@ sut: - ./certs/web.nginx-proxy.tld.key:/etc/nginx/certs/web.nginx-proxy.tld.key:ro - ./certs/web-server-tokens-off.nginx-proxy.tld.crt:/etc/nginx/certs/web-server-tokens-off.nginx-proxy.tld.crt:ro - ./certs/web-server-tokens-off.nginx-proxy.tld.key:/etc/nginx/certs/web-server-tokens-off.nginx-proxy.tld.key:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_http_port.yml b/test/test_http_port.yml index a7fa0eb..72f142f 100644 --- a/test/test_http_port.yml +++ b/test/test_http_port.yml @@ -10,6 +10,5 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: HTTP_PORT: 8080 \ No newline at end of file diff --git a/test/test_ipv6.yml b/test/test_ipv6.yml index c98c17e..4dce515 100644 --- a/test/test_ipv6.yml +++ b/test/test_ipv6.yml @@ -33,7 +33,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: ENABLE_IPV6: "true" networks: diff --git a/test/test_multiple-hosts.yml b/test/test_multiple-hosts.yml index bdc2804..b72da83 100644 --- a/test/test_multiple-hosts.yml +++ b/test/test_multiple-hosts.yml @@ -11,4 +11,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-networks.yml b/test/test_multiple-networks.yml index 1cc6d30..e4548b5 100644 --- a/test/test_multiple-networks.yml +++ b/test/test_multiple-networks.yml @@ -9,7 +9,6 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro networks: - net1 - net2 diff --git a/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml index e28a481..dff6212 100644 --- a/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml +++ b/test/test_multiple-ports/test_VIRTUAL_PORT-single-different-from-single-port.yml @@ -12,4 +12,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_VIRTUAL_PORT.yml b/test/test_multiple-ports/test_VIRTUAL_PORT.yml index 3ee2d1a..1a3ecaa 100644 --- a/test/test_multiple-ports/test_VIRTUAL_PORT.yml +++ b/test/test_multiple-ports/test_VIRTUAL_PORT.yml @@ -12,4 +12,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_default-80.yml b/test/test_multiple-ports/test_default-80.yml index ca61286..10047dc 100644 --- a/test/test_multiple-ports/test_default-80.yml +++ b/test/test_multiple-ports/test_default-80.yml @@ -11,4 +11,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_multiple-ports/test_single-port-not-80.yml b/test/test_multiple-ports/test_single-port-not-80.yml index fbb5b6a..18b3655 100644 --- a/test/test_multiple-ports/test_single-port-not-80.yml +++ b/test/test_multiple-ports/test_single-port-not-80.yml @@ -11,4 +11,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_nominal.yml b/test/test_nominal.yml index 2b62d04..fe02034 100644 --- a/test/test_nominal.yml +++ b/test/test_nominal.yml @@ -33,6 +33,5 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro networks: - net1 diff --git a/test/test_raw-ip-vhost.yml b/test/test_raw-ip-vhost.yml index e265d74..066dade 100644 --- a/test/test_raw-ip-vhost.yml +++ b/test/test_raw-ip-vhost.yml @@ -41,7 +41,6 @@ services: ENABLE_IPV6: "true" volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro networks: net1: ipv4_address: 172.20.0.4 diff --git a/test/test_server-down/test_load-balancing.yml b/test/test_server-down/test_load-balancing.yml index b7162d1..d420072 100644 --- a/test/test_server-down/test_load-balancing.yml +++ b/test/test_server-down/test_load-balancing.yml @@ -27,4 +27,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_server-down/test_no-server-down.yml b/test/test_server-down/test_no-server-down.yml index 2f99f05..b3d4629 100644 --- a/test/test_server-down/test_no-server-down.yml +++ b/test/test_server-down/test_no-server-down.yml @@ -10,4 +10,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_server-down/test_server-down.yml b/test/test_server-down/test_server-down.yml index fc20e85..938d26a 100644 --- a/test/test_server-down/test_server-down.yml +++ b/test/test_server-down/test_server-down.yml @@ -11,4 +11,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_hsts.yml b/test/test_ssl/test_hsts.yml index 779dc07..b4af3b6 100644 --- a/test/test_ssl/test_hsts.yml +++ b/test/test_ssl/test_hsts.yml @@ -38,5 +38,4 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro diff --git a/test/test_ssl/test_https_port.yml b/test/test_ssl/test_https_port.yml index adcf2a8..7b674d7 100644 --- a/test/test_ssl/test_https_port.yml +++ b/test/test_ssl/test_https_port.yml @@ -10,7 +10,6 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro environment: HTTP_PORT: 8080 diff --git a/test/test_ssl/test_nohttp.yml b/test/test_ssl/test_nohttp.yml index 7a7ea08..48a7aa3 100644 --- a/test/test_ssl/test_nohttp.yml +++ b/test/test_ssl/test_nohttp.yml @@ -12,5 +12,4 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro diff --git a/test/test_ssl/test_nohttps.yml b/test/test_ssl/test_nohttps.yml index 0a6a9a5..3f3df19 100644 --- a/test/test_ssl/test_nohttps.yml +++ b/test/test_ssl/test_nohttps.yml @@ -12,4 +12,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_ssl/test_noredirect.yml b/test/test_ssl/test_noredirect.yml index 9ac7169..ecd93f6 100644 --- a/test/test_ssl/test_noredirect.yml +++ b/test/test_ssl/test_noredirect.yml @@ -12,5 +12,4 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro diff --git a/test/test_ssl/test_wildcard.yml b/test/test_ssl/test_wildcard.yml index 6168084..e1504ed 100644 --- a/test/test_ssl/test_wildcard.yml +++ b/test/test_ssl/test_wildcard.yml @@ -10,5 +10,4 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro diff --git a/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml b/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml index 6257aee..98f41a0 100644 --- a/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml +++ b/test/test_ssl/wildcard_cert_and_nohttps/docker-compose.yml @@ -7,7 +7,6 @@ services: volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./certs:/etc/nginx/certs:ro - - ../../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro web1: image: web diff --git a/test/test_upstream-name/test_predictable-name.yml b/test/test_upstream-name/test_predictable-name.yml index 1265230..cd8d250 100644 --- a/test/test_upstream-name/test_predictable-name.yml +++ b/test/test_upstream-name/test_predictable-name.yml @@ -13,4 +13,3 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro diff --git a/test/test_upstream-name/test_sha1-name.yml b/test/test_upstream-name/test_sha1-name.yml index d2095f3..54989ae 100644 --- a/test/test_upstream-name/test_sha1-name.yml +++ b/test/test_upstream-name/test_sha1-name.yml @@ -13,6 +13,5 @@ services: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro environment: SHA1_UPSTREAM_NAME: "true" diff --git a/test/test_wildcard_host.yml b/test/test_wildcard_host.yml index d39dad4..b745e31 100644 --- a/test/test_wildcard_host.yml +++ b/test/test_wildcard_host.yml @@ -35,4 +35,3 @@ sut: image: nginxproxy/nginx-proxy:test volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ./lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro From fd35a0924072851648b049972ffea01789513a95 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 21:54:22 +1300 Subject: [PATCH 117/126] tests: Revise dhparams tests - `dhparam_generation` tests are no longer necessary, dropped. Modified the remaining `dhparam` test to use multiple `nginx-proxy` images to verify correct behavior for different configs. Tests now cover: - Default (ffdhe4096) is used. - Alternative via ENV (ffdhe2048) works correctly. - Invalid group via ENV (1024-bit) fails. - Custom DH params provided via file mount works with warning emitted. --- - `assert_log_contains`: added a `container_name` arg with `nginxproxy` as the default value. This allows multiple nginx-proxy containers to utilize this method instead. - Extracted out the `openssl` test (_to `negotiate_cipher()`_) and modified it to be a bit more flexible. It now takes a container with optional extra args to pass to `openssl` command called, as well as the `grep` string to match. This made the original test redundant, so I've dropped it. - Added two methods to use `negotiate_cipher()`, one verifies a DHE cipher suite was negotiated and checks that a DH emphermal key was also mentioned in the output. The other method verifies the expectation of failing to negotiate a valid cipher if DH params have not been set, while verifying that non-DHE cipher suites can be successfully negotiated. - Added a `get_env()` method for extracting attached environments on a container. This is useful for verifying invalid `DHPARAM_BITS` values (eg `1024`-bit). - The original `Server Temp Key` assertion was incorrect, it was expecting a value that is unrelated to DHE cipher suite support (_`X25519` is related to ECDHE_). This is due to TLS 1.3 being negotiated where you cannot use custom DH params, nor influence the negotiated cipher due to this mechanism changing from TLS 1.3. TLS 1.3 does support DH params, but it internally negotiates RFC 7919 group between server and client instead. Thus to verify expectations, the connection via `openssl` is made explicitly with TLS 1.2 instead. --- test/test_ssl/test_dhparam.py | 117 ++++++++++++++++++---- test/test_ssl/test_dhparam.yml | 33 +++++- test/test_ssl/test_dhparam_generation.py | 44 -------- test/test_ssl/test_dhparam_generation.yml | 8 -- 4 files changed, 128 insertions(+), 74 deletions(-) delete mode 100644 test/test_ssl/test_dhparam_generation.py delete mode 100644 test/test_ssl/test_dhparam_generation.yml diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index acb4269..0e567d2 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -15,7 +15,7 @@ docker_client = docker.from_env() ############################################################################### @backoff.on_exception(backoff.constant, AssertionError, interval=2, max_tries=15, jitter=None) -def assert_log_contains(expected_log_line): +def assert_log_contains(expected_log_line, container_name="nginxproxy"): """ Check that the nginx-proxy container log contains a given string. The backoff decorator will retry the check 15 times with a 2 seconds delay. @@ -24,7 +24,7 @@ def assert_log_contains(expected_log_line): :return: None :raises: AssertError if the expected string is not found in the log """ - sut_container = docker_client.containers.get("nginxproxy") + sut_container = docker_client.containers.get(container_name) docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False) assert bytes(expected_log_line, encoding="utf8") in docker_logs @@ -58,36 +58,117 @@ def require_openssl(required_version): reason=f"openssl v{openssl_version} is less than required version {required_version}") +@require_openssl("1.0.2") +def negotiate_cipher(sut_container, additional_params='', grep='Cipher is'): + host = f"{sut_container.attrs['NetworkSettings']['IPAddress']}:443" + + return subprocess.check_output( + f"echo '' | openssl s_client -connect {host} -tls1_2 {additional_params} | grep '{grep}'", + shell=True + ) + + +def can_negotiate_dhe_ciphersuite(sut_container): + r = negotiate_cipher(sut_container, "-cipher 'EDH'") + assert b"New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384\n" == r + + r2 = negotiate_cipher(sut_container, "-cipher 'EDH'", "Server Temp Key") + assert b"DH" in r2 + + +def cannot_negotiate_dhe_ciphersuite(sut_container): + # Fail to negotiate a DHE cipher suite: + r = negotiate_cipher(sut_container, "-cipher 'EDH'") + assert b"New, (NONE), Cipher is (NONE)\n" == r + + # Correctly establish a connection (TLS 1.2): + r2 = negotiate_cipher(sut_container) + assert b"New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384\n" == r2 + + r3 = negotiate_cipher(sut_container, grep="Server Temp Key") + assert b"X25519" in r3 + + +# Parse array of container ENV, splitting at the `=` and returning the value, otherwise `None` +def get_env(sut_container, var): + env = sut_container.attrs['Config']['Env'] + + for e in env: + if e.startswith(var): + return e.split('=')[1] + + return None + + ############################################################################### # # Tests # ############################################################################### -def test_dhparam_is_not_generated_if_present(docker_compose): - sut_container = docker_client.containers.get("nginxproxy") +def test_default_dhparam_is_ffdhe4096(docker_compose): + container_name="dh-default" + sut_container = docker_client.containers.get(container_name) assert sut_container.status == "running" - assert_log_contains("Custom dhparam.pem file found, generation skipped") + assert_log_contains("Setting up DH Parameters..", container_name) - # Make sure the dhparam in use is not the default, pre-generated one - default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").output.split() + # Make sure the dhparam file used is the default ffdhe4096.pem: + default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe4096.pem").output.split() + current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() + assert default_checksum[0] == current_checksum[0] + + can_negotiate_dhe_ciphersuite(sut_container) + + +def test_can_change_dhparam_group(docker_compose): + container_name="dh-env" + sut_container = docker_client.containers.get(container_name) + assert sut_container.status == "running" + + assert_log_contains("Setting up DH Parameters..", container_name) + + # Make sure the dhparam file used is ffdhe2048.pem, not the default (ffdhe4096.pem): + default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe2048.pem").output.split() + current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() + assert default_checksum[0] == current_checksum[0] + + can_negotiate_dhe_ciphersuite(sut_container) + + +def test_fail_if_dhparam_group_not_supported(docker_compose): + container_name="invalid-group-1024" + sut_container = docker_client.containers.get(container_name) + assert sut_container.status == "exited" + + DHPARAM_BITS = get_env(sut_container, "DHPARAM_BITS") + assert DHPARAM_BITS == "1024" + + assert_log_contains( + f"ERROR: Unsupported DHPARAM_BITS size: {DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default).", + container_name + ) + + +def test_custom_dhparam_is_supported(docker_compose): + container_name="dh-file" + sut_container = docker_client.containers.get(container_name) + assert sut_container.status == "running" + + assert_log_contains( + "Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.", + container_name + ) + + # Make sure the dhparam file used is not the default (ffdhe4096.pem): + default_checksum = sut_container.exec_run("md5sum /app/dhparam/ffdhe4096.pem").output.split() current_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() assert default_checksum[0] != current_checksum[0] + can_negotiate_dhe_ciphersuite(sut_container) + def test_web5_https_works(docker_compose, nginxproxy): r = nginxproxy.get("https://web5.nginx-proxy.tld/port", allow_redirects=False) assert r.status_code == 200 assert "answer from port 85\n" in r.text - - -@require_openssl("1.0.2") -def test_web5_dhparam_is_used(docker_compose): - sut_container = docker_client.containers.get("nginxproxy") - assert sut_container.status == "running" - - host = f"{sut_container.attrs['NetworkSettings']['IPAddress']}:443" - r = subprocess.check_output( - f"echo '' | openssl s_client -connect {host} -cipher 'EDH' | grep 'Server Temp Key'", shell=True) - assert b"Server Temp Key: X25519, 253 bits\n" == r diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index 9b29842..fd254f1 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -6,11 +6,36 @@ web5: WEB_PORTS: "85" VIRTUAL_HOST: "web5.nginx-proxy.tld" - -sut: +# sut - System Under Test +with_default_group: image: nginxproxy/nginx-proxy:test - container_name: nginxproxy + container_name: dh-default volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro - ./certs:/etc/nginx/certs:ro + +with_alternative_group: + image: nginxproxy/nginx-proxy:test + container_name: dh-env + environment: + - DHPARAM_BITS=2048 + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs:ro + +with_invalid_group: + image: nginxproxy/nginx-proxy:test + container_name: invalid-group-1024 + environment: + - DHPARAM_BITS=1024 + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs:ro + +with_custom_file: + image: nginxproxy/nginx-proxy:test + container_name: dh-file + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs:ro + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro \ No newline at end of file diff --git a/test/test_ssl/test_dhparam_generation.py b/test/test_ssl/test_dhparam_generation.py deleted file mode 100644 index ec1c90e..0000000 --- a/test/test_ssl/test_dhparam_generation.py +++ /dev/null @@ -1,44 +0,0 @@ -import backoff -import docker - -docker_client = docker.from_env() - - -############################################################################### -# -# Tests helpers -# -############################################################################### - -@backoff.on_exception(backoff.constant, AssertionError, interval=2, max_tries=15, jitter=None) -def assert_log_contains(expected_log_line): - """ - Check that the nginx-proxy container log contains a given string. - The backoff decorator will retry the check 15 times with a 2 seconds delay. - - :param expected_log_line: string to search for - :return: None - :raises: AssertError if the expected string is not found in the log - """ - sut_container = docker_client.containers.get("nginxproxy") - docker_logs = sut_container.logs(stdout=True, stderr=True, stream=False, follow=False) - assert bytes(expected_log_line, encoding="utf8") in docker_logs - - -############################################################################### -# -# Tests -# -############################################################################### - -def test_dhparam_is_generated_if_missing(docker_compose): - sut_container = docker_client.containers.get("nginxproxy") - assert sut_container.status == "running" - - assert_log_contains("Generating DSA parameters") - assert_log_contains("dhparam generation complete, reloading nginx") - - # Make sure the dhparam in use is not the default, pre-generated one - default_checksum = sut_container.exec_run("md5sum /app/dhparam.pem.default").output.split() - generated_checksum = sut_container.exec_run("md5sum /etc/nginx/dhparam/dhparam.pem").output.split() - assert default_checksum[0] != generated_checksum[0] diff --git a/test/test_ssl/test_dhparam_generation.yml b/test/test_ssl/test_dhparam_generation.yml deleted file mode 100644 index 6df55c1..0000000 --- a/test/test_ssl/test_dhparam_generation.yml +++ /dev/null @@ -1,8 +0,0 @@ -sut: - image: nginxproxy/nginx-proxy:test - container_name: nginxproxy - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro - environment: - - DHPARAM_BITS=256 From 1d2f308cdff1c0771d4faf8a91da497c013ad90b Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 21:49:06 +1300 Subject: [PATCH 118/126] feat: Bring back ability to skip default DH params Adds back the ability to avoid using DH params, provided no file was explicitly supplied. This used to be `DHPARAM_GENERATION=false`, the equivalent is now `DHPARAM_SKIP=1` (default 0). Previous name was no longer appropriate. Ensures that if a user has explicitly provided their own dhparam file to still output a warning instead of the skip message, since `DHPARAM_SKIP=1` doesn't disable the support in nginx. --- README.md | 6 ++++++ docker-entrypoint.sh | 3 +++ test/test_ssl/test_dhparam.py | 10 ++++++++++ test/test_ssl/test_dhparam.yml | 11 ++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2177056..038358f 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,12 @@ To use custom `dhparam.pem` files per-virtual-host, the files should be named af In the separate container setup, no pre-generated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image, nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will provide one. If you still want A+ security in a separate container setup, you should mount an RFC7919 DH key file to the nginx container at `/etc/nginx/dhparam/dhparam.pem`. +Set `DHPARAM_SKIP` environment variable to `1` to disable using default Diffie-Hellman parameters. The default value is `0`. + +```console +docker run -e DHPARAM_SKIP=1 .... +``` + #### Wildcard Certificates Wildcard certificates and keys should be named after the domain name with a `.crt` and `.key` extension. For example `VIRTUAL_HOST=foo.bar.com` would use cert name `bar.com.crt` and `bar.com.key`. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2dba7ea..0e74204 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -47,6 +47,9 @@ function _setup_dhparam() { if [[ -f ${DHPARAM_FILE} ]]; then echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 return 0 + elif [[ ${DHPARAM_SKIP:=0} -eq 1 ]]; then + echo 'Skipping Diffie-Hellman parameters setup.' + return 0 elif [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then echo "ERROR: Unsupported DHPARAM_BITS size: ${DHPARAM_BITS}. Use: 2048, 3072, or 4096 (default)." >&2 exit 1 diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index 0e567d2..33b2ed7 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -168,6 +168,16 @@ def test_custom_dhparam_is_supported(docker_compose): can_negotiate_dhe_ciphersuite(sut_container) +def test_can_skip_dhparam(docker_compose): + container_name="dh-skip" + sut_container = docker_client.containers.get(container_name) + assert sut_container.status == "running" + + assert_log_contains("Skipping Diffie-Hellman parameters setup.", container_name) + + cannot_negotiate_dhe_ciphersuite(sut_container) + + def test_web5_https_works(docker_compose, nginxproxy): r = nginxproxy.get("https://web5.nginx-proxy.tld/port", allow_redirects=False) assert r.status_code == 200 diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index fd254f1..8906937 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -38,4 +38,13 @@ with_custom_file: volumes: - /var/run/docker.sock:/tmp/docker.sock:ro - ./certs:/etc/nginx/certs:ro - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro \ No newline at end of file + - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + +with_skip: + image: nginxproxy/nginx-proxy:test + container_name: dh-skip + environment: + - DHPARAM_SKIP=1 + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + - ./certs:/etc/nginx/certs:ro \ No newline at end of file From e81001615cc77428b810dc40b16548c08b68e088 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 28 Sep 2021 19:47:59 +1300 Subject: [PATCH 119/126] tests: Improve error handling output and use regular string comparisons As this project isn't exactly python focused apart from the test suite, I'll assume other contributors are probably not as experienced with python either. Since this is a rather technical test, the extra comments should help grok the functionality without floundering around with the docs. When the subprocess raises an exception due to an issue with the command (_eg using `-CAfile` arg to `openssl` with an invalid path_), the tests would output large walls of text that wasn't particularly helpful in troubleshooting the issue. `stderr` was also leaking out inbetween the test case results in the terminal, this has been resolved by ensuring that output is caught and piped, which keeps it available to python when an exception is raised. Identifying the actual error cause and location is now much nicer. Updated the output to be plain string content instead of byte strings, this works fine :) --- test/test_ssl/test_dhparam.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index 33b2ed7..1169775 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -61,32 +61,44 @@ def require_openssl(required_version): @require_openssl("1.0.2") def negotiate_cipher(sut_container, additional_params='', grep='Cipher is'): host = f"{sut_container.attrs['NetworkSettings']['IPAddress']}:443" - - return subprocess.check_output( - f"echo '' | openssl s_client -connect {host} -tls1_2 {additional_params} | grep '{grep}'", - shell=True - ) + + try: + # Enforce TLS 1.2 as newer versions don't support custom dhparam or ciphersuite preference. + # The empty `echo` is to provide `openssl` user input, so that the process exits: https://stackoverflow.com/a/28567565 + # `shell=True` enables using a single string to execute as a shell command. + # `text=True` prevents the need to compare against byte strings. + # `stderr=subprocess.PIPE` removes the output to stderr being interleaved with test case status (output during exceptions). + return subprocess.check_output( + f"echo '' | openssl s_client -connect {host} -tls1_2 {additional_params} | grep '{grep}'", + shell=True, + text=True, + stderr=subprocess.PIPE, + ) + except subprocess.CalledProcessError as e: + # Output a more helpful error, the original exception in this case isn't that helpful. + # `from None` to ignore undesired output from exception chaining. + raise Exception("Failed to process CLI request:\n" + e.stderr) from None def can_negotiate_dhe_ciphersuite(sut_container): r = negotiate_cipher(sut_container, "-cipher 'EDH'") - assert b"New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384\n" == r + assert "New, TLSv1.2, Cipher is DHE-RSA-AES256-GCM-SHA384\n" == r r2 = negotiate_cipher(sut_container, "-cipher 'EDH'", "Server Temp Key") - assert b"DH" in r2 + assert "DH" in r2 def cannot_negotiate_dhe_ciphersuite(sut_container): # Fail to negotiate a DHE cipher suite: r = negotiate_cipher(sut_container, "-cipher 'EDH'") - assert b"New, (NONE), Cipher is (NONE)\n" == r + assert "New, (NONE), Cipher is (NONE)\n" == r # Correctly establish a connection (TLS 1.2): r2 = negotiate_cipher(sut_container) - assert b"New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384\n" == r2 + assert "New, TLSv1.2, Cipher is ECDHE-RSA-AES256-GCM-SHA384\n" == r2 r3 = negotiate_cipher(sut_container, grep="Server Temp Key") - assert b"X25519" in r3 + assert "X25519" in r3 # Parse array of container ENV, splitting at the `=` and returning the value, otherwise `None` From 0cd573f043b78ff587b9b3682b08c5c7aa9e7e36 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 20:07:08 +1200 Subject: [PATCH 120/126] tests(`pytest.sh`): Update Syntax - Added clarification comment of the DIR command - Quoted `ARGS` usage required wrapping `ARGS` assignment in an array to properly expand. This wasn't broken before, but is required change to keep ShellCheck lint happy. - Quote wrapped `DIR` usage, the volume target had an extra `/` before the `DIR` which seems unnecessary as `pwd` should return absolute path. - Expanded `docker run` options to long-form. --- test/pytest.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/pytest.sh b/test/pytest.sh index a9745f5..99c054c 100755 --- a/test/pytest.sh +++ b/test/pytest.sh @@ -8,17 +8,18 @@ # # ############################################################################### +# Returns the absolute directory path to this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -ARGS="$@" +ARGS=("$@") # check requirements echo "> Building nginx-proxy-tester image..." -docker build -t nginx-proxy-tester -f $DIR/requirements/Dockerfile-nginx-proxy-tester $DIR/requirements +docker build -t nginx-proxy-tester -f "${DIR}/requirements/Dockerfile-nginx-proxy-tester" "${DIR}/requirements" # run the nginx-proxy-tester container setting the correct value for the working dir in order for # docker-compose to work properly when run from within that container. exec docker run --rm -it \ - -v ${DIR}:/${DIR} \ - -w ${DIR} \ - -v /var/run/docker.sock:/var/run/docker.sock \ - nginx-proxy-tester ${ARGS} +--volume /var/run/docker.sock:/var/run/docker.sock \ +--volume "${DIR}:${DIR}" \ +--workdir "${DIR}" \ +nginx-proxy-tester "${ARGS[@]}" \ No newline at end of file From 391ca3e3b536d98fa34c34cf32bc96ae8746edb3 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Sat, 25 Sep 2021 16:47:46 +1200 Subject: [PATCH 121/126] fix(Dockerfile): Remove `VOLUME` in Dockerfile Anonymous volumes are discouraged for reliable persistence. Users should use named volumes or bind mounts instead. Potentially breaking change, users can also use explicit anonymous volumes instead of relying on implicit anonymous volumes. `nginx-proxy` really should not be creating implicit anonymous volumes as in most cases it is undesirable. `git blame` reveals this was added in 2014 by jwilder, with a message that implies implicit anonymous volumes was never intended.. --- Dockerfile | 2 -- Dockerfile.alpine | 2 -- 2 files changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5642e2c..a08f223 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,7 +70,5 @@ WORKDIR /app/ ENV DOCKER_HOST unix:///tmp/docker.sock -VOLUME ["/etc/nginx/certs"] - ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 546de81..1281f8f 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -67,7 +67,5 @@ WORKDIR /app/ ENV DOCKER_HOST unix:///tmp/docker.sock -VOLUME ["/etc/nginx/certs"] - ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] From 41bd4076c09ce23ea8d55e566ee4588d9c3847aa Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Wed, 29 Sep 2021 15:19:38 +1300 Subject: [PATCH 122/126] chore: DRY up `test_dhparam.yml` Use YAML anchors for repeated values providing a single source of truth. I would use `x-*` convention to store anchors above service containers, but this seems to require a compose config that defines the services (and version?) keys, which this test setup was failing to be compatible with for some reason.. --- test/test_ssl/test_dhparam.yml | 36 +++++++++++++++------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index 8906937..6673f18 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -7,44 +7,40 @@ web5: VIRTUAL_HOST: "web5.nginx-proxy.tld" # sut - System Under Test +# `docker.sock` required for functionality +# `certs` required to enable HTTPS via template with_default_group: - image: nginxproxy/nginx-proxy:test container_name: dh-default - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro + image: &img-nginxproxy nginxproxy/nginx-proxy:test + volumes: &vols-common + - &docker-sock /var/run/docker.sock:/tmp/docker.sock:ro + - &nginx-certs ./certs:/etc/nginx/certs:ro with_alternative_group: - image: nginxproxy/nginx-proxy:test container_name: dh-env environment: - DHPARAM_BITS=2048 - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro + image: *img-nginxproxy + volumes: *vols-common with_invalid_group: - image: nginxproxy/nginx-proxy:test container_name: invalid-group-1024 environment: - DHPARAM_BITS=1024 - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro + image: *img-nginxproxy + volumes: *vols-common with_custom_file: - image: nginxproxy/nginx-proxy:test container_name: dh-file - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro + image: *img-nginxproxy + volumes: + - *docker-sock + - *nginx-certs - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro with_skip: - image: nginxproxy/nginx-proxy:test container_name: dh-skip environment: - DHPARAM_SKIP=1 - volumes: - - /var/run/docker.sock:/tmp/docker.sock:ro - - ./certs:/etc/nginx/certs:ro \ No newline at end of file + image: *img-nginxproxy + volumes: *vols-common \ No newline at end of file From b1b1b700eac59270d1cc7b79a3c9d2ca90b0a90c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 8 Oct 2021 04:27:38 +0000 Subject: [PATCH 123/126] chore(deps): bump docker from 5.0.2 to 5.0.3 in /test/requirements Bumps [docker](https://github.com/docker/docker-py) from 5.0.2 to 5.0.3. - [Release notes](https://github.com/docker/docker-py/releases) - [Commits](https://github.com/docker/docker-py/compare/5.0.2...5.0.3) --- updated-dependencies: - dependency-name: docker dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements/python-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements/python-requirements.txt b/test/requirements/python-requirements.txt index 2f231f8..1a2ad1e 100644 --- a/test/requirements/python-requirements.txt +++ b/test/requirements/python-requirements.txt @@ -1,5 +1,5 @@ backoff==1.11.1 docker-compose==1.29.2 -docker==5.0.2 +docker==5.0.3 pytest==6.2.5 requests==2.26.0 From ab7ac0aadbdfd505651800bdcbfeb006dd0a3bc1 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 20 Oct 2021 19:15:27 +0200 Subject: [PATCH 124/126] fix: backward compatibility w/ DHPARAM_GENERATION Also use true rather than 1 to stay consistent with other boolean environment variables --- README.md | 4 ++-- docker-entrypoint.sh | 38 +++++++++++++++++++++++++++++++--- test/test_ssl/test_dhparam.py | 10 +++++++++ test/test_ssl/test_dhparam.yml | 9 +++++++- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 038358f..1605fc9 100644 --- a/README.md +++ b/README.md @@ -261,10 +261,10 @@ To use custom `dhparam.pem` files per-virtual-host, the files should be named af In the separate container setup, no pre-generated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image, nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will provide one. If you still want A+ security in a separate container setup, you should mount an RFC7919 DH key file to the nginx container at `/etc/nginx/dhparam/dhparam.pem`. -Set `DHPARAM_SKIP` environment variable to `1` to disable using default Diffie-Hellman parameters. The default value is `0`. +Set `DHPARAM_SKIP` environment variable to `true` to disable using default Diffie-Hellman parameters. The default value is `false`. ```console -docker run -e DHPARAM_SKIP=1 .... +docker run -e DHPARAM_SKIP=true .... ``` #### Wildcard Certificates diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 0e74204..45d6cd2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,6 +1,34 @@ #!/bin/bash set -e +function _parse_true() { + case "$1" in + + true | True | TRUE | 1) + return 0 + ;; + + *) + return 1 + ;; + + esac +} + +function _parse_false() { + case "$1" in + + false | False | FALSE | 0) + return 0 + ;; + + *) + return 1 + ;; + + esac +} + function _check_unix_socket() { # Warn if the DOCKER_HOST socket does not exist if [[ ${DOCKER_HOST} == unix://* ]]; then @@ -35,8 +63,6 @@ function _resolvers() { } function _setup_dhparam() { - echo 'Setting up DH Parameters..' - # DH params will be supplied for nginx here: local DHPARAM_FILE='/etc/nginx/dhparam/dhparam.pem' @@ -47,7 +73,11 @@ function _setup_dhparam() { if [[ -f ${DHPARAM_FILE} ]]; then echo 'Warning: A custom dhparam.pem file was provided. Best practice is to use standardized RFC7919 DHE groups instead.' >&2 return 0 - elif [[ ${DHPARAM_SKIP:=0} -eq 1 ]]; then + elif _parse_true "${DHPARAM_SKIP:=false}"; then + echo 'Skipping Diffie-Hellman parameters setup.' + return 0 + elif _parse_false "${DHPARAM_GENERATION:=true}"; then + echo 'Warning: The DHPARAM_GENERATION environment variable is deprecated, please consider using DHPARAM_SKIP set to true instead.' >&2 echo 'Skipping Diffie-Hellman parameters setup.' return 0 elif [[ ! ${DHPARAM_BITS} =~ ^(2048|3072|4096)$ ]]; then @@ -55,6 +85,8 @@ function _setup_dhparam() { exit 1 fi + echo 'Setting up DH Parameters..' + # Use an existing pre-generated DH group from RFC7919 (https://datatracker.ietf.org/doc/html/rfc7919#appendix-A): local RFC7919_DHPARAM_FILE="/app/dhparam/ffdhe${FFDHE_GROUP}.pem" diff --git a/test/test_ssl/test_dhparam.py b/test/test_ssl/test_dhparam.py index 1169775..6de92b2 100644 --- a/test/test_ssl/test_dhparam.py +++ b/test/test_ssl/test_dhparam.py @@ -189,6 +189,16 @@ def test_can_skip_dhparam(docker_compose): cannot_negotiate_dhe_ciphersuite(sut_container) +def test_can_skip_dhparam_backward_compatibility(docker_compose): + container_name="dh-skip-backward" + sut_container = docker_client.containers.get(container_name) + assert sut_container.status == "running" + + assert_log_contains("Warning: The DHPARAM_GENERATION environment variable is deprecated, please consider using DHPARAM_SKIP set to true instead.", container_name) + assert_log_contains("Skipping Diffie-Hellman parameters setup.", container_name) + + cannot_negotiate_dhe_ciphersuite(sut_container) + def test_web5_https_works(docker_compose, nginxproxy): r = nginxproxy.get("https://web5.nginx-proxy.tld/port", allow_redirects=False) diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index 6673f18..791a9d7 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -41,6 +41,13 @@ with_custom_file: with_skip: container_name: dh-skip environment: - - DHPARAM_SKIP=1 + - DHPARAM_SKIP=true + image: *img-nginxproxy + volumes: *vols-common + +with_skip_backward: + container_name: dh-skip-backward + environment: + - DHPARAM_GENERATION=false image: *img-nginxproxy volumes: *vols-common \ No newline at end of file From 36c4ed7632037515bec256ff46cb3e8ecc7388ef Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 20 Oct 2021 21:04:29 +0200 Subject: [PATCH 125/126] test: replace test dhparam.pem with ffdhe3072.pem --- test/lib/ssl/dhparam.pem | 8 -------- test/test_ssl/test_dhparam.yml | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 test/lib/ssl/dhparam.pem diff --git a/test/lib/ssl/dhparam.pem b/test/lib/ssl/dhparam.pem deleted file mode 100644 index eb3218c..0000000 --- a/test/lib/ssl/dhparam.pem +++ /dev/null @@ -1,8 +0,0 @@ ------BEGIN DH PARAMETERS----- -MIIBCAKCAQEA1cae6HqPSgicEuAuSCf6Ii3d6qMX9Ta8lnwoX0JQ0CWK7mzaiiIi -dY7oHmc4cq0S3SH+g0tdLP9yqygFS9hdUGINwS2VV6poj2/vdL/dUshegyxpEH58 -nofCPnFDeKkcPDMYAlGS8zjp60TsBkRJKcrxxwnjod1Q5mWuMN5KH3sxs842udKH -0nHFE9kKW/NfXb+EGsjpocGpf786cGuCO2d00THsoItOEcM9/aI8DX1QcyxAHR6D -HaYTFJnyyx8Q44u27M15idI4pbNoKORlotiuOwCTGYCfbN14aOV+Ict7aSF8FWpP -48j9SMNuIu2DlF9pNLo6fsrOjYY3c9X12wIBAg== ------END DH PARAMETERS----- diff --git a/test/test_ssl/test_dhparam.yml b/test/test_ssl/test_dhparam.yml index 791a9d7..d49afc9 100644 --- a/test/test_ssl/test_dhparam.yml +++ b/test/test_ssl/test_dhparam.yml @@ -36,7 +36,7 @@ with_custom_file: volumes: - *docker-sock - *nginx-certs - - ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro + - ../../dhparam/ffdhe3072.pem:/etc/nginx/dhparam/dhparam.pem:ro with_skip: container_name: dh-skip From bbdee361f1d391f96f0c12a59ac22d8b7fac2ae1 Mon Sep 17 00:00:00 2001 From: HPPinata <83947761+HPPinata@users.noreply.github.com> Date: Thu, 4 Nov 2021 21:45:10 +0100 Subject: [PATCH 126/126] Clarify grammar in DH-GROUP section Since the second option got removed, the "either" makes no sense any more and may lead to confusion about non existent alternatives --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1605fc9..d387b73 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ If you are running the container in a virtualized environment (Hyper-V, VirtualB To use custom `dhparam.pem` files per-virtual-host, the files should be named after the virtual host with a `dhparam` suffix and `.pem` extension. For example, a container with `VIRTUAL_HOST=foo.bar.com` should have a `foo.bar.com.dhparam.pem` file in the `/etc/nginx/certs` directory. -> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these clients, you must either provide your own `dhparam.pem`. +> COMPATIBILITY WARNING: The default generated `dhparam.pem` key is 4096 bits for A+ security. Some older clients (like Java 6 and 7) do not support DH keys with over 1024 bits. In order to support these clients, you must provide your own `dhparam.pem`. In the separate container setup, no pre-generated key will be available and neither the [jwilder/docker-gen](https://hub.docker.com/r/jwilder/docker-gen) image, nor the offical [nginx](https://registry.hub.docker.com/_/nginx/) image will provide one. If you still want A+ security in a separate container setup, you should mount an RFC7919 DH key file to the nginx container at `/etc/nginx/dhparam/dhparam.pem`.