From 50263716464550d1bdbd0d2e268f68371c9cfcb7 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 13:19:27 +0100 Subject: [PATCH 1/2] Generate the Shibboleth SP key pair when the container starts The test image ran shib-keygen at build time, so every container shared one key pair stored in an image layer. The startup script now creates it on the first start and keeps an existing or mounted pair. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit d34a597b38349bea223de9f7887be73138def9f0) --- dspace/src/main/docker/README.md | 3 +++ dspace/src/main/docker/dspace-shibboleth/Dockerfile | 1 - .../docker/dspace-shibboleth/httpd-shibd-foreground.sh | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dspace/src/main/docker/README.md b/dspace/src/main/docker/README.md index e800f80d5bc2..83081ab17c63 100644 --- a/dspace/src/main/docker/README.md +++ b/dspace/src/main/docker/README.md @@ -109,6 +109,9 @@ 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/`. + **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..bb409ab0ee72 100644 --- a/dspace/src/main/docker/dspace-shibboleth/Dockerfile +++ b/dspace/src/main/docker/dspace-shibboleth/Dockerfile @@ -42,7 +42,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..483bcfc74fe5 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,14 @@ 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 on the first start, so it is never part of the image. +# -b skips it when the files already exist (e.g. after a restart or when mounted). +shib-keygen -b -o /etc/shibboleth +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 From 9845cdf959fa2515a970ef081e6168729eacc358 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 14:14:17 +0100 Subject: [PATCH 2/2] Create the Apache test certificate when the container starts The startup script now also runs make-ssl-cert, so the image contains no private key file. Existing files are kept. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 4c07eb68098931f651a23ce48756c4b2e3b44ac0) --- dspace/src/main/docker/README.md | 1 + dspace/src/main/docker/dspace-shibboleth/Dockerfile | 5 +++-- .../main/docker/dspace-shibboleth/httpd-shibd-foreground.sh | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/dspace/src/main/docker/README.md b/dspace/src/main/docker/README.md index 83081ab17c63..37e67c895220 100644 --- a/dspace/src/main/docker/README.md +++ b/dspace/src/main/docker/README.md @@ -111,6 +111,7 @@ 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 bb409ab0ee72..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/ 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 483bcfc74fe5..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,9 +14,10 @@ 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 on the first start, so it is never part of the image. -# -b skips it when the files already exist (e.g. after a restart or when mounted). +# 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