Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit a7a1a04

Browse files
committed
Enable TLS by default if /ssl directory is present.
Generates needed keys and certs. If only one element in the key/cert pair is present, nothing is overriden; instead, the user is asked to either remove the existing element, or put the missing one back. Uses TLSv1, since TLSv1.1 nor TLSv1.2 are available in the current version of python 2.7. Usage: docker run -d -p 5000:5000 -v /etc/docker/certs.d:/ssl registry There are no breaking changes, since the /ssl directory is not present by default. Signed-off-by: Tibor Vass <[email protected]>
1 parent 14796be commit a7a1a04

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ FROM ubuntu:14.04
1212
RUN apt-get update \
1313
# Install pip
1414
&& apt-get install -y \
15+
curl \
1516
python-pip \
1617
# Install deps for backports.lmza (python2 requires it)
1718
python-dev \
1819
liblzma-dev \
1920
libevent1-dev \
2021
&& rm -rf /var/lib/apt/lists/*
2122

23+
# get generate_cert
24+
RUN curl -L -o /usr/local/bin/generate_cert https://github.com/SvenDowideit/generate_cert/releases/download/0.1/generate_cert-0.1-linux-amd64/ && \
25+
chmod +x /usr/local/bin/generate_cert
26+
2227
COPY . /docker-registry
2328
COPY ./config/boto.cfg /etc/boto.cfg
2429

@@ -37,4 +42,4 @@ ENV SETTINGS_FLAVOR dev
3742

3843
EXPOSE 5000
3944

40-
CMD ["docker-registry"]
45+
CMD ["/docker-registry/run.sh"]

run.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
export ${REGISTRY_HOST:=localhost}
6+
7+
x=0
8+
for f in /ssl/ca.{key,cert}; do
9+
[[ -f $f ]] && x=$((x + 1)) || break
10+
done
11+
case "$x" in
12+
0)
13+
generate_cert -cert=/ssl/ca.cert -key=/ssl/ca.key
14+
;;
15+
1)
16+
echo "Only one of /ssl/ca.key and /ssl/ca.cert was found. Make sure both are either present or absent." && exit 1
17+
;;
18+
esac
19+
20+
x=0
21+
for f in /ssl/registry.{key,crt}; do
22+
[[ -f $f ]] && x=$((x + 1)) || break
23+
done
24+
case "$x" in
25+
0)
26+
generate_cert -cert=/ssl/ca.cert -key=/ssl/ca.key && generate_cert -host="$REGISTRY_HOST" -ca=/ssl/ca.cert -ca-key=/ssl/ca.key -cert=/ssl/registry.crt -key=/ssl/registry.key
27+
;;
28+
1)
29+
echo "Only one of /ssl/registry.key and /ssl/registry.crt was found. Make sure both are either present or absent." && exit 1
30+
;;
31+
esac
32+
33+
# --ssl-version 3 == ssl.PROTOCOL_TLSv1
34+
[[ -d /ssl ]] && export ${GUNICORN_OPTS:="['--certfile','/ssl/registry.crt','--keyfile','/ssl/registry.key','--ca-certs','/ssl/ca.cert','--ssl-version',3]"}
35+
36+
exec "$@"

0 commit comments

Comments
 (0)