From c38d6b0fe3440b71e9e4f9ddae05b81a52160c75 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 cdce1f4184a7..5c4934f4d050 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,7 +60,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 \ @@ -71,7 +71,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 @@ -82,13 +82,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 b7f44f9fa7af9e6b94a6ffcf45bd0890a8d07a15 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 5c4934f4d050..d72dc1cb62b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -90,12 +90,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 9c05f89be31bbd9e17a59874efd671b239b8d0f6 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 d72dc1cb62b7..3bd14760fb3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -82,21 +82,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 30c110484ef02d5d4f3401e84f7a42b8329651b9 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 3bd14760fb3d..de045a4e6e2c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,14 +84,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 f4718d0da3b4b2e2acf8ae6eb3141890914661b7 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 de045a4e6e2c..b21acf8c9515 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,7 +88,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 1354e7a38dbff31074c7f108dacc71075ece88a3 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 b21acf8c9515..48d58184d3c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,13 +85,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 aaf6384a085df8402d3b14967b304b0d8a1d65aa 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 48d58184d3c3..fa2283cf997b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,17 +84,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 \