Skip to content

Commit f96c43f

Browse files
gw0rpardini
authored andcommitted
Allow push only if own authentication is provided
1 parent 3a51ce3 commit f96c43f

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
@@ -102,6 +102,8 @@ ENV ALLOW_OWN_AUTH="false"
102102

103103
# Should we allow actions different than pull, default to false.
104104
ENV ALLOW_PUSH="false"
105+
# Should we allow push only with own authentication, default to false.
106+
ENV ALLOW_PUSH_WITH_OWN_AUTH="false"
105107

106108
# If push is allowed, buffering requests can cause issues on slow upstreams.
107109
# If you have trouble pushing, set this to false first, then fix remainig timouts.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ for this to work it requires inserting a root CA certificate into system trusted
8787
- Map volume `/docker_mirror_cache` for up to `CACHE_MAX_SIZE` (32gb by default) of cached images across all cached registries
8888
- Map volume `/ca`, the proxy will store the CA certificate here across restarts. **Important** this is security sensitive.
8989
- 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).
90-
- 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).
90+
- 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).
91+
- Env `ALLOW_PUSH_WITH_OWN_AUTH` (default `false`): Allow bypassing the proxy when pushing only if own authentication is provided.
9192
- 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).
9293
- Env `ENABLE_MANIFEST_CACHE`, see the section on pull rate limiting.
9394
- 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
@@ -170,6 +170,31 @@ if [[ "a${ALLOW_PUSH}" == "atrue" ]]; then
170170
# only cache GET requests
171171
proxy_cache_methods GET;
172172
EOF
173+
elif [[ "a${ALLOW_PUSH_WITH_OWN_AUTH}" == "atrue" ]]; then
174+
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
175+
# Block POST/PUT/DELETE if own authentication is not provided.
176+
set $combined_ha_rm "$http_authorization$request_method";
177+
if ($combined_ha_rm = POST) {
178+
return 405 "POST method is not allowed";
179+
}
180+
if ($combined_ha_rm = PUT) {
181+
return 405 "PUT method is not allowed";
182+
}
183+
if ($combined_ha_rm = DELETE) {
184+
return 405 "DELETE method is not allowed";
185+
}
186+
187+
if ($http_authorization != "") {
188+
# override with own authentication if provided
189+
set $finalAuth $http_authorization;
190+
}
191+
192+
# allow to upload big layers
193+
client_max_body_size 0;
194+
195+
# only cache GET requests
196+
proxy_cache_methods GET;
197+
EOF
173198
else
174199
cat << 'EOF' > /etc/nginx/conf.d/allowed.methods.conf
175200
# Block POST/PUT/DELETE. Don't use this proxy for pushing.

0 commit comments

Comments
 (0)