Skip to content

[Feat] Reuse Isolated User + Default Username#1087

Open
RichardAnderson wants to merge 3 commits into
vitodeploy:4.xfrom
RichardAnderson:feat/reuse-isolated-user
Open

[Feat] Reuse Isolated User + Default Username#1087
RichardAnderson wants to merge 3 commits into
vitodeploy:4.xfrom
RichardAnderson:feat/reuse-isolated-user

Conversation

@RichardAnderson
Copy link
Copy Markdown
Member

@RichardAnderson RichardAnderson commented May 15, 2026

This pull request introduces significant improvements to the handling of isolated users and PHP version management for sites, focusing on safety, concurrency, and user experience. The main changes include the addition of distributed locking to prevent race conditions when manipulating isolated users, improved validation and error handling, and new endpoints and utilities for managing and suggesting isolated usernames. It also improves the existing reserved user name list to prevent the use of system or privileged accounts as site users, as well as allow isolated users to be shared across sites.

Isolated User Selection
CleanShot 2026-05-15 at 13 44 46
Isolated User Default
CleanShot 2026-05-15 at 13 45 21
Change Isolated User / Create New
CleanShot 2026-05-15 at 13 46 16

Concurrency and Safety Improvements:

  • Added distributed locking (isolatedUserLock) when creating, deleting, or modifying isolated users and their PHP FPM pools to prevent race conditions and ensure that only one operation can proceed per user at a time. This affects site deletion, PHP version updates, and user isolation logic. User-friendly validation errors are now returned if a lock cannot be acquired.
  • Refactored site deletion and PHP version change logic to use the new locking mechanism and to avoid deleting shared users or FPM pools if they are still in use by sibling sites.

Validation and Reserved User Names:

  • Introduced a reserved_user_names configuration to block the use of system/service accounts as site users, and updated validation logic to enforce this restriction. The reserved list is now shared with the frontend for consistent validation.

API and Utility Additions:

  • Added a new backend action and API endpoint to list all isolated users and their site counts per server, supporting better UI/UX for user selection and management.
  • Introduced utility methods on the Site model to check if a user or PHP FPM pool is shared with sibling sites, supporting safer resource cleanup.

Frontend Enhancements:

  • Added isolated user name suggestion logic in the site creation form, using the reserved names and existing users to suggest safe, unique, and valid usernames.

Codebase Cleanup:

  • Removed the now-obsolete changePHPVersion method from the Site model, centralizing PHP version switching logic in the action class for better separation of concerns.

These changes collectively enhance the reliability, safety, and usability of isolated user management and PHP version switching in the application.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Allows multiple sites on the same server to share an isolated Linux user (and FPM pool) safely. Adds distributed locking around isolated-user mutations, a reserved-username blocklist, an API + UI for picking/creating isolated users on site creation, and refactors PHP-version switching out of the Site model into the action layer.

Changes:

  • Concurrency: introduces Server::isolatedUserLock() and wraps create / delete / PHP-version-switch flows in it; refuses to delete users/pools still used by sibling sites.
  • Validation/UX: adds reserved_user_names config (shared with frontend), drops the per-server unique-user constraint, adds GetIsolatedUsers action + sites.isolated-users endpoint, and a new IsolatedUserSelect combobox with auto-suggested usernames.
  • Idempotency: create-isolated-user.blade.php short-circuits if the user already exists and tightens home-dir permissions.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/Feature/SitesTest.php Adds tests for reuse, isolated-users endpoint, shared-user delete, and PHP version switch behavior.
resources/views/ssh/os/create-isolated-user.blade.php Skips creation if user exists; uses mkdir -p and tighter chmods.
resources/js/types/index.d.ts Exposes reserved_user_names on the shared configs.site type.
resources/js/pages/sites/components/isolated-user-select.tsx New combobox listing existing isolated users with site counts and a "create new" affordance.
resources/js/pages/sites/components/create-site.tsx Wires the new select, suggests usernames using existing+reserved, invalidates query on submit.
config/core.php Adds the reserved_user_names blocklist.
app/SiteTypes/AbstractSiteType.php Locks isolation; skips user/FPM-pool creation when already shared with siblings.
app/Models/Site.php Removes changePHPVersion; adds userSharedWithSiblings/fpmPoolSharedWithSiblings helpers.
app/Models/Server.php Adds isolatedUserLock() cache lock helper.
app/Http/Middleware/HandleInertiaRequests.php Shares reserved usernames with the frontend.
app/Http/Controllers/SiteController.php Adds sites.isolated-users endpoint.
app/Actions/SSL/GetMatchingSslCertificates.php Loosens PHPDoc array shape from non-falsy-string to string.
app/Actions/Site/UpdatePHPVersion.php Centralizes PHP version switching with locking and shared-pool checks.
app/Actions/Site/GetIsolatedUsers.php New action returning isolated users with per-server site counts.
app/Actions/Site/DeleteSite.php Refactored to lock and skip teardown of user/pool still used by siblings.
app/Actions/Site/CreateSite.php Replaces unique-user rule with reserved-name + SSH-user blocklist.

Comment thread tests/Feature/SitesTest.php Outdated
Comment thread app/SiteTypes/AbstractSiteType.php
Comment thread resources/js/pages/sites/components/isolated-user-select.tsx Outdated
Comment thread resources/views/ssh/os/create-isolated-user.blade.php Outdated
Comment thread app/Actions/Site/DeleteSite.php Outdated
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.

2 participants