Skip to content

Fix dspace-customers 1083 finding 6: keep the backend application files owned by root - #1706

Open
milanmajchrak wants to merge 5 commits into
dtq-devfrom
fix/app-files-owned-by-root
Open

milanmajchrak wants to merge 5 commits into
dtq-devfrom
fix/app-files-owned-by-root

Conversation

@milanmajchrak

@milanmajchrak milanmajchrak commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

References

dspace-customers issue 1083, finding 6. This PR also creates /dspace/sitemaps, which is all that the open PR 1496 does.

Description

The backend image now keeps the DSpace and Tomcat files owned by root. Tomcat still runs as dspace, which owns only the data folders and the few paths listed below.

Instructions for Reviewers

List of changes in this PR:

  • Dockerfile: /dspace and /usr/local/tomcat are no longer owned by dspace. It owns only these:
    • the data folders assetstore, ctqueues, exports, handle-server, imports, log, matomo_reports, reports, sitemaps, temp, triplestore, upload and var (missing ones are created);
    • solr/search/conf, where database migrate writes reindex.flag so the webapp reindexes Discovery;
    • Tomcat's webapps folder. The compose entrypoint relinks the namespace there at every start, so it stays writable;
    • config/item-submission.xml, which admins can edit through /api/admin/configfiles (config.admin.updateable.files).
  • /dspace/config is root:dspace with the sticky bit. DSpace can write its backup files there, but it cannot replace other files. The image ships an empty root-owned local.cfg; a mounted local.cfg replaces it.
  • /dspace/bin gets a+rX, so dspace can still run the installed scripts (the installer makes them 744).
  • conf/Catalina/localhost is created up front, because Tomcat logs an error when it cannot create it.
  • redebug.sh, undebug.sh, custom_run.sh: the do_debug.txt flag moves from Tomcat's bin folder to /home/dspace.

Named volumes that already exist keep their owner, so deployments need no migration. Three things change:

  • If a deployment lists more files than item-submission.xml in config.admin.updateable.files, the API can no longer save those files unless they are mounted writable.
  • A CLI command that writes a file to a relative path (for example dspace metadata-export -f out.csv) now fails, because the working folder is root-owned. So do the solr-*-statistics commands without -d (the export one only prints an error and exits with 0), because they cannot create /dspace/solr-export. Give them a path in a writable folder such as /dspace/exports.
  • dspace stats-util -u can no longer download spider lists into config/spiders. Our cron jobs use only -f, -i and -s.

How to test:

docker build -t dspace-test .
docker run --rm --entrypoint bash dspace-test -c "touch /dspace/config/dspace.cfg; touch /dspace/lib/x.jar; touch /usr/local/tomcat/bin/setenv.sh"

All three touch commands fail with Permission denied.

Also tested with a full build on a stack set up like our deployments, once with the current dtq-dev image and once with this one. Both pass the same checks (start, reindex after the first migration, login, config API save, upload, sitemaps, OAI import, index-discovery, debug restart). Only this one refuses writes to config/dspace.cfg, lib, WEB-INF/lib, bin and Tomcat's bin, conf and lib. The last commit (debug flag, solr-export) was tested on that build with the changed files swapped in.

Codex review (gpt-6.2-sol, high): 2 findings fixed, 1 noted in the list of changes above. The last round flagged only the solr-*-statistics and stats-util -u changes.

AI Disclosure (REQUIRED)

Were AI tools used in the creation of this PR?

  • No (This PR does NOT include AI-generated or AI-assisted content that requires disclosure.)
  • Yes (This PR includes AI-generated or AI-assisted content that requires disclosure.)

Claude Code wrote the change and tested it in Docker as described above.

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & integration tests). Exceptions may be made if previously agreed upon.
  • My PR follows all coding best practices based on the Code Conventions Guide.
  • My PR passes Checkstyle validation based on the Code Style Guide.
  • My PR includes Javadoc for all new (or modified) public methods and classes. It also includes Javadoc for large or complex private methods.
  • My PR passes all tests and includes new/updated Unit or Integration Tests based on the Code Testing Guide.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in any pom.xml), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR modifies REST API endpoints, I've opened a separate REST Contract PR related to this change.
  • If my PR includes new configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

🤖 Generated with Claude Code

milanmajchrak and others added 5 commits November 18, 2026 16:51
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new permissions prevent stats-util -s and -b from deleting /dspace/temp, causing cleanup IOExceptions after Solr updates and affecting documented cron usage.

1 open issue
What changed in this PR

Hardens the backend image by keeping DSpace and Tomcat application files root-owned while retaining targeted write access for the dspace runtime user.

Changes:

  • Restricts runtime ownership to data directories and specific writable paths, including the newly created /dspace/sitemaps.
  • Preserves configuration backups, administrative submission-file edits, and script execution under the tighter permissions.
  • Moves the debug flag from Tomcat’s bin directory to /home/dspace.
File Description
scripts/​restart_debug/​undebug.sh Removes the debug flag from its new home-directory location.
scripts/​restart_debug/​redebug.sh Creates the debug flag in the writable home directory.
scripts/​restart_debug/​custom_run.sh Reads the relocated flag when selecting debug startup.
Dockerfile Keeps application files root-owned and grants targeted runtime access.

Review effort: Balanced

Comment thread Dockerfile
Comment on lines +91 to +92
temp triplestore upload var; do \
mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants