Skip to content

fix(packaging): let root own what the root scripts execute - #23

Merged
chrip merged 1 commit into
mainfrom
fix/root-owned-packaging-main
Nov 4, 2026
Merged

chrip merged 1 commit into
mainfrom
fix/root-owned-packaging-main

Conversation

@chrip

@chrip chrip commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

This brings b85c4f17 from master to main. It was merged into master on 2026-11-02 by mistake: main is the branch the releases are built from, so the change is missing from 9.3.8-rc.1.

The commit is a plain cherry-pick (-x) with no changes. It applies cleanly to current main: 3 files, +38/−5 (deb/template/postinst.m4, rpm/common.spec, documentserver-generate-allfonts.sh.m4). The change was already reviewed and approved on its original PR.

One note on the commit message: it mentions a chown ds:ds companion for the orchestrated image. The companion that was actually merged instead is DocumentServer#502, which drops the chmod on FileConverter/bin from the orchestrated font init. #502 is already on main and in rc.1, so this PR has no other dependency.

After merging, this needs /backport to stable-9.3.8 so it lands in rc.2.

🤖 Generated with Claude Code

The installation hands the application tree to the unprivileged ds user: the
deb postinst ends its configure step with a chown of everything under
/var/www/<product> to ds, and the rpm files section says the same with
%attr(550, ds, ds). Among those files are programs the helpers in /usr/bin run
as root: allfontsgen, allthemesgen and pluginsmanager in server/tools, and the
converter x2t together with the libraries it loads through LD_LIBRARY_PATH.
Whoever owns a file can chmod it and write it, so ds can put its own code into
one of them and have the next font regeneration, or the next plugin install,
run it as root. The sudoers grant lets ds start the font script as root itself.

What root executes is now owned by root. The rpm already said so for the shared
libraries in FileConverter/bin; it says it for the tools and for x2t too, and
the blanket chown in the postinst gets the matching exception. The directories
holding them belong to root for the same reason: chmod a-w does not hold
against the owner of a directory, who can make it writable again, and in a
writable directory ds can replace x2t whoever owns the file. That holds for
every directory on the way down, so the application root, server/,
server/FileConverter/ and npm/ become root's too: in a ds owned server/, ds can
rename the root owned tools/ aside and put its own in its place. Only the
directories change owner; what is in them keeps its owner. The json helper
the root scripts parse configuration with moves to root as well.

The font script stops handing the whole converter directory back to ds after
each run and names the three files it generated instead, otherwise it would
undo the fix on the next regeneration. It uses chown -h, so a symlink in place
of one of those names is changed itself, as chown -R did before, rather than
the file it points at.

The generators keep running as root in the packaged install: the tree is write
protected for ds on purpose. The orchestrated image is different. It installs
this rpm with --noscripts, carries the ownership over with COPY --from, and runs
its font init as ds, which chmods and writes server/FileConverter/bin. That
directory is now root's there as well, so the image needs a matching
chown ds:ds of it in its docs stage, where nothing runs as root.

Checked: the chown sequence taken from the rendered postinst and font script,
replayed on a model tree, leaves the programs, their two directories and the
json helper root owned and the generated font files with ds, for the plain
install and the container variant that skips the chowns, while the templates
before this change leave them with ds. As root in a container, ds replaced a
root owned x2t inside a ds owned directory, including one left at a-w, and
could not inside a root owned one, nor by renaming a directory on the way down
aside; and the font script's chown no longer gives
ds the target of a symlinked fonts.log. rpmbuild of the files section shows
the directories and the programs as root 755 and docservice and docbuilder
still with ds.

The sudoers file is untouched: the three commands in it are what the
application legitimately asks for, and it was the writable programs behind
them that made the escalation possible. An existing installation is repaired
by the next package upgrade, which runs the configure step again.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
(cherry picked from commit b85c4f1)
Signed-off-by: Christoph Schaefer <christoph.schaefer@nextcloud.com>
@chrip
chrip requested review from juliusknorr and rikled November 4, 2026 14:51
@chrip chrip added this to the 9.3.8 milestone Nov 4, 2026
@chrip
chrip merged commit 4d982be into main Nov 4, 2026
2 checks passed
@chrip

chrip commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/backport to stable-9.3.8

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