File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ RUN set -x \
131131# supervisord
132132COPY resources/supervisord.conf /etc/
133133
134- # Install j2cli
134+ # Install jinja2-cli and certbot
135135RUN set -x \
136136 && apt-get update \
137137 && apt-get -y --no-install-recommends --no-install-suggests install \
@@ -140,7 +140,7 @@ RUN set -x \
140140 && rm -rf /var/lib/apt/lists/* \
141141 && mkdir /opt/venv \
142142 && python3 -m venv /opt/venv \
143- && /opt/venv/bin/pip install --no-cache-dir jinja2-cli
143+ && /opt/venv/bin/pip install --no-cache-dir jinja2-cli certbot
144144
145145ENV PATH=/opt/venv/bin:$PATH
146146
@@ -150,12 +150,17 @@ COPY resources/etc/templates /etc/templates
150150# Set the current working directory
151151WORKDIR /var/www/html
152152
153- # Expose port 80
153+ # Expose port 80, 443
154154EXPOSE 80
155155EXPOSE 443
156156
157- COPY resources/scripts/start.sh /
158- RUN chmod +x /start.sh
157+ COPY --chmod=755 resources/scripts/start.sh /
158+ COPY --chmod=755 resources/scripts/acme-init.sh /
159+ COPY --chmod=755 resources/scripts/acme-renew.sh /
160+ COPY --chmod=755 resources/scripts/reload-nginx /
161+ COPY --chmod=755 resources/scripts/healthcheck.sh /
162+
163+ HEALTHCHECK --interval=30s --timeout=3s --retries=3 --start-period=10s --start-interval=1s CMD /healthcheck.sh
159164
160165COPY --chown=www-data:www-data resources/htdocs/php /var/www/htdocs/php
161166COPY --chown=www-data:www-data resources/html /var/www/htdocs/html
Original file line number Diff line number Diff line change 11@reboot /bin/sleep 10 && /usr/bin/curl --silent --insecure "https://localhost/simplesaml/module.php/cron/run/daily/{{ environ("CRON_SECRET") }}"
220 0 * * * /usr/bin/curl --silent --insecure "https://localhost/simplesaml/module.php/cron/run/daily/{{ environ("CRON_SECRET") }}"
3-
3+ {% if environ ("ACME_ENABLED" ) %} 0 1 * * 1 /acme-renew.sh
4+ {% endif -%}
Original file line number Diff line number Diff line change @@ -44,7 +44,14 @@ http {
4444 server {
4545 listen 80;
4646 server_name hub;
47- rewrite ^ https://$host$request_uri? permanent;
47+ root /var/www/htdocs;
48+
49+ location /.well-known/acme-challenge/ {
50+ }
51+
52+ location / {
53+ return 301 https://$host$request_uri;
54+ }
4855 }
4956
5057 server {
5360 root /var/www/htdocs;
5461 index login.php logout.php;
5562
56- ssl_certificate "/etc/nginx/certs/auth-proxy.chained .cer";
57- ssl_certificate_key "/etc/nginx/certs/auth-proxy .key";
63+ ssl_certificate "/etc/nginx/live- certs/server .cer";
64+ ssl_certificate_key "/etc/nginx/live- certs/server .key";
5865
5966 ssl_ciphers "AES128+EECDH:AES128+EDH";
6067 ssl_protocols TLSv1.2;
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -xe
4+
5+ CERTBOT_OPT=' '
6+ CERTBOT_SERVER_OPT=' '
7+
8+ if [[ ! -z " ${ACME_SERVER} " ]] ; then
9+ CERTBOT_SERVER_OPT=" --server ${ACME_SERVER} "
10+ fi
11+
12+ CERTBOT_OPT=' '
13+ if [[ ! -z " ${ACME_EAB_KID} " ]] ; then
14+ CERTBOT_OPT=" ${CERTBOT_OPT} --eab-kid ${ACME_EAB_KID} "
15+ fi
16+ if [[ ! -z " ${ACME_EAB_HMAC_KEY} " ]] ; then
17+ CERTBOT_OPT=" ${CERTBOT_OPT} --eab-hmac-key ${ACME_EAB_HMAC_KEY} "
18+ fi
19+ if [[ ! -z " ${ACME_EAB_HMAC_ALG} " ]] ; then
20+ CERTBOT_OPT=" ${CERTBOT_OPT} --eab-hmac-alg ${ACME_EAB_HMAC_ALG} "
21+ fi
22+ if [[ ! -z " ${ACME_EMAIL} " ]] ; then
23+ CERTBOT_OPT=" ${CERTBOT_OPT} -m ${ACME_EMAIL} "
24+ fi
25+ if [[ ! -z " ${ACME_KEY_TYPE} " ]] ; then
26+ CERTBOT_OPT=" ${CERTBOT_OPT} --key-type ${ACME_KEY_TYPE} "
27+ fi
28+
29+ cleanup () {
30+ rm -f /.acme-init
31+ }
32+
33+ trap ' cleanup' EXIT
34+
35+ if [[ ! -d /etc/letsencrypt/live/${MASTER_FQDN} ]]; then
36+ touch /.acme-init
37+ # wait for the service to become healthy
38+ time_wait_for_running=" ${TIME_WAIT_FOR_RUNNING:- 1} "
39+ sleep ${time_wait_for_running}
40+ certbot certonly --debug -vvv -n \
41+ --standalone \
42+ -d ${MASTER_FQDN} \
43+ ${CERTBOT_SERVER_OPT} \
44+ ${CERTBOT_OPT} \
45+ --agree-tos \
46+ --no-eff-email
47+ fi
48+
49+ echo " certbot certificates"
50+ certbot ${CERTBOT_SERVER_OPT} certificates || true
51+
52+ ln -s -f /etc/letsencrypt/live/${MASTER_FQDN} /fullchain.pem /etc/nginx/live-certs/server.cer
53+ ln -s -f /etc/letsencrypt/live/${MASTER_FQDN} /privkey.pem /etc/nginx/live-certs/server.key
54+ ln -s -f /reload-nginx /etc/letsencrypt/renewal-hooks/deploy/reload-nginx
55+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -e
4+
5+ CERTBOT_OPT=' '
6+ if [[ ! -z " ${ACME_KEY_TYPE} " ]] ; then
7+ CERTBOT_OPT=" ${CERTBOT_OPT} --key-type ${ACME_KEY_TYPE} "
8+ fi
9+
10+ if [[ -d /etc/letsencrypt/live/${MASTER_FQDN} ]]; then
11+ /opt/venv/bin/certbot renew ${CERTBOT_OPT} --webroot -w /var/www/htdocs " $@ "
12+ fi
13+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ set -xe
4+
5+ if [[ -e /.acme-init ]]; then
6+ exit 0
7+ fi
8+
9+ curl -k -f https://localhost/php/login.php
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ /usr/sbin/nginx -s reload
Original file line number Diff line number Diff line change 33
44TEMPLATE_DIR=/etc/templates
55
6+ ACME_CONFIG_FILE=${ACME_CONFIG_FILE:- acme-config}
7+
8+ if [[ -e " /run/secrets/${ACME_CONFIG_FILE} " ]]; then
9+ source " /run/secrets/${ACME_CONFIG_FILE} "
10+ export ACME_SERVER \
11+ ACME_EAB_KID \
12+ ACME_EAB_HMAC_KEY \
13+ ACME_EAB_HMAC_ALG \
14+ ACME_EMAIL \
15+ ACME_KEY_TYPE
16+ fi
17+
18+ CERT_DIR=/etc/nginx/certs
19+ mkdir -p /etc/nginx/live-certs
20+ if [[ -e $CERT_DIR /server.cer ]] && [[ -e $CERT_DIR /server.key ]]; then
21+ ln -s -f $CERT_DIR /server.cer /etc/nginx/live-certs/server.cer
22+ ln -s -f $CERT_DIR /server.key /etc/nginx/live-certs/server.key
23+ else
24+ export ACME_ENABLED=1
25+ /acme-init.sh
26+ fi
27+
628if [[ -z ${SIMPLESAMLPHP_ADMIN_PASSWORD} ]]; then
729 export SIMPLESAMLPHP_ADMIN_PASSWORD=$( LC_ALL=C tr -dc ' A-Za-z0-9' < /dev/urandom | head -c 12)
830fi
@@ -30,4 +52,4 @@ elif [[ "$ENABLE_FEDERATION" == "1" || "$ENABLE_FEDERATION" == "yes" ]]; then
3052 jinja2 ${TEMPLATE_DIR} /authsources.php.j2 -o /var/www/simplesamlphp/config/authsources.php
3153fi
3254
33- /usr/bin/supervisord -n -c /etc/supervisord.conf
55+ exec /usr/bin/supervisord -n -c /etc/supervisord.conf
You can’t perform that action at this time.
0 commit comments