Skip to content

[dtq-dev-767-base] Fix dspace-customers 1083 finding 6: keep the backend application files owned by root - #1708

Open
milanmajchrak wants to merge 6 commits into
dtq-dev-767-basefrom
767-base/be-app-files-owned-by-root
Open

milanmajchrak wants to merge 6 commits into
dtq-dev-767-basefrom
767-base/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. This branch installs Ant with apt; the PR does not touch that stage. /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>
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>

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

Writable configuration and deployment directories permit code injection, while filesystem permissions break S3 uploads and statistics cleanup.

5 open issues
What changed in this PR

Hardens the backend image for security finding 6 by applying the ownership approach from PR #1706 while continuing to run Tomcat as dspace.

Changes:

  • Keeps application files root-owned, with targeted writable runtime paths and configuration exceptions.
  • Creates required runtime directories and preserves script execution 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 writable location.
scripts/​restart_debug/​redebug.sh Creates the debug flag under /home/dspace.
scripts/​restart_debug/​custom_run.sh Checks the relocated flag when selecting debug startup.
Dockerfile Replaces broad ownership grants with targeted permissions and initializes runtime directories.

Review effort: Balanced

Comment thread Dockerfile
&& 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 \
Comment thread Dockerfile
&& chown dspace:dspace /usr/local/tomcat/webapps \
&& touch /dspace/config/local.cfg \
&& chown root:dspace /dspace/config \
&& chmod 1775 /dspace/config \
Comment thread Dockerfile
# 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 \
temp triplestore upload var; do \
Comment thread Dockerfile
temp triplestore upload var; do \
mkdir -p /dspace/$dir && chown -R dspace:dspace /dspace/$dir; \
done \
&& chown dspace:dspace /dspace/solr/search/conf \
Comment thread Dockerfile
done \
&& chown dspace:dspace /dspace/solr/search/conf \
&& chmod -R a+rX /dspace/bin \
&& mkdir -p /usr/local/tomcat/conf/Catalina/localhost \

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