Skip to content

Fix PHP-FPM pool group lookup when primary group name differs from username#92

Merged
peterjaap merged 1 commit into
mainfrom
fix/php-fpm-primary-group-lookup
Apr 21, 2026
Merged

Fix PHP-FPM pool group lookup when primary group name differs from username#92
peterjaap merged 1 commit into
mainfrom
fix/php-fpm-primary-group-lookup

Conversation

@peterjaap
Copy link
Copy Markdown
Collaborator

@peterjaap peterjaap commented Apr 20, 2026

Summary

  • Resolve the PHP-FPM pool group via os/user + GID lookup instead of assuming the primary group name matches the username
  • Route getCurrentUser() through user.Current() as well, so both resolutions share one source of truth and fall back gracefully

Why

On Linux, getCurrentGroup() returned the username verbatim. That works on distros that follow the "user private group" convention (USERGROUPS_ENAB), but breaks as soon as an admin renames the primary group or assigns a shared one. Concrete failure: a user john with primary group john-doe gets a generated pool with group = john, and php-fpm refuses to start:

cannot get gid for group 'john'

Because the pool file is regenerated on every magebox start, hand-patching it doesn't stick — the fix has to live in core.

Test plan

  • make lint (0 issues)
  • make test (all packages pass, including internal/php)
  • Manual verification on a system where id -un != id -gn (e.g. john / john-doe): generated pool contains the correct group and php-fpm starts cleanly

getCurrentGroup() previously returned the username on Linux, which breaks
on systems where the user's primary group has a different name (e.g. a
user 'mitchell' with primary group 'mitchell-de-roode'). php-fpm then
fails to start with "cannot get gid for group 'mitchell'".

Use os/user to look up the actual primary group name by GID, falling
back to the previous behavior only if the lookup fails. Also switch
getCurrentUser() to user.Current() so both resolutions go through the
same source of truth.
@peterjaap peterjaap merged commit 37c6434 into main Apr 21, 2026
11 checks passed
@peterjaap peterjaap deleted the fix/php-fpm-primary-group-lookup branch April 21, 2026 06:43
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