diff --git a/dspace/src/main/docker/README.md b/dspace/src/main/docker/README.md index e800f80d5bc2..37e67c895220 100644 --- a/dspace/src/main/docker/README.md +++ b/dspace/src/main/docker/README.md @@ -109,6 +109,10 @@ with `mod_shib` & Shibboleth installed based on the It is primarily for usage for testing DSpace's Shibboleth integration. It uses https://samltest.id/ as the Shibboleth IDP +The SP key pair (`sp-key.pem`, `sp-cert.pem`) is created when a container starts for the first time, +so each container has its own. To keep a fixed key, mount both files into `/etc/shibboleth/`. +Apache's self-signed `ssl-cert-snakeoil` certificate is also created at the first start. + **This image is built manually.** It should be rebuilt as needed. ``` diff --git a/dspace/src/main/docker/dspace-shibboleth/Dockerfile b/dspace/src/main/docker/dspace-shibboleth/Dockerfile index 5a92c96e02b6..29d09ea5eb41 100644 --- a/dspace/src/main/docker/dspace-shibboleth/Dockerfile +++ b/dspace/src/main/docker/dspace-shibboleth/Dockerfile @@ -21,7 +21,7 @@ ENV APACHE_PID_FILE=/var/run/apache2/apache2.pid ENV APACHE_SERVER_NAME=localhost # Ensure Apache2, mod_shib & shibboleth daemon are installed. -# Also install ssl-cert to provide a local SSL cert for use with Apache +# Also install ssl-cert to provide a local SSL cert for use with Apache (created at container start) RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ apache2 \ @@ -30,7 +30,8 @@ RUN apt-get update \ libapache2-mod-shib2 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ - && rm -rf /tmp/* + && rm -rf /tmp/* \ + && rm -f /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/certs/ssl-cert-snakeoil.pem # Setup Apache configs & enable mod-shib & dspace vhost COPY dspace-vhost.conf /etc/apache2/sites-available/ @@ -42,7 +43,6 @@ RUN a2enmod ssl proxy proxy_ajp proxy_http shib && \ WORKDIR /etc/shibboleth COPY shibboleth2.xml . COPY attribute-map.xml . -RUN shib-keygen # Copy over our startup script COPY httpd-shibd-foreground.sh /usr/local/bin/ diff --git a/dspace/src/main/docker/dspace-shibboleth/httpd-shibd-foreground.sh b/dspace/src/main/docker/dspace-shibboleth/httpd-shibd-foreground.sh index e265f064ff43..96fba7af1b28 100755 --- a/dspace/src/main/docker/dspace-shibboleth/httpd-shibd-foreground.sh +++ b/dspace/src/main/docker/dspace-shibboleth/httpd-shibd-foreground.sh @@ -14,6 +14,15 @@ set -e # $APACHE_SERVER_NAME environment variable. sed -i "s/\${APACHE_SERVER_NAME}/$APACHE_SERVER_NAME/g" /etc/shibboleth/shibboleth2.xml +# Create the SP key pair and the Apache test certificate on the first start, so no private key is in the image. +# Existing or mounted files are kept (-b makes shib-keygen skip them instead of failing). +shib-keygen -b -o /etc/shibboleth +DEBIAN_FRONTEND=noninteractive make-ssl-cert generate-default-snakeoil +if [ ! -s /etc/shibboleth/sp-key.pem ] || [ ! -s /etc/shibboleth/sp-cert.pem ]; then + echo "Both sp-key.pem and sp-cert.pem must exist in /etc/shibboleth." >&2 + exit 1 +fi + # Start the Shibboleth daemon /etc/init.d/shibd start