From 876fdf112911ff1528c650fb7d87a825d622bbd9 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 16:25:40 +0100 Subject: [PATCH 1/7] Keep the backend application files owned by root in the Docker image Tomcat still runs as the dspace user. The user can write only to the data folders DSpace uses at runtime, Tomcat's webapps folder and item-submission.xml. The do_debug.txt flag of redebug.sh moves to Tomcat's temp folder, because the bin folder is no longer writable. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit a20e448b12425c58cd6eca0733630ea8b0cea25a) --- Dockerfile | 25 +++++++++++++++++-------- scripts/restart_debug/custom_run.sh | 2 +- scripts/restart_debug/redebug.sh | 2 +- scripts/restart_debug/undebug.sh | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7148af21980..1b37d643f2c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,7 +55,7 @@ ENV DSPACE_INSTALL=/dspace # because Kubernetes deployment accepts only numeric user IDs when specifying the container user. RUN useradd -u 1100 -m -s /bin/bash dspace # Copy the /dspace directory from 'ant_build' container to /dspace in this container -COPY --chown=dspace:dspace --from=ant_build /dspace $DSPACE_INSTALL +COPY --from=ant_build /dspace $DSPACE_INSTALL # Need host command for "[dspace]/bin/make-handle-config" RUN apt-get update \ && apt-get install -y --no-install-recommends host \ @@ -66,7 +66,7 @@ EXPOSE 8080 8009 8000 # Give java extra memory (2GB) ENV JAVA_OPTS=-Xmx2000m COPY scripts/restart_debug/* /usr/local/tomcat/bin -COPY --chown=dspace:dspace scripts/index-scripts/* /dspace/bin +COPY scripts/index-scripts/* /dspace/bin # Link the DSpace 'server' webapp into Tomcat's webapps directory. # This ensures that when we start Tomcat, it runs from /server path (e.g. http://localhost:8080/server/) RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server @@ -77,13 +77,22 @@ RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server # ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT WORKDIR /usr/local/tomcat/bin -RUN chmod u+x redebug.sh undebug.sh custom_run.sh +RUN chmod +x redebug.sh undebug.sh custom_run.sh -RUN mkdir -p /dspace/assetstore \ - && chown dspace:dspace /dspace/assetstore \ - && chown -Rv dspace:dspace /usr/local/tomcat -# NOTE: /dspace/assetstore does not exist in the base image. -# We create it so Docker named volumes inherit the correct ownership. +# App files stay owned by root. The dspace user writes only to the data folders, Tomcat's webapps +# (the compose entrypoint links the namespace there) and item-submission.xml (config.admin.updateable.files). +# The sticky /dspace/config lets DSpace add its backups there, but not replace other files. +# NOTE: missing folders are created so Docker named volumes inherit the correct ownership. # This only works for *named volumes* — bind mounts use host permissions. +# Tomcat only reads conf/Catalina/localhost, but logs an error at start when it cannot create it. +RUN chmod -R a+rX /dspace/bin \ + && mkdir -p /dspace/assetstore /dspace/ctqueues /dspace/imports /dspace/matomo_reports /dspace/sitemaps /dspace/temp \ + /usr/local/tomcat/conf/Catalina/localhost \ + && chown -R dspace:dspace /dspace/assetstore /dspace/ctqueues /dspace/exports /dspace/handle-server \ + /dspace/imports /dspace/log /dspace/matomo_reports /dspace/reports /dspace/sitemaps /dspace/temp \ + /dspace/triplestore /dspace/upload /dspace/var /usr/local/tomcat/webapps \ + && chown root:dspace /dspace/config \ + && chmod 1775 /dspace/config \ + && chown dspace:dspace /dspace/config/item-submission.xml USER dspace diff --git a/scripts/restart_debug/custom_run.sh b/scripts/restart_debug/custom_run.sh index 5fc45b1c0a15..02bb0747fab3 100644 --- a/scripts/restart_debug/custom_run.sh +++ b/scripts/restart_debug/custom_run.sh @@ -1,5 +1,5 @@ #!/bin/bash -FILE=do_debug.txt +FILE=/usr/local/tomcat/temp/do_debug.txt if [ -f "$FILE" ]; then export JPDA_ADDRESS="*:8000" ./catalina.sh jpda run diff --git a/scripts/restart_debug/redebug.sh b/scripts/restart_debug/redebug.sh index 84ae4a08b08b..d2c4c32f1d4a 100644 --- a/scripts/restart_debug/redebug.sh +++ b/scripts/restart_debug/redebug.sh @@ -1,3 +1,3 @@ #!/bin/bash -touch do_debug.txt +touch /usr/local/tomcat/temp/do_debug.txt ./shutdown.sh diff --git a/scripts/restart_debug/undebug.sh b/scripts/restart_debug/undebug.sh index aab52a225961..c708a49df797 100644 --- a/scripts/restart_debug/undebug.sh +++ b/scripts/restart_debug/undebug.sh @@ -1,3 +1,3 @@ #!/bin/bash -rm do_debug.txt +rm /usr/local/tomcat/temp/do_debug.txt ./shutdown.sh From 106a4584cbfbd5eb065fee5e79b5fe5a0f3982ca Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 17:19:51 +0100 Subject: [PATCH 2/7] Create every data folder before giving it to the dspace user Branches whose installation lacks one of the folders would otherwise fail at chown. Tomcat's conf/Catalina/localhost is created root-owned, so Tomcat does not log an error at start. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit a796f8c9be80317f4560c0e67a5e3746c9b2d7f3) --- Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1b37d643f2c7..1372d6c017d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,12 +85,13 @@ RUN chmod +x redebug.sh undebug.sh custom_run.sh # NOTE: missing folders are created so Docker named volumes inherit the correct ownership. # This only works for *named volumes* — bind mounts use host permissions. # Tomcat only reads conf/Catalina/localhost, but logs an error at start when it cannot create it. -RUN chmod -R a+rX /dspace/bin \ - && mkdir -p /dspace/assetstore /dspace/ctqueues /dspace/imports /dspace/matomo_reports /dspace/sitemaps /dspace/temp \ - /usr/local/tomcat/conf/Catalina/localhost \ - && chown -R dspace:dspace /dspace/assetstore /dspace/ctqueues /dspace/exports /dspace/handle-server \ - /dspace/imports /dspace/log /dspace/matomo_reports /dspace/reports /dspace/sitemaps /dspace/temp \ - /dspace/triplestore /dspace/upload /dspace/var /usr/local/tomcat/webapps \ +RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps temp \ + triplestore upload var; do \ + mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ + done \ + && chmod -R a+rX /dspace/bin \ + && mkdir -p /usr/local/tomcat/conf/Catalina/localhost \ + && chown dspace:dspace /usr/local/tomcat/webapps \ && chown root:dspace /dspace/config \ && chmod 1775 /dspace/config \ && chown dspace:dspace /dspace/config/item-submission.xml From 30c270f1c701bc10aadb5f5c690fe76463ec88bd Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 17:31:56 +0100 Subject: [PATCH 3/7] Let the dspace user write the Discovery reindex flag and solr-export The database migration writes solr/search/conf/reindex.flag as dspace, and solr-export-statistics defaults to /dspace/solr-export. The image also ships an empty root-owned local.cfg, and the debug scripts get read rights for all. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1372d6c017d4..48a896d229a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -77,21 +77,25 @@ RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server # ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT WORKDIR /usr/local/tomcat/bin -RUN chmod +x redebug.sh undebug.sh custom_run.sh +RUN chmod a+rx redebug.sh undebug.sh custom_run.sh # App files stay owned by root. The dspace user writes only to the data folders, Tomcat's webapps -# (the compose entrypoint links the namespace there) and item-submission.xml (config.admin.updateable.files). +# (the compose entrypoint links the namespace there), solr/search/conf (reindex.flag after a migration) +# and item-submission.xml (config.admin.updateable.files). # The sticky /dspace/config lets DSpace add its backups there, but not replace other files. +# The empty local.cfg is root-owned too; a mounted local.cfg replaces it. # NOTE: missing folders are created so Docker named volumes inherit the correct ownership. # This only works for *named volumes* — bind mounts use host permissions. # Tomcat only reads conf/Catalina/localhost, but logs an error at start when it cannot create it. -RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps temp \ - triplestore upload var; do \ +RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps \ + solr-export temp triplestore upload var; do \ mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ done \ + && chown dspace:dspace /dspace/solr/search/conf \ && chmod -R a+rX /dspace/bin \ && mkdir -p /usr/local/tomcat/conf/Catalina/localhost \ && chown dspace:dspace /usr/local/tomcat/webapps \ + && touch /dspace/config/local.cfg \ && chown root:dspace /dspace/config \ && chmod 1775 /dspace/config \ && chown dspace:dspace /dspace/config/item-submission.xml From 07d4461d56a3985e49b44e3c40762210b04e0941 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 18:48:21 +0100 Subject: [PATCH 4/7] Shorten the ownership comment in the Dockerfile Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48a896d229a0..f2d882bc7918 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,14 +79,9 @@ RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server WORKDIR /usr/local/tomcat/bin RUN chmod a+rx redebug.sh undebug.sh custom_run.sh -# App files stay owned by root. The dspace user writes only to the data folders, Tomcat's webapps -# (the compose entrypoint links the namespace there), solr/search/conf (reindex.flag after a migration) -# and item-submission.xml (config.admin.updateable.files). -# The sticky /dspace/config lets DSpace add its backups there, but not replace other files. -# The empty local.cfg is root-owned too; a mounted local.cfg replaces it. -# NOTE: missing folders are created so Docker named volumes inherit the correct ownership. -# This only works for *named volumes* — bind mounts use host permissions. -# Tomcat only reads conf/Catalina/localhost, but logs an error at start when it cannot create it. +# App files stay owned by root. dspace writes only to the data folders, Tomcat's webapps (namespace link), +# solr/search/conf (reindex.flag) and item-submission.xml. The sticky config folder takes its backups. +# Missing folders are created so named volumes (not bind mounts) inherit the owner. RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps \ solr-export temp triplestore upload var; do \ mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ From 957e8cfa499fff16b14510089be9b015c20dc2c4 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 20:41:27 +0100 Subject: [PATCH 5/7] Move the debug flag to the dspace home and stop pre-creating solr-export Tomcat's temp folder is writable by every user, so the flag now lives in /home/dspace. solr-reindex-statistics removes its export folder only when it created it, so the image no longer creates /dspace/solr-export. The solr-*-statistics commands take -d instead. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 2 +- scripts/restart_debug/custom_run.sh | 2 +- scripts/restart_debug/redebug.sh | 2 +- scripts/restart_debug/undebug.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index f2d882bc7918..d3a409c0c1ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,7 +83,7 @@ RUN chmod a+rx redebug.sh undebug.sh custom_run.sh # solr/search/conf (reindex.flag) and item-submission.xml. The sticky config folder takes its backups. # Missing folders are created so named volumes (not bind mounts) inherit the owner. RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps \ - solr-export temp triplestore upload var; do \ + temp triplestore upload var; do \ mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ done \ && chown dspace:dspace /dspace/solr/search/conf \ diff --git a/scripts/restart_debug/custom_run.sh b/scripts/restart_debug/custom_run.sh index 02bb0747fab3..695f436f0691 100644 --- a/scripts/restart_debug/custom_run.sh +++ b/scripts/restart_debug/custom_run.sh @@ -1,5 +1,5 @@ #!/bin/bash -FILE=/usr/local/tomcat/temp/do_debug.txt +FILE=/home/dspace/do_debug.txt if [ -f "$FILE" ]; then export JPDA_ADDRESS="*:8000" ./catalina.sh jpda run diff --git a/scripts/restart_debug/redebug.sh b/scripts/restart_debug/redebug.sh index d2c4c32f1d4a..15d46bc30dd9 100644 --- a/scripts/restart_debug/redebug.sh +++ b/scripts/restart_debug/redebug.sh @@ -1,3 +1,3 @@ #!/bin/bash -touch /usr/local/tomcat/temp/do_debug.txt +touch /home/dspace/do_debug.txt ./shutdown.sh diff --git a/scripts/restart_debug/undebug.sh b/scripts/restart_debug/undebug.sh index c708a49df797..56fd06050c93 100644 --- a/scripts/restart_debug/undebug.sh +++ b/scripts/restart_debug/undebug.sh @@ -1,3 +1,3 @@ #!/bin/bash -rm /usr/local/tomcat/temp/do_debug.txt +rm /home/dspace/do_debug.txt ./shutdown.sh From 8f52c7a1a295f0883816c1f576c1a56b5d6da719 Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 21:08:35 +0100 Subject: [PATCH 6/7] Make /dspace sticky so DSpace can remove its own folders stats-util -s and -b delete /dspace/temp when they finish, and solr-reindex-statistics creates and deletes /dspace/solr-export. Both need write access to /dspace. With the sticky bit dspace can add and remove its own entries there, but not the root-owned ones. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d3a409c0c1ff..f89cd43b35b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -80,13 +80,16 @@ WORKDIR /usr/local/tomcat/bin RUN chmod a+rx redebug.sh undebug.sh custom_run.sh # App files stay owned by root. dspace writes only to the data folders, Tomcat's webapps (namespace link), -# solr/search/conf (reindex.flag) and item-submission.xml. The sticky config folder takes its backups. +# solr/search/conf (reindex.flag) and item-submission.xml. /dspace and config are sticky, so dspace can add +# and remove its own entries there (temp folders, config backups), but not replace the others. # Missing folders are created so named volumes (not bind mounts) inherit the owner. RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps \ temp triplestore upload var; do \ mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ done \ && chown dspace:dspace /dspace/solr/search/conf \ + && chown root:dspace /dspace \ + && chmod 1775 /dspace \ && chmod -R a+rX /dspace/bin \ && mkdir -p /usr/local/tomcat/conf/Catalina/localhost \ && chown dspace:dspace /usr/local/tomcat/webapps \ From fe430d0bd7f15eddfa3011f7953d91a6b6d8305c Mon Sep 17 00:00:00 2001 From: milanmajchrak Date: Wed, 18 Nov 2026 21:23:21 +0100 Subject: [PATCH 7/7] Make solr/search/conf sticky instead of owned by dspace DSpace only needs to create and delete reindex.flag there. With the sticky bit it can, while schema.xml and solrconfig.xml stay root-owned. Co-Authored-By: Claude Opus 5.5 --- Dockerfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f89cd43b35b7..7bc6cb1b54d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,17 +79,16 @@ RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server WORKDIR /usr/local/tomcat/bin RUN chmod a+rx redebug.sh undebug.sh custom_run.sh -# App files stay owned by root. dspace writes only to the data folders, Tomcat's webapps (namespace link), -# solr/search/conf (reindex.flag) and item-submission.xml. /dspace and config are sticky, so dspace can add -# and remove its own entries there (temp folders, config backups), but not replace the others. +# App files stay owned by root. dspace writes only to the data folders, Tomcat's webapps (namespace link) +# and item-submission.xml. /dspace, config and solr/search/conf are sticky, so dspace can add and remove +# its own entries there (temp folders, config backups, reindex.flag), but not replace the others. # Missing folders are created so named volumes (not bind mounts) inherit the owner. RUN for dir in assetstore ctqueues exports handle-server imports log matomo_reports reports sitemaps \ temp triplestore upload var; do \ mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \ done \ - && chown dspace:dspace /dspace/solr/search/conf \ - && chown root:dspace /dspace \ - && chmod 1775 /dspace \ + && chown root:dspace /dspace /dspace/solr/search/conf \ + && chmod 1775 /dspace /dspace/solr/search/conf \ && chmod -R a+rX /dspace/bin \ && mkdir -p /usr/local/tomcat/conf/Catalina/localhost \ && chown dspace:dspace /usr/local/tomcat/webapps \