The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Workers: Sign everyone out with every API token revokes every worker's token too
Adarsh957637fceb5c
diff --git a/docs/SELF-HOSTING.md b/docs/SELF-HOSTING.mdindex 207423d9..f16e1155 100644--- a/docs/SELF-HOSTING.md+++ b/docs/SELF-HOSTING.md@@ -70,7 +70,7 @@ claude mcp add --transport http fuobe http://localhost:3000/api/mcp --header "AuShare links are the one exception: `/s/<token>` and its files open for anyone who has the link, after the host and cross-site checks. Without a password, anyone who can open a share link can open the whole studio too.-A sign-in lasts 30 days. If you think someone else has signed in as you, open **Settings → Security** and press **Sign everyone out**. It ends every sign-in on every device, yours included (an open live feed too), and can revoke every API token too. Your password stays the same. A new password also ends every owner sign-in: a Settings password change at once (it signs accounts out too), and a new `FUOBE_PASSWORD` when the server restarts (accounts stay signed in). API tokens are not tied to the password: revoke them in **Settings → Security**, or tick **Also revoke every API token** when you sign everyone out.+A sign-in lasts 30 days. If you think someone else has signed in as you, open **Settings → Security** and press **Sign everyone out**. It ends every sign-in on every device, yours included (an open live feed too), and can revoke every API token too (workers' tokens included). Your password stays the same. A new password also ends every owner sign-in: a Settings password change at once (it signs accounts out too), and a new `FUOBE_PASSWORD` when the server restarts (accounts stay signed in). API tokens are not tied to the password: revoke them in **Settings → Security**, or tick **Also revoke every API token** when you sign everyone out.To manage accounts, runs and workers from your own tools without the owner's sign-in, make an **admin token** in the same place: it works only on `/api/admin`, and only for the rights you tick ([admin-api.md](admin-api.md)).diff --git a/docs/admin-api.md b/docs/admin-api.mdindex 7feb8129..9bbadbbd 100644--- a/docs/admin-api.md+++ b/docs/admin-api.md@@ -123,7 +123,8 @@ Times are epoch milliseconds and sizes are bytes. Every answer is `Cache-ControlA log row is `{ id, at, actor: "owner" | "token" | "system", token: { id, name } | null, action, target, detail, status }`.`token.name` is the name the token had at the time. Actions: `account.disable`, `account.enable`, `account.signout`,`account.delete`, `run.delete`, `outputs.hide`, `outputs.unhide`, `outputs.remove`, `worker.add`, `worker.change`,-`worker.rotate`, `worker.revoke`, `queue.settings` (with the values before and after), `token.create`, `token.revoke`,+`worker.rotate`, `worker.revoke`, `worker.revoke_all` (Sign everyone out with every API token), `queue.settings` (with+the values before and after), `token.create`, `token.revoke`,`token.revoke_all`, `settings.comfy_where` (where ComfyUI runs, with the values before and after); a token's reads`accounts.list`, `accounts.csv`, `account.read`, `runs.list`, `reports.list`, `audit.read` (one row per token and actionevery 10 minutes); reads of accounts' content by a token or the owner: `runs.content` (one row per reader and accountdiff --git a/docs/gpu-workers.md b/docs/gpu-workers.mdindex 1bd76ee5..489ddf80 100644--- a/docs/gpu-workers.md+++ b/docs/gpu-workers.md@@ -493,7 +493,10 @@ The worker keeps its jobs going by itself:Every worker call carries `Authorization: Bearer fuobe_wkr_…`. A worker token works only on `/api/gpu/computer/*` andgets 403 everywhere else. It is never the owner, and an owner API token can never act as a worker. The studio reads the-token on every call, so a revoked token stops at once.+token on every call, so a revoked token stops at once. **Settings → Security → Sign everyone out** with **Also revoke+every API token** revokes every worker's token too. Their jobs go back to the queue with their places kept, and the+admin log gets one `worker.revoke_all` row. Add each worker again to give it a new token. People's own paired+ComfyUIs keep theirs.**A token's lifetime.** With `FUOBE_WORKER_TOKEN_DAYS` set (unset or 0: a token never expires, as before), a poolworker's token lasts that many days. A worker added before the lifetime was set gets it from its first call after. Oncediff --git a/src/app/api/auth/sessions/route.ts b/src/app/api/auth/sessions/route.tsindex ff6864fb..7c6e49ae 100644--- a/src/app/api/auth/sessions/route.ts+++ b/src/app/api/auth/sessions/route.ts@@ -1,12 +1,13 @@import { z } from "zod";import { audit, revokeAllAdminTokens } from "@/server/admin-tokens";import { authEnabled, SESSION_COOKIE, sessionCookieOf, signOutEveryone, validSession } from "@/server/auth";+import { revokeAllWorkers } from "@/server/computer/pool";/*** Settings → Security → Sign everyone out: a new session secret, so every signed-in browser (the owner's, this one* too, and every account's) has to sign in again. It works while FUOBE_PASSWORD is set. Only from the owner's* signed-in browser (an API token can't do it). With { tokens: true }, every API token is revoked too, admin tokens- * included.+ * included, and every worker's token (their jobs go back in line; people's own paired ComfyUIs stay paired).*/export async function POST(request: Request) {if (!authEnabled()) return Response.json({ error: "Set a password first. Without one, nobody signs in." }, { status: 400 });@@ -17,6 +18,8 @@ export async function POST(request: Request) {if (tokensRevoked) {const n = revokeAllAdminTokens();if (n) audit({ kind: "owner" }, "token.revoke_all", null, { count: n }, 200);+ const workers = revokeAllWorkers();+ if (workers) audit({ kind: "owner" }, "worker.revoke_all", null, { count: workers }, 200);}const secure = new URL(request.url).protocol === "https:" ? "; Secure" : "";return Response.json(diff --git a/src/components/admin-tokens.tsx b/src/components/admin-tokens.tsxindex d32e1773..e941f530 100644--- a/src/components/admin-tokens.tsx+++ b/src/components/admin-tokens.tsx@@ -71,6 +71,7 @@ const ACTION_WORDS: Record<string, string> = {"worker.change": "Changed a worker","worker.rotate": "Gave a worker a new token","worker.revoke": "Revoked a worker",+ "worker.revoke_all": "Revoked every worker","worker.alert": "A worker's token was used from somewhere new","queue.settings": "Changed the queue's settings","settings.comfy_where": "Changed where ComfyUI runs",diff --git a/src/components/security-settings.tsx b/src/components/security-settings.tsxindex b3acfd01..00b7a4a3 100644--- a/src/components/security-settings.tsx+++ b/src/components/security-settings.tsx@@ -254,7 +254,7 @@ function SignOutEveryone({ tokens }: { tokens: number }) {<div className="flex items-start gap-2"><Checkbox id={`${id}-tokens`} className="mt-0.5" checked={revoke} onCheckedChange={(v) => setRevoke(!!v)} /><Label htmlFor={`${id}-tokens`} className="text-[13px] leading-snug font-normal">- Also revoke every API token{tokens > 0 ? ` (${tokens})` : ""}. Scripts and agents that use one stop working until you give them a new one.+ Also revoke every API token{tokens > 0 ? ` (${tokens})` : ""}. Scripts, agents and workers that use one stop working until you give them a new one.</Label></div><AlertDialogFooter>diff --git a/src/server/computer/pool.ts b/src/server/computer/pool.tsindex 4fa3a67e..6e048914 100644--- a/src/server/computer/pool.ts+++ b/src/server/computer/pool.ts@@ -861,15 +861,32 @@ export interface WorkerPatch {revoke?: boolean;}+/** A worker's token stops at once, and its tasks go back in line at once (not the worker's fault). */+function revokePoolWorker(id: string, now: number): void {+ revokeWorker(id, now);+ for (const t of db().prepare("SELECT * FROM relay_tasks WHERE worker_id = ? AND state IN ('sending','queued','running','collecting')").all(id) as TaskRow[]) backInLine(t, { blame: false });+}++/**+ * Every worker's token stops at once (Settings → Security → Sign everyone out, with every API token), and their tasks go+ * back in line with their places kept. People's own paired ComfyUIs keep theirs. Returns how many workers it revoked.+ */+export function revokeAllWorkers(now = Date.now()): number {+ const d = db();+ return d.transaction(() => {+ const ids = (d.prepare("SELECT id FROM relay_workers WHERE kind = 'pool' AND revoked_at IS NULL").all() as { id: string }[]).map((r) => r.id);+ for (const id of ids) revokePoolWorker(id, now);+ return ids.length;+ })();+}+/** The owner changes a worker. Each change reaches it at its next beat. */export function patchWorker(id: string, p: WorkerPatch, now = Date.now()): { view: WorkerView | null; token?: string } {const d = db();const w = d.prepare("SELECT * FROM relay_workers WHERE id = ? AND kind = 'pool' AND revoked_at IS NULL").get(id) as WorkerRow | undefined;if (!w) return { view: null };if (p.revoke) {- revokeWorker(id, now);- // Its tasks go back in line at once (not the worker's fault).- for (const t of d.prepare("SELECT * FROM relay_tasks WHERE worker_id = ? AND state IN ('sending','queued','running','collecting')").all(id) as TaskRow[]) backInLine(t, { blame: false });+ revokePoolWorker(id, now);return { view: null };}const set: Record<string, unknown> = {};diff --git a/tests/admin-tokens.test.ts b/tests/admin-tokens.test.tsindex 1a7dcffc..d7b7c1ef 100644--- a/tests/admin-tokens.test.ts+++ b/tests/admin-tokens.test.ts@@ -472,8 +472,60 @@ describe("admin tokens: accounts and files", () => {expect(res.status).toBe(200);expect((await routes.queue.GET(req("/api/admin/queue", { token }))).status).toBe(401);expect(admin.liveAdminTokenCount()).toBe(0);- expect(auditRows().at(-1)).toMatchObject({ actor: "owner", action: "token.revoke_all", status: 200 });- expect(JSON.parse(auditRows().at(-1)!.detail_json!).count).toBeGreaterThanOrEqual(1);+ const row = auditRows().findLast((r) => r.action === "token.revoke_all");+ expect(row).toMatchObject({ actor: "owner", action: "token.revoke_all", status: 200 });+ expect(JSON.parse(row!.detail_json!).count).toBeGreaterThanOrEqual(1);+ ownerCookie = auth.createSession().value;+ });++ it("Sign everyone out with every API token stops every worker's token too, and their jobs go back in line; paired ComfyUIs stay", async () => {+ const pool = await import("@/server/computer/pool");+ const tasks = await import("@/server/computer/tasks");+ const { principalOf } = await import("@/server/computer/http");+ const { setSetting } = await import("@/server/settings");+ setSetting("comfyWhere", "workers");+ const w = pool.addWorker(`panic-${++n}`);+ pool.patchWorker(w.id, { paused: false, hours: { always: true }, allow: { small: { delayMs: 0 } }, claimAfterMs: 0 });+ db().prepare("UPDATE relay_workers SET lanes_json = ?, facts_json = ? WHERE id = ?").run(JSON.stringify({ lanes: ["small"], workflows: ["wf-panic"] }), JSON.stringify({ vramBytes: 2 ** 34 }), w.id);+ const a = auth.createAccount(`panic-${++n}@example.com`, "long enough");+ const paired = workers.createWorker({ name: `paired-${++n}`, kind: "personal", principal: `acct:${a.id}` });+ const gid = `panic-run-${++n}`;+ const now = Date.now();+ db()+ .prepare("INSERT INTO generations (id, feature, model_id, engine, provider, op, kind, status, request_json, outputs_json, created_at, updated_at) VALUES (?, 'image', 'm', 'open', 'comfyui', 't2i', 'image', 'queued', ?, '[]', ?, ?)")+ .run(gid, JSON.stringify({ account: a.id, place: "pool" }), now, now);+ const t = tasks.createTask({+ principal: `acct:${a.id}`,+ generationId: gid,+ graph: { "1": { class_type: "SaveImage", inputs: { filename_prefix: "x" } } },+ pool: { pools: ["pool"], account: a.id, rankAt: now, lane: "small", needs: { workflowId: "wf-panic", files: [], packs: [], minVramBytes: 0 } },+ });+ const worker = () => workers.getWorker(w.id)!;+ pool.workerBeat(worker(), pool.cleanBeat({ device: `wkr-${w.id}`, protocol: 2, version: "1", local: { paused: false, why: null, until: null }, gpu: {}, inventoryHash: null, running: [], stopped: [] }));+ expect(pool.workerClaim(worker(), [])?.id).toBe(t.id);+ const call = (token: string) => principalOf(new Request("http://localhost:3000/api/gpu/computer/beat", { method: "POST", headers: { host: "localhost:3000", authorization: `Bearer ${token}` } }));+ expect(call(w.token)).not.toBeInstanceOf(Response);++ const res = await routes.sessions.POST(req("/api/auth/sessions", { cookie: ownerCookie, method: "POST", body: { tokens: true } }));+ expect(res.status).toBe(200);+ expect((call(w.token) as Response).status).toBe(401);+ // Its job waits in line again with its place, at no cost.+ const back = db().prepare("SELECT state, requeues, worker_id FROM relay_tasks WHERE id = ?").get(t.id) as { state: string; requeues: number; worker_id: string | null };+ expect(back).toEqual({ state: "waiting", requeues: 0, worker_id: null });+ // A person's own paired ComfyUI keeps its token.+ expect(workers.workerFromAuth(`Bearer ${paired.token}`, null)?.id).toBe(paired.id);+ const row = auditRows().findLast((r) => r.action === "worker.revoke_all");+ expect(row).toMatchObject({ actor: "owner", status: 200 });+ expect(JSON.parse(row!.detail_json!).count).toBe(1);+ ownerCookie = auth.createSession().value;+ });++ it("Sign everyone out without the API tokens leaves workers as they are", async () => {+ const pool = await import("@/server/computer/pool");+ const w = pool.addWorker(`calm-${++n}`);+ const res = await routes.sessions.POST(req("/api/auth/sessions", { cookie: ownerCookie, method: "POST", body: {} }));+ expect(res.status).toBe(200);+ expect(workers.getWorker(w.id)?.revoked_at).toBeNull();ownerCookie = auth.createSession().value;});});