[PR #5324] [MERGED] fix: repair mixed Docker data ownership before dropping privileges #6729

Closed
opened 2026-10-23 04:13:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5324
Author: @NeoKazuya
Created: 8/20/2026
Status: ✅ Merged
Merged: 8/20/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/docker-nested-ownership-repair


📝 Commits (1)

  • d44ed28 fix: repair mixed Docker data ownership

📊 Changes

2 files changed (+46 additions, -10 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 scripts/docker-entrypoint.mjs (+45 -10)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #5323

Why this change

  • Marinara's Docker entrypoint only runs its recursive ownership repair when a configured data or storage root has the wrong owner. A volume can instead have correctly owned roots with mismatched descendants, so the app drops to its non-root runtime identity without repairing them. Private-storage hardening then cannot tighten those descendants and startup fails with EPERM.
  • During startup, Marinara applies private permissions throughout the configured storage tree, so an ownership mismatch anywhere inside it can prevent startup. Applying the same deep scan to all of /app/data would unnecessarily traverse large galleries and media folders, so this extends the existing repair more selectively: retain the full-tree repair for a moved or restored data root, deeply check the configured storage tree, and recursively repair mismatched immediate children commonly introduced by copying or restoring folders into an existing data directory.

What changed

  • Added ownership discovery for mismatched immediate children when the data root is already correct, plus a deep check of the configured file-storage tree so nested mismatches cannot be hidden by a correctly owned storage root.
  • Changed ownership only for mismatched entries and deduplicated overlapping repair paths, so nested storage is not traversed twice and correctly owned non-storage trees do not receive a deep scan.
  • Preserved the existing full-tree repair when the data root belongs to a different UID/GID, along with runtime user resolution and MARINARA_SKIP_DATA_CHOWN.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • A disposable named-volume test using the exact Node 24 base pinned by the regular Dockerfile verified a correctly owned data root with mismatched storage and top-level descendants. The entrypoint repaired only those entries before the command ran as UID/GID 1000.
  • The same disposable Docker fixture was changed to a completely root-owned restored data folder. The existing full-tree repair remained effective, storage was not traversed twice, and the command again ran as UID/GID 1000.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

No UI changes.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Docker startup handling for mixed file-storage ownership.
    • Imported top-level data folders are now correctly repaired when the data root already belongs to the runtime user.
    • Ownership repairs now target only mismatched files and folders, reducing unnecessary changes.
    • Startup logs report the number of ownership repairs performed.
  • Documentation

    • Added an unreleased changelog entry describing the Docker startup repairs.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5324 **Author:** [@NeoKazuya](https://github.com/NeoKazuya) **Created:** 8/20/2026 **Status:** ✅ Merged **Merged:** 8/20/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/docker-nested-ownership-repair` --- ### 📝 Commits (1) - [`d44ed28`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d44ed28ed0a78ba2d5ecb8291ef16c22609c5fe3) fix: repair mixed Docker data ownership ### 📊 Changes **2 files changed** (+46 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `scripts/docker-entrypoint.mjs` (+45 -10) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #5323 ## Why this change - Marinara's Docker entrypoint only runs its recursive ownership repair when a configured data or storage root has the wrong owner. A volume can instead have correctly owned roots with mismatched descendants, so the app drops to its non-root runtime identity without repairing them. Private-storage hardening then cannot tighten those descendants and startup fails with `EPERM`. - During startup, Marinara applies private permissions throughout the configured storage tree, so an ownership mismatch anywhere inside it can prevent startup. Applying the same deep scan to all of `/app/data` would unnecessarily traverse large galleries and media folders, so this extends the existing repair more selectively: retain the full-tree repair for a moved or restored data root, deeply check the configured storage tree, and recursively repair mismatched immediate children commonly introduced by copying or restoring folders into an existing data directory. ## What changed - Added ownership discovery for mismatched immediate children when the data root is already correct, plus a deep check of the configured file-storage tree so nested mismatches cannot be hidden by a correctly owned storage root. - Changed ownership only for mismatched entries and deduplicated overlapping repair paths, so nested storage is not traversed twice and correctly owned non-storage trees do not receive a deep scan. - Preserved the existing full-tree repair when the data root belongs to a different UID/GID, along with runtime user resolution and `MARINARA_SKIP_DATA_CHOWN`. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - A disposable named-volume test using the exact Node 24 base pinned by the regular Dockerfile verified a correctly owned data root with mismatched storage and top-level descendants. The entrypoint repaired only those entries before the command ran as UID/GID 1000. - The same disposable Docker fixture was changed to a completely root-owned restored data folder. The existing full-tree repair remained effective, storage was not traversed twice, and the command again ran as UID/GID 1000. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved Docker startup handling for mixed file-storage ownership. * Imported top-level data folders are now correctly repaired when the data root already belongs to the runtime user. * Ownership repairs now target only mismatched files and folders, reducing unnecessary changes. * Startup logs report the number of ownership repairs performed. * **Documentation** * Added an unreleased changelog entry describing the Docker startup repairs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:13:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6729
No description provided.