forked from RoushTech/docker
frankenphp: keep groups, HOME and the session dir across the privilege drop #31
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/frankenphp-privilege-drop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Three bugs with one root cause area: the frankenphp service script dropped
privileges with
chpst -u app, and everything root was carrying — groups,HOME, directory ownership — either got thrown away or came along unchangedwhen it should not have.
All three failed quietly. Nothing crashed; the image just did less than it
claimed. That is the main reason each fix here comes with an assertion.
#22 — supplementary groups
chpstsets only uid and gid, soaddgroup app <group>before the servicestarts was a silent no-op. Replaced with
su-exec, which callsinitgroups()(new apk package, ~10KB). Verified against a real bind-mounted socket:
That is the Docker Engine API
/versionendpoint, unreachable before andanswering now.
#23 — session directory
The
php-ztspackage pointssession.save_pathat/var/lib/php-zts/session,owned
root:frankenphp 0770— unwritable byapp, so every session read andwrite failed with a warning and nobody stayed logged in. The directory now
belongs to
app, with the group and mode kept so membership of thefrankenphpgroup still grants access (which now actually works, given #22).The path is read back from
ini_get()at build time rather than hardcoded.Before / after, same probe page, two requests with a cookie jar:
#24 — HOME
Half of this was already fixed on main but unreleased:
25aba96addedXDG_DATA_HOME=/var/cache/frankenphp, and I confirmed by building main thatFRANKENPHP_MERCURE=Ondoes boot and serve the hub — the blocking error inthe issue is gone. It is not fully fixed, though.
HOMEwas still/root, somain logs on every boot:
and
~resolved somewhere the server cannot read, hiding theknown_hoststheimage installs in the app user's home.
HOMEnow follows the drop; that erroris gone and the container logs zero Caddy errors.
Test coverage
appsurvives the drop. This has tobe root-side, so it is a
RUNin the Dockerfile rather than a/etc/validate.dscript —validateruns each script asappviasu./etc/validate.d/frankenphp.shassertssession.save_pathis writable.Running as
appis exactly right here: it is the server's own view.frankenphp-85-session-healthchecks(new) is healthy only when a sessionsurvives between two requests and the server reports the app user's
HOME.Confirmed it goes unhealthy against a pre-fix image.
frankenphp-85-mercure-healthchecksnow asks the hub for a subscriptioninstead of settling for the site root, so it exercises the bolt store under
XDG_DATA_HOME— the thing #24 was about.Verification
./testgreen locally, and./test test-frankenphpgreen across 8.2/8.3/8.4/8.5 on native aarch64.
Worth flagging about CI: the
testjob does not build the FrankenPHP images(they are behind the separate
test-frankenphpgroup, per the x86-64-v3/v4note in the README), so a green run here does not exercise the new session
healthcheck. The
buildjob does bake the images on both arches, so the twobuild-time assertions are covered by CI.
Closes #22
Closes #23
Closes #24