Skip to content

Commit c1a433d

Browse files
committed
Allow push only if own authentication is provided
1 parent 9a3beba commit c1a433d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ ENV ALLOW_OWN_AUTH="false"
9999

100100
# Should we allow actions different than pull, default to false.
101101
ENV ALLOW_PUSH="false"
102+
# Should we allow push only with own authentication, default to false.
103+
ENV ALLOW_PUSH_WITH_OWN_AUTH="false"
102104

103105
# Timeouts
104106
# ngx_http_core_module

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ for this to work it requires inserting a root CA certificate into system trusted
8080
- Map volume `/docker_mirror_cache` for up to `CACHE_MAX_SIZE` (32gb by default) of cached images across all cached registries
8181
- Map volume `/ca`, the proxy will store the CA certificate here across restarts. **Important** this is security sensitive.
8282
- Env `ALLOW_OWN_AUTH` (default `false`): Allow overridding the `AUTH_REGISTRIES` authentication with own Docker credentials if provided (to support `docker login` as another user).
83-
- Env `ALLOW_PUSH` : This bypasses the proxy when pushing, default to false - if kept to false, pushing will not work. For more info see this [commit](https://github.com/rpardini/docker-registry-proxy/commit/536f0fc8a078d03755f1ae8edc19a86fc4b37fcf).
83+
- Env `ALLOW_PUSH` (default `false`): This bypasses the proxy when pushing, default to false - if kept to false, pushing will not work. For more info see this [commit](https://github.com/rpardini/docker-registry-proxy/commit/536f0fc8a078d03755f1ae8edc19a86fc4b37fcf).
84+
- Env `ALLOW_PUSH_WITH_OWN_AUTH` (default `false`): Allow bypassing the proxy when pushing only if own authentication is provided.
8485
- Env `CACHE_MAX_SIZE` (default `32g`): set the max size to be used for caching local Docker image layers. Use [Nginx sizes](http://nginx.org/en/docs/syntax.html).
8586
- Env `ENABLE_MANIFEST_CACHE`, see the section on pull rate limiting.
8687
- Env `REGISTRIES`: space separated list of registries to cache; no need to include DockerHub, its already done internally.

entrypoint.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,31 @@ if [[ "a${ALLOW_PUSH}" == "atrue" ]]; then
156156
# only cache GET requests
157157
proxy_cache_methods GET;
158158
EOF
159+
elif [[ "a${ALLOW_PUSH_WITH_OWN_AUTH}" == "atrue" ]]; then
160+
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
161+
# Block POST/PUT/DELETE if own authentication is not provided.
162+
set $combined_ha_rm "$http_authorization$request_method";
163+
if ($combined_ha_rm = POST) {
164+
return 405 "POST method is not allowed";
165+
}
166+
if ($combined_ha_rm = PUT) {
167+
return 405 "PUT method is not allowed";
168+
}
169+
if ($combined_ha_rm = DELETE) {
170+
return 405 "DELETE method is not allowed";
171+
}
172+
173+
if ($http_authorization != "") {
174+
# override with own authentication if provided
175+
set $finalAuth $http_authorization;
176+
}
177+
178+
# allow to upload big layers
179+
client_max_body_size 0;
180+
181+
# only cache GET requests
182+
proxy_cache_methods GET;
183+
EOF
159184
else
160185
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
161186
# Block POST/PUT/DELETE. Don't use this proxy for pushing.

0 commit comments

Comments
 (0)