Skip to content

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

Open
milanmajchrak wants to merge 6 commits into
customer/lindatfrom
lindat/be-app-files-owned-by-root
Open

milanmajchrak wants to merge 6 commits into
customer/lindatfrom
lindat/be-app-files-owned-by-root

Conversation

@milanmajchrak

Copy link
Copy Markdown
Collaborator

References

dspace-customers issue 1083, finding 6. Same change as #1706 on dtq-dev.

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

The diff is the same as #1706 on dtq-dev and was tested there. /dspace and Tomcat stay root-owned; dspace owns only the data folders, solr/search/conf, Tomcat's webapps and config/item-submission.xml. The do_debug.txt flag of the debug scripts moves 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.

Codex review (gpt-6.2-sol, high): it flagged only the changes listed above. The 2 findings fixed on dtq-dev are in this PR too.

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 17:19
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>
(cherry picked from commit a20e448)
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>
(cherry picked from commit a796f8c)
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 directory permissions cause stats-util -s and stats-util -b cleanup to fail when deleting /dspace/temp, including in documented cron usage, so both cleanup calls need to preserve the directory.

1 open issue
What changed in this PR

Backports the backend image hardening from #1706: DSpace and Tomcat application files remain root-owned while Tomcat runs as dspace.

Changes:

  • Restricts writable paths to runtime data directories and selected configuration and deployment paths.
  • Preserves script execution permissions and prepares required directories.
  • Moves the debug flag to /home/dspace, outside Tomcat’s protected installation.
File Description
scripts/​restart_debug/​undebug.sh Removes the debug flag from its new location.
scripts/​restart_debug/​redebug.sh Creates the debug flag in /home/dspace.
scripts/​restart_debug/​custom_run.sh Reads the relocated flag when selecting debug mode.
Dockerfile Keeps application files root-owned and grants targeted runtime write 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; \
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 <noreply@anthropic.com>

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