Skip to content

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

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

milanmajchrak wants to merge 6 commits into
customer/mendelufrom
mendelu/be-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. Same idea as #1706 on dtq-dev, written for the Spring Boot image of this branch. This PR also creates /dspace/sitemaps, which is all that the open PR 1498 does.

Description

The backend image now keeps the DSpace files owned by root. DSpace still runs as dspace, which owns only the data folders.

Instructions for Reviewers

List of changes in this PR:

  • Dockerfile: COPY --from=ant_build /dspace $DSPACE_INSTALL drops --chown, so /dspace stays owned by root. dspace owns only the data folders assetstore, ctqueues, exports, handle-server, imports, log, reports, sitemaps, temp, triplestore, upload and var (missing ones are created).
  • /dspace and solr/search/conf are root:dspace with the sticky bit. DSpace can add and remove its own entries there (stats-util -s removes temp, CLI output to a relative path, database migrate writes reindex.flag so DSpace reindexes Discovery at start), but it cannot replace the others.
  • SPRING_CONFIG_LOCATION keeps the Spring Boot defaults except file:./, so Spring Boot does not read an application.properties from the working folder /dspace.
  • /dspace/bin gets a+rX, so dspace can still run the installed scripts (the installer makes them 744).

Named volumes that already exist keep their owner, so deployments need no migration. What changes:

  • dspace stats-util -u can no longer download spider lists into config/spiders, and dspace submission-forms-migrate cannot write its .migrated files into config.

Run CLI commands as dspace, the default for docker exec. DSpace cannot remove what root creates in the sticky folders, for example a reindex.flag from a migration run as root.

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 /dspace/webapps/server-boot.jar"

All three touch commands fail with Permission denied.

Also tested on a stack with PostgreSQL, Solr and named volumes, running database migrate force before the jar: once with the current customer-mendelu image, once with this PR's final stage on top of the install from that image. Both start and answer on /server/api. With the PR image the Discovery reindex after the first migration still runs, stats-util -s ends without an error, an application.properties written to /dspace is ignored after a restart, and writes to config, lib and webapps are refused.

Codex review (gpt-6.2-sol, high), 4 rounds: 2 findings fixed. The last round flagged only the changes listed above, the root-run case, and a run as UID 1100 without the dspace group, which our compose files do not do.

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 2 commits November 18, 2026 18:50
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

🟢 Approval recommended

No active review issues were identified for the Dockerfile ownership-hardening change.

No open issues 🎉

What changed in this PR

Hardens the Spring Boot backend image by keeping application files root-owned while DSpace continues to run as the non-root dspace user. This adapts the ownership approach from PR #1706 to this branch.

Changes:

  • Removes the ownership override when copying the DSpace installation.
  • Creates and grants dspace ownership of runtime data directories, including sitemaps.
  • Keeps solr/search/conf writable for reindex flags and installed scripts readable and executable.
File Description
Dockerfile Restricts runtime write access while preserving data-directory access, Discovery reindexing, and script execution.

Review effort: Balanced

milanmajchrak and others added 2 commits November 18, 2026 21:12
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>
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 <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 writable /dspace working directory lets a compromised backend persist Spring Boot startup configuration through newly created files, so configuration loading must be restricted to packaged and root-controlled paths.

1 open issue

Review effort: Balanced

Comment thread Dockerfile Resolved
milanmajchrak and others added 2 commits November 18, 2026 21:55
/dspace is the working folder and dspace can now add files there. The default Spring
Boot locations stay, except ./ itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

🟢 Approval recommended

No active review issues block the Dockerfile ownership and runtime-permission hardening.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

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