3131export ALLDOMAINS=${ALLDOMAINS: 1} # remove the first comma and export
3232/create_ca_cert.sh # This uses ALLDOMAINS to generate the certificates.
3333
34+ # Target host interception. Empty by default. Used to intercept outgoing requests
35+ # from the proxy to the registries.
36+ echo -n " " > /etc/nginx/docker.targetHost.map
37+
3438# Now handle the auth part.
3539echo -n " " > /etc/nginx/docker.auth.map
3640
@@ -63,19 +67,6 @@ if [ "$AUTH_REGISTRIES" ]; then
6367 done
6468fi
6569
66- echo " " > /etc/nginx/docker.verify.ssl.conf
67- if [[ " a${VERIFY_SSL} " == " atrue" ]]; then
68- cat << EOD > /etc/nginx/docker.verify.ssl.conf
69- # We actually wanna be secure and avoid mitm attacks.
70- # Fitting, since this whole thing is a mitm...
71- # We'll accept any cert signed by a CA trusted by Mozilla (ca-certificates-bundle in alpine)
72- proxy_ssl_verify on;
73- proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
74- proxy_ssl_verify_depth 2;
75- EOD
76- echo " Upstream SSL certificate verification enabled."
77- fi
78-
7970# create default config for the caching layer to listen on 443.
8071echo " listen 443 ssl default_server;" > /etc/nginx/caching.layer.listen
8172echo " error_log /var/log/nginx/error.log warn;" > /etc/nginx/error.log.debug.warn
@@ -99,7 +90,7 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
9990 # in debug mode, change caching layer to listen on 444, so that mitmproxy can sit in the middle.
10091 echo " listen 444 ssl default_server;" > /etc/nginx/caching.layer.listen
10192
102- echo " Starting in DEBUG MODE (mitmproxy)."
93+ echo " Starting in DEBUG MODE (mitmproxy)." >&2
10394 echo " Run mitmproxy with reverse pointing to the same certs..."
10495 mitmweb --no-web-open-browser --web-iface 0.0.0.0 --web-port 8081 \
10596 --set keep_host_header=true --set ssl_insecure=true \
@@ -108,6 +99,28 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
10899 echo " Access mitmweb via http://127.0.0.1:8081/ "
109100fi
110101
102+ if [[ " a${DEBUG_HUB} " == " atrue" ]]; then
103+ if [[ ! -f /usr/bin/mitmweb ]]; then
104+ echo " To debug, you need the -debug version of this image, eg: :latest-debug"
105+ exit 3
106+ fi
107+
108+ # in debug hub mode, we remap targetHost to point to mitmproxy below
109+ echo " \" registry-1.docker.io\" \" 127.0.0.1:445\" ;" > /etc/nginx/docker.targetHost.map
110+
111+ echo " Debugging outgoing DockerHub connections via mitmproxy on 8082." >&2
112+ # this one has keep_host_header=false so we don't need to modify nginx config
113+ mitmweb --no-web-open-browser --web-iface 0.0.0.0 --web-port 8082 \
114+ --set keep_host_header=false --set ssl_insecure=true \
115+ --mode reverse:https://registry-1.docker.io --listen-host 0.0.0.0 \
116+ --listen-port 445 --certs /certs/fullchain_with_key.pem & > /dev/null &
117+
118+ echo " Warning, DockerHub outgoing debugging disables upstream SSL verification for all upstreams." >&2
119+ VERIFY_SSL=false
120+
121+ echo " Access mitmweb for outgoing DockerHub requests via http://127.0.0.1:8082/ "
122+ fi
123+
111124if [[ " a${DEBUG_NGINX} " == " atrue" ]]; then
112125 if [[ ! -f /usr/sbin/nginx-debug ]]; then
113126 echo " To debug, you need the -debug version of this image, eg: :latest-debug"
@@ -120,6 +133,23 @@ if [[ "a${DEBUG_NGINX}" == "atrue" ]]; then
120133 NGINX_BIN=" /usr/sbin/nginx-debug"
121134fi
122135
136+ # Upstream SSL verification.
137+ echo " " > /etc/nginx/docker.verify.ssl.conf
138+ if [[ " a${VERIFY_SSL} " == " atrue" ]]; then
139+ cat << EOD > /etc/nginx/docker.verify.ssl.conf
140+ # We actually wanna be secure and avoid mitm attacks.
141+ # Fitting, since this whole thing is a mitm...
142+ # We'll accept any cert signed by a CA trusted by Mozilla (ca-certificates-bundle in alpine)
143+ proxy_ssl_verify on;
144+ proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
145+ proxy_ssl_verify_depth 2;
146+ EOD
147+ echo " Upstream SSL certificate verification enabled."
148+ else
149+ echo " Upstream SSL certificate verification is DISABLED."
150+ fi
151+
152+
123153echo " Testing nginx config..."
124154${NGINX_BIN} -t
125155
0 commit comments