Skip to content

Commit 2611cd9

Browse files
Merge pull request #5 from coreweave/bj/update-branches
fix(proxy): fixing branch history
2 parents ec6ad55 + 07abae5 commit 2611cd9

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ ENV ALLOW_PUSH="false"
102102
# Default is true to not change default behavior.
103103
ENV PROXY_REQUEST_BUFFERING="true"
104104

105+
# Should we allow overridding with own authentication, default to false.
106+
ENV ALLOW_OWN_AUTH="false"
107+
108+
# Should we allow push only with own authentication, default to false.
109+
ENV ALLOW_PUSH_WITH_OWN_AUTH="false"
110+
111+
105112
# Timeouts
106113
# ngx_http_core_module
107114
ENV SEND_TIMEOUT="60s"

entrypoint.sh

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ echo "DEBUG, determined RESOLVERS from /etc/resolv.conf: '$RESOLVERS'"
2525
conf=""
2626
for ONE_RESOLVER in ${RESOLVERS}; do
2727
echo "Possible resolver: $ONE_RESOLVER"
28-
conf="resolver $ONE_RESOLVER; "
28+
conf="resolver $ONE_RESOLVER ipv6=off; "
2929
done
3030

3131
echo "Final chosen resolver: $conf"
3232
confpath=/etc/nginx/resolvers.conf
33-
if [ ! -e $confpath ]
33+
if [ ! -e $confpath ] || [ "$conf" != "$(cat $confpath)" ]
3434
then
3535
echo "Using auto-determined resolver '$conf' via '$confpath'"
3636
echo "$conf" > $confpath
@@ -147,6 +147,17 @@ echo -e "\nManifest caching config: ---\n"
147147
cat /etc/nginx/nginx.manifest.caching.config.conf
148148
echo "---"
149149

150+
if [[ "a${ALLOW_OWN_AUTH}" == "atrue" ]]; then
151+
cat << 'EOF' > /etc/nginx/conf.d/allowed_override_auth.conf
152+
if ($http_authorization != "") {
153+
# override with own authentication if provided
154+
set $finalAuth $http_authorization;
155+
}
156+
EOF
157+
else
158+
echo '' > /etc/nginx/conf.d/allowed_override_auth.conf
159+
fi
160+
150161
if [[ "a${ALLOW_PUSH}" == "atrue" ]]; then
151162
cat <<EOF > /etc/nginx/conf.d/allowed.methods.conf
152163
# allow to upload big layers
@@ -155,6 +166,31 @@ if [[ "a${ALLOW_PUSH}" == "atrue" ]]; then
155166
# only cache GET requests
156167
proxy_cache_methods GET;
157168
EOF
169+
elif [[ "a${ALLOW_PUSH_WITH_OWN_AUTH}" == "atrue" ]]; then
170+
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
171+
# Block POST/PUT/DELETE if own authentication is not provided.
172+
set $combined_ha_rm "$http_authorization$request_method";
173+
if ($combined_ha_rm = POST) {
174+
return 405 "POST method is not allowed";
175+
}
176+
if ($combined_ha_rm = PUT) {
177+
return 405 "PUT method is not allowed";
178+
}
179+
if ($combined_ha_rm = DELETE) {
180+
return 405 "DELETE method is not allowed";
181+
}
182+
183+
if ($http_authorization != "") {
184+
# override with own authentication if provided
185+
set $finalAuth $http_authorization;
186+
}
187+
188+
# allow to upload big layers
189+
client_max_body_size 0;
190+
191+
# only cache GET requests
192+
proxy_cache_methods GET;
193+
EOF
158194
else
159195
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
160196
# Block POST/PUT/DELETE. Don't use this proxy for pushing.

nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
249249
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
250250

251251
# Add the authentication info, if the map matched the target domain.
252+
include "/etc/nginx/conf.d/allowed_override_auth.conf";
252253
proxy_set_header Authorization $finalAuth;
253254

254255
# Use SNI during the TLS handshake with the upstream.

0 commit comments

Comments
 (0)