PEP-95: peppa web logout-all — every web session issued before the cut-off ends

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Асель 2026-11-15 14:00:05 +05:00
parent 51847e1ac1
commit feeeb908e5
7 changed files with 64 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { enterActor, getUser, isUserAllowed, sign, verify, type User } from "@peppa/core";
import { enterActor, getUser, isUserAllowed, sessionsValidAfter, sign, verify, type User } from "@peppa/core";
import { loadEnv } from "@peppa/shared";
import { cookies, headers } from "next/headers";
import { redirect } from "next/navigation";
@ -22,6 +22,9 @@ interface SessionPayload {
export const currentUser = cache(async (): Promise<User | null> => {
const p = verify<SessionPayload>((await cookies()).get(SESSION_COOKIE)?.value);
if (!p || p.exp < Date.now()) return null;
// PEP-95: «выкинуть всех» — a session issued before the cut-off is no longer valid.
const after = await sessionsValidAfter(db);
if (after !== null && p.exp - SESSION_DAYS * 86400_000 < after) return null;
const user = await getUser(db, p.uid);
// Removed from the allowlist → the session stops working right away.
return user && (await isUserAllowed(db, user)) ? user : null;

View File

@ -0,0 +1,9 @@
# Proposal: PEP-95 — выкинуть всех пользователей
## Why
Суперадмину нужно, чтобы все зашли заново. Сессия веба — подписанная cookie на 30 дней, отозвать её было нельзя.
## What Changes
- `logoutAllUsers` / `sessionsValidAfter` (core/access.ts, настройка `auth.sessions_after`).
- `currentUser` отклоняет сессию, выданную раньше отметки (выдана = exp − 30 дней).
- CLI `peppa web logout-all`.

View File

@ -0,0 +1,8 @@
## ADDED Requirements
### Requirement: Выход всех пользователей
Суперадмин SHALL иметь возможность завершить все сессии веба разом.
#### Scenario: Выкинуть всех
- **WHEN** выполнено `peppa web logout-all`
- **THEN** все сессии, выданные раньше, недействительны, а новый вход работает

View File

@ -0,0 +1,2 @@
- [x] 1.1 отметка в settings, проверка в currentUser
- [x] 1.2 CLI `peppa web logout-all`, тест

View File

@ -75,6 +75,7 @@ import { checkPlatformChannel, describeChannel, getPlatformChannel, parseChatId,
import { setSharedPool, sharedPool, createHost, deleteHost, findHost, HOST_STATUS_RU, listHosts, setHostDisabled, updateHost } from "@peppa/core";
import { getProjectRunnerSettings, getSystemRunnerSettings, getTaskRunnerSettings, resolveRunnerSettings, runnerStories, setProjectRunnerSettings, setSystemRunnerSettings, setTaskRunnerSettings, type RunnerSettingsPatch } from "@peppa/core";
import { connectErrorTrackingFromEnv } from "@peppa/runner";
import { logoutAllUsers } from "@peppa/core";
import { installCrashReporting } from "@peppa/core";
import { answerAndDeliver, connectCi, importIssues, deployProd, listReleases, platformReleaseOffers, setPlatformReleaseOffers, recordRelease, type ReleaseStatus, provisionProject, setProjectVisibility, transferProject, PROVIDERS, type Provider, resumeSession, runWatchdog, sendToSession, startSession, stopSession, tick } from "@peppa/runner";
import { spawnSync } from "node:child_process";
@ -149,6 +150,7 @@ const USAGE = `peppa — Peppa software factory CLI
peppa secrets check-gitea (who GITEA_TOKEN is; warns about admin rights)
peppa secrets list <KEY> (PEP-54: names of a project's secrets; values are set in the web)
peppa web login-link <gitea-login> (one-time admin login, 10 minutes)
peppa web logout-all (PEP-95: every web session ends — everyone signs in again)
peppa watchdog [--once] [--interval <sec>] [--stall <min>]
peppa db migrate (apply schema migrations to PEPPA_DB)
peppa db backup [file] (checked VACUUM INTO copy; default: today's daily copy)
@ -634,6 +636,11 @@ async function main(): Promise<void> {
await pushImage(await findHost(db, args[0] ?? ""));
console.log(`образ загружен на ${args[0]}`);
break;
case "web logout-all": {
const at = await logoutAllUsers(db);
console.log(`web sessions issued before ${at.toISOString()} are no longer valid`);
break;
}
case "web login-link": {
const u = await getUserByLogin(db, args[0] ?? "");
if (!u) throw new PeppaError(`User "${args[0]}" has never logged into the web`);

View File

@ -63,3 +63,17 @@ export async function mayUseMachineLogin(db: Db, ownerId: number | null): Promis
const admins = (await getSetting<string[]>(db, "platform.admins")) ?? (await allowedLogins(db));
return admins.includes(login) || (await allowedLogins(db)).includes(login);
}
const SESSIONS_AFTER = "auth.sessions_after";
/** PEP-95: every web session issued before now stops working — everyone signs in again. */
export async function logoutAllUsers(db: Db, now = new Date()): Promise<Date> {
await setSetting(db, SESSIONS_AFTER, now.getTime());
return now;
}
/** Web sessions issued before this moment are invalid (null: no cut-off). */
export async function sessionsValidAfter(db: Db): Promise<number | null> {
const v = await getSetting<number>(db, SESSIONS_AFTER);
return typeof v === "number" ? v : null;
}

View File

@ -0,0 +1,20 @@
// PEP-95: «выкинуть всех» — web sessions issued before the cut-off stop working.
import assert from "node:assert/strict";
import { after, describe, test } from "node:test";
import { core, db, teardown } from "./helpers.ts";
after(teardown);
describe("PEP-95: logout of every user", () => {
test("no cut-off by default; after logout-all, older sessions are invalid and new ones work", async () => {
assert.equal(await core.sessionsValidAfter(db), null);
const at = await core.logoutAllUsers(db, new Date("2026-11-15T10:00:00Z"));
const after = (await core.sessionsValidAfter(db))!;
assert.equal(after, at.getTime());
// The web's rule (apps/web/lib/auth.ts): issuedAt = exp − 30 days must not be before the cut-off.
const DAYS = 30 * 86400_000;
const valid = (issuedAt: number) => !(issuedAt + DAYS - DAYS < after);
assert.equal(valid(at.getTime() - 60_000), false, "a session from before is out");
assert.equal(valid(at.getTime() + 60_000), true, "signing in again works");
});
});