feat(setup): setup mode for first-user registration (VS-26) #38
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/setup-mode-first-user-VS-26"
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?
VS-26: Setup mode for first-user registration
Adds a setup mode gated by
VERVAIN_SETUP_ENABLEthat exposes two unauthenticated endpoints driving the vervain-apps/setuponboarding flow. The first-user-is-admin decision lives server-side, never in the frontend.Endpoints
GET /api/setup: 404 when setup mode is off;{"setup": true, "needs_first_user": <user count == 0>}when on. The object shape leaves room for future setup-only steps as additional fields.POST /api/setup/register: unauthenticated JSON{"username","password"}. Guards in order: 404 when setup mode is off, 400 on empty input, 403 once any user exists. On success creates the first user as a full site admin (siteadmin = 0xFFFFFFFF) with the same doc shapemaybe_bootstrap_adminproduces, then auto-logs them in by minting a session and setting the samemc_sessioncookielogin::post_loginsets. The token is also echoed in the body so the frontend lands authenticated without a second round trip.Behavior
VERVAIN_SETUP_ENABLEis exactlytrue(case-insensitive); absent or any other value leaves it off.tokio::sync::Mutexso two concurrent registrations cannot both pass the zero-user gate and create two site admins. Single-instance SQLite makes this sufficient.maybe_bootstrap_adminis unchanged: it already no-ops when any user exists, so theADMIN_USERNAME/ADMIN_PASSWORDenv path and the setup path cannot conflict; whichever creates the first user wins and the other becomes a no-op.Tests
crates/meshcentral-web/tests/setup.rsstands up the full router over a plain-HTTP listener and covers: disabled-mode 404 (both routes), the zero-user happy path (probe, register, doc shape +siteadmincheck, body token), existing-user 403 even with setup on, and auto-login session validity against/refresh.ashx.Acceptance criteria
VERVAIN_SETUP_ENABLE=trueenables setup mode; absent/other values disable itGET /api/setupreturns 404 when disabled;{"setup": true, "needs_first_user": bool}when enabledPOST /api/setup/registerreturns 404 when setup mode disabledPOST /api/setup/registerreturns 403 when any user already existssiteadmin = 0xFFFFFFFFand the same doc shape asmaybe_bootstrap_adminADMIN_USERNAME/ADMIN_PASSWORDbootstrap still works and still no-ops when a user existsCloses VS-26.
Add a setup mode gated by VERVAIN_SETUP_ENABLE that exposes two unauthenticated endpoints driving the vervain-apps /setup onboarding flow. The first-user-is-admin decision lives server-side, never in the frontend. GET /api/setup returns 404 when setup mode is off and {"setup": true, "needs_first_user": <user count == 0>} when on. POST /api/setup/register creates the first user as a full site admin (siteadmin = 0xFFFFFFFF) with the same doc shape maybe_bootstrap_admin produces, then auto-logs them in by minting a session and setting the same mc_session cookie post_login sets (token also echoed in the body). Registration 404s when setup mode is off and 403s once any user exists, so it can only ever mint the first account. Setup mode is on only when VERVAIN_SETUP_ENABLE is exactly "true" (case-insensitive); absent or any other value leaves it off. The user-count check and insert are serialized behind a per-process mutex so two concurrent registrations cannot both pass the zero-user gate. maybe_bootstrap_admin is unchanged: it already no-ops when any user exists, so the env path and the setup path cannot conflict. Integration tests cover disabled-mode 404, the zero-user happy path, existing-user 403, and auto-login session validity against /refresh.ashx. #VS-26