Skip to content

Commit

Permalink
Allow push (#59)
Browse files Browse the repository at this point in the history
Introduce ALLOW_PUSH, if set to true, allows non-GET methods through the proxy
  • Loading branch information
fgimenez authored Dec 2, 2020
1 parent dfb6a5d commit 536f0fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@ ENV MANIFEST_CACHE_SECONDARY_TIME="60d"
# In the default config, :latest and other frequently-used tags will get this value.
ENV MANIFEST_CACHE_DEFAULT_TIME="1h"

# Should we allow actions different than pull, default to false.
ENV ALLOW_PUSH="false"

# Did you want a shell? Sorry, the entrypoint never returns, because it runs nginx itself. Use 'docker exec' if you need to mess around internally.
ENTRYPOINT ["/entrypoint.sh"]
23 changes: 23 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ echo "Manifest caching config: ---"
cat /etc/nginx/nginx.manifest.caching.config.conf
echo "---"

if [[ "a${ALLOW_PUSH}" == "atrue" ]]; then
cat <<EOF > /etc/nginx/conf.d/allowed.methods.conf
# allow to upload big layers
client_max_body_size 0;
# only cache GET requests
proxy_cache_methods GET;
EOF
else
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
# Block POST/PUT/DELETE. Don't use this proxy for pushing.
if ($request_method = POST) {
return 405 "POST method is not allowed";
}
if ($request_method = PUT) {
return 405 "PUT method is not allowed";
}
if ($request_method = DELETE) {
return 405 "DELETE method is not allowed";
}
EOF
fi

# normally use non-debug version of nginx
NGINX_BIN="/usr/sbin/nginx"

Expand Down
12 changes: 2 additions & 10 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,8 @@ echo "Docker configured with HTTPS_PROXY=$scheme://$http_host/"
# Docker needs this. Don't ask.
chunked_transfer_encoding on;

# Block POST/PUT/DELETE. Don't use this proxy for pushing.
if ($request_method = POST) {
return 405 "POST method is not allowed";
}
if ($request_method = PUT) {
return 405 "PUT method is not allowed";
}
if ($request_method = DELETE) {
return 405 "DELETE method is not allowed";
}
# configuration of the different allowed methods
include "/etc/nginx/conf.d/allowed.methods.conf";

proxy_read_timeout 900;

Expand Down

0 comments on commit 536f0fc

Please sign in to comment.