From be51f643b872fbd4b4048ac23f743767e74b178d 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 | 2 -- .../docker/dspace-shibboleth/httpd-shibd-foreground.sh | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dspace/src/main/docker/README.md b/dspace/src/main/docker/README.md index 8d7588fd286d..551074b3c348 100644 --- a/dspace/src/main/docker/README.md +++ b/dspace/src/main/docker/README.md @@ -116,6 +116,9 @@ This is a test / demo image which provides an Apache HTTPD proxy (in front of To with mod_shib & Shibboleth installed. 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 79f2921bd7d6..229acd4a763b 100644 --- a/dspace/src/main/docker/dspace-shibboleth/Dockerfile +++ b/dspace/src/main/docker/dspace-shibboleth/Dockerfile @@ -41,8 +41,6 @@ RUN a2enmod ssl proxy proxy_ajp proxy_http shib && \ # Setup Shibboleth configs COPY shibboleth2.xml /etc/shibboleth/ COPY attribute-map.xml /etc/shibboleth/ -RUN cd /etc/shibboleth/ \ - && 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 100644 --- 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 e9f4da321bcbaef1107b266c686537492eda1327 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 551074b3c348..209703acfc3e 100644 --- a/dspace/src/main/docker/README.md +++ b/dspace/src/main/docker/README.md @@ -118,6 +118,7 @@ testing DSpace's Shibboleth integration. It uses https://samltest.id/ as the Shi 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 229acd4a763b..9ab2059c146c 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 100644 --- 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