Skip to content

Hand panel-written server files to the game container's user - #343

Merged
athNdev merged 1 commit into
mainfrom
fix/server-file-ownership
Nov 4, 2026
Merged

athNdev merged 1 commit into
mainfrom
fix/server-file-ownership

Conversation

@athNdev

@athNdev athNdev commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Problem

A modpack server could not start. The live console showed it exiting at boot:

me.itzg.helpers.properties.SetPropertiesCommand
  at java.base/java.nio.file.Files.newBufferedWriter(Unknown Source)
[init] [ERROR] Failed to update server.properties

server.properties, ops.json, whitelist.json and user_jvm_args.txt in the server's data directory were owned by root and mode 0644, while the game container runs as uid 1000. The itzg image rewrites server.properties on every boot, so the server crash-looped. It reads as a mod or modpack failure; it is an ownership failure.

The files came from a server pack unzipped through the panel. The panel runs as root, the game does not, and both use the same bind mount, so every file the panel writes into a server's data directory was root-owned: extraction, uploads, file edits and restore.

Fix

files.AdoptOwnership(reference, target, recursive) copies the reference's uid/gid onto what was just written, skipping paths that already match. Applied at the seams where the panel mutates a server's data directory:

  • archive extraction (the path that produced this),
  • file upload,
  • file edit,
  • restore, which captures the owner of the tree being replaced before the swap and reapplies it after.

It is a no-op when the platform has no uid/gid model, which keeps the Windows build and the Windows-native development path unchanged (ownership_windows.go).

Verification

  • go build ./... on Windows and GOOS=linux; go vet ./pkg/files
  • go test ./pkg/files ./internal/rpc/services green
  • New tests: ownership is copied to a tree, a missing reference changes nothing, and a matching owner is left alone
  • Reproduced and confirmed on a live instance: a server whose data directory had root-owned server.properties crash-looped; after handing the directory to uid 1000 it started and reached "Done (5.898s)!" with the world intact

Refs OSS-238, OSS-247

The panel runs as root and the game container runs unprivileged, but
they share a bind-mounted data directory. Anything the panel wrote there
was root-owned mode 0644, so the game could not rewrite it. A modpack
whose server pack was extracted through the panel then crash-looped on
Failed to update server.properties, which reads as a mod bug.

files.AdoptOwnership copies the data directory's uid/gid onto what was
just written. Applied after extraction, upload, file update and a
restore's tree swap; a no-op when ownership already matches and on
Windows, which has no uid/gid model.
@athNdev

athNdev commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

End-to-end evidence on a live instance (panel container runs as root, game container as uid 1000):

# same directory, same container
docker exec carbon-panel-review touch .../root-probe.txt  ->  owner=0:0
POST FileService/UpdateFile (ownership-probe.txt)         ->  owner=1000:1000 mode=644

The panel write now lands with the data directory's owner instead of root's, which is the exact file the game needs to rewrite on boot.

@athNdev
athNdev merged commit 6e17ab0 into main Nov 4, 2026
11 checks passed
@athNdev
athNdev deleted the fix/server-file-ownership branch November 4, 2026 08:12
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.

1 participant