Give the Windows bundle a single-user mode without sign-in

LUMINARY_LOCAL=1 creates one local admin and treats an unauthenticated
request as that account, so the packaged desktop app opens signed in. It
is off unless the launcher sets it, leaving the shared server and Docker
deploy unchanged.
This commit is contained in:
2026-11-28 18:33:08 +00:00
parent fb43ca8e99
commit b79f6c9a4e
2 changed files with 79 additions and 4 deletions
+69 -4
View File
@@ -8,6 +8,8 @@ import {
DIST_DIR,
HOST,
INVITE,
LOCAL_EMAIL,
LOCAL_MODE,
MAX_UPLOAD,
PORT,
RAW_PREVIEW_EDGE,
@@ -337,6 +339,32 @@ function sessionCookie(req, token, maxAge) {
return `${COOKIE}=${token}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${maxAge}${secure}`;
}
/**
* LUMINARY_LOCAL=1 (the Windows desktop bundle): one admin account, no signup,
* no sign-in, and an unauthenticated request is the local owner. The password
* is random and never shown, so the account cannot be signed into over a
* network; the launcher also binds loopback only.
*/
let localOwner = null;
async function prepareLocalOwner() {
if (!LOCAL_MODE) return;
const existing = users.byEmail(LOCAL_EMAIL);
if (existing) {
localOwner = publicUser(existing);
return;
}
const id = crypto.randomUUID();
users.create({
id,
email: LOCAL_EMAIL,
name: 'Local',
passHash: await hashPassword(crypto.randomBytes(32).toString('hex')),
role: 'admin',
});
localOwner = publicUser(users.byId(id));
}
function currentUser(req) {
const cookieToken = parseCookies(req)[COOKIE];
if (cookieToken) {
@@ -346,7 +374,10 @@ function currentUser(req) {
if (user && !user.disabled) return publicUser(user);
}
}
return authenticate(req);
const authenticated = authenticate(req);
if (authenticated) return authenticated;
// A personal, loopback-only install has one owner: no credentials needed.
return LOCAL_MODE ? localOwner : null;
}
function requireAdmin(req, res) {
@@ -599,8 +630,10 @@ route('GET', '/api/health', async ({ req, res }) => {
ok: true,
app: 'luminary',
version: VERSION,
needsSetup: users.count() === 0,
registrationOpen: users.count() === 0 || Boolean(INVITE) || invites.pendingCount() > 0,
needsSetup: !LOCAL_MODE && users.count() === 0,
registrationOpen:
!LOCAL_MODE && (users.count() === 0 || Boolean(INVITE) || invites.pendingCount() > 0),
local: LOCAL_MODE,
photos: stats.photos,
bytes: stats.bytes,
// The absolute data path is only for signed-in team members.
@@ -610,6 +643,9 @@ route('GET', '/api/health', async ({ req, res }) => {
});
route('POST', '/api/auth/register', async ({ req, res }) => {
if (LOCAL_MODE) {
return error(res, 403, 'This is a single-user desktop install; accounts are not used');
}
const body = await readJson(req, 64 * 1024);
const email = normalizeEmail(body.email);
const password = typeof body.password === 'string' ? body.password : '';
@@ -665,6 +701,18 @@ route('POST', '/api/auth/register', async ({ req, res }) => {
});
route('POST', '/api/auth/login', async ({ req, res }) => {
// Desktop mode has no password; hand out the local session so a stale login
// form or bookmark cannot strand the user on a sign-in screen.
if (LOCAL_MODE && localOwner) {
const token = createSession(localOwner.id);
return json(
res,
200,
{ token, user: localOwner },
{ 'Set-Cookie': sessionCookie(req, token, 30 * 24 * 3600) },
);
}
const ipKey = `login:ip:${clientIp(req)}`;
if (authFailures(ipKey) >= LOGIN_IP_LIMIT) {
return error(res, 429, 'Too many sign-in attempts. Try again later.', { 'Retry-After': '900' });
@@ -800,6 +848,9 @@ route('PATCH', '/api/admin/users/:id', async ({ req, res, params }) => {
if (!admin) return;
const target = users.byId(params.id);
if (!target) return error(res, 404, 'No such account');
if (LOCAL_MODE && localOwner && target.id === localOwner.id) {
return error(res, 403, 'The local account is managed by the desktop launcher');
}
const body = await readJson(req, 64 * 1024);
const patch = {};
@@ -872,6 +923,9 @@ route('DELETE', '/api/admin/users/:id', async ({ req, res, params }) => {
if (params.id === admin.id) return error(res, 400, 'You cannot delete your own account');
const target = users.byId(params.id);
if (!target) return error(res, 404, 'No such account');
if (LOCAL_MODE && localOwner && target.id === localOwner.id) {
return error(res, 403, 'The local account is managed by the desktop launcher');
}
if (target.role === 'admin' && users.activeAdmins() <= 1) {
return error(res, 400, 'Keep at least one active administrator');
}
@@ -2567,6 +2621,13 @@ async function sweepOrphanOriginals() {
}
}
await prepareLocalOwner();
if (LOCAL_MODE && !['127.0.0.1', 'localhost', '::1'].includes(HOST)) {
console.warn(
` local: LUMINARY_LOCAL=1 with HOST=${HOST}; every client is treated as the local admin`,
);
}
server.listen(PORT, HOST, async () => {
startQuotaWorker();
const raw = await rawSupport();
@@ -2575,7 +2636,11 @@ server.listen(PORT, HOST, async () => {
console.log(
` raw: libraw ${raw.libraw ? `ready (${raw.workers} parallel worker${raw.workers === 1 ? '' : 's'})` : 'missing'} · jpeg ${raw.sharp ? 'sharp' : 'png fallback'}`,
);
console.log(` users: ${users.count()} account(s)${users.count() === 0 ? ' — first signup becomes admin' : ''}`);
if (LOCAL_MODE) {
console.log(` local: ${LOCAL_EMAIL} — sign-in disabled (LUMINARY_LOCAL=1)`);
} else {
console.log(` users: ${users.count()} account(s)${users.count() === 0 ? ' — first signup becomes admin' : ''}`);
}
if (!raw.libraw) console.log(' note: install libraw-wasm for full raw demosaic (embedded previews still work)');
resumePreviewRebuild();
});