31
31
export ALLDOMAINS=${ALLDOMAINS: 1} # remove the first comma and export
32
32
/create_ca_cert.sh # This uses ALLDOMAINS to generate the certificates.
33
33
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
+
34
38
# Now handle the auth part.
35
39
echo -n " " > /etc/nginx/docker.auth.map
36
40
@@ -63,19 +67,6 @@ if [ "$AUTH_REGISTRIES" ]; then
63
67
done
64
68
fi
65
69
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
-
79
70
# create default config for the caching layer to listen on 443.
80
71
echo " listen 443 ssl default_server;" > /etc/nginx/caching.layer.listen
81
72
echo " error_log /var/log/nginx/error.log warn;" > /etc/nginx/error.log.debug.warn
@@ -99,7 +90,7 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
99
90
# in debug mode, change caching layer to listen on 444, so that mitmproxy can sit in the middle.
100
91
echo " listen 444 ssl default_server;" > /etc/nginx/caching.layer.listen
101
92
102
- echo " Starting in DEBUG MODE (mitmproxy)."
93
+ echo " Starting in DEBUG MODE (mitmproxy)." >&2
103
94
echo " Run mitmproxy with reverse pointing to the same certs..."
104
95
mitmweb --no-web-open-browser --web-iface 0.0.0.0 --web-port 8081 \
105
96
--set keep_host_header=true --set ssl_insecure=true \
@@ -108,6 +99,28 @@ if [[ "a${DEBUG}" == "atrue" ]]; then
108
99
echo " Access mitmweb via http://127.0.0.1:8081/ "
109
100
fi
110
101
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
+
111
124
if [[ " a${DEBUG_NGINX} " == " atrue" ]]; then
112
125
if [[ ! -f /usr/sbin/nginx-debug ]]; then
113
126
echo " To debug, you need the -debug version of this image, eg: :latest-debug"
@@ -120,6 +133,23 @@ if [[ "a${DEBUG_NGINX}" == "atrue" ]]; then
120
133
NGINX_BIN=" /usr/sbin/nginx-debug"
121
134
fi
122
135
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
+
123
153
echo " Testing nginx config..."
124
154
${NGINX_BIN} -t
125
155
0 commit comments