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
Admin tokens: the Read only preset in Settings ticks no account emails, and queue:write names the paused budget
Adarsheedde693ecd4
diff --git a/docs/admin-api.md b/docs/admin-api.mdindex cd435f4a..a257ebfd 100644--- a/docs/admin-api.md+++ b/docs/admin-api.md@@ -47,7 +47,7 @@ Keep the token out of URLs, logs and shared files. Send it only in the `Authoriz| `workers:write` | `PATCH /api/admin/workers/{id}`: pause, resume, drain, hours, lanes, revoke || `workers:tokens` | `POST /api/admin/workers`, and `PATCH /api/admin/workers/{id}` with `rotate`: both answer with a worker token. A worker receives accounts' queued jobs with their input files and sends back the results, so give this scope only to a tool you'd trust with those || `queue:read` | `GET /api/admin/queue`, `GET /api/admin/queue/settings` |-| `queue:write` | `PATCH /api/admin/queue/settings`: the run ceiling, the owner's wait limit, fair share and the pick allowance |+| `queue:write` | `PATCH /api/admin/queue/settings`: the run ceiling, the owner's wait limit, fair share, the pick allowance and the paused budget (`pausedBudgetS`: how long a run that has started may spend back in line) || `audit:read` | `GET /api/admin/audit` |The read-only preset in Settings ticks `runs:read`, `reports:read`, `workers:read`, `queue:read` and `audit:read`:diff --git a/src/app/api/admin/queue/settings/route.ts b/src/app/api/admin/queue/settings/route.tsindex 605f8fbe..c472ab49 100644--- a/src/app/api/admin/queue/settings/route.ts+++ b/src/app/api/admin/queue/settings/route.ts@@ -6,7 +6,7 @@ const NO_STORE = { "Cache-Control": "no-store" };/*** The line's settings (owner only, or an admin token with queue:read): the run ceiling (a default and per lane, in- * seconds), the owner's wait limit, fair share and the pick allowance (src/server/queue-settings.ts).+ * seconds), the owner's wait limit, fair share, the pick allowance and the paused budget (src/server/queue-settings.ts).*/export async function GET(request: Request) {await connection();diff --git a/src/components/admin-tokens.tsx b/src/components/admin-tokens.tsxindex e941f530..2e6a35f7 100644--- a/src/components/admin-tokens.tsx+++ b/src/components/admin-tokens.tsx@@ -19,6 +19,7 @@ import { Checkbox } from "@/components/ui/checkbox";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";+import { READ_ONLY_SCOPES } from "@/lib/admin-scopes";import { copyWithToast } from "@/lib/clipboard";import { timeAgo } from "@/lib/format";import { responseError, toastError } from "@/lib/refusals";@@ -48,7 +49,8 @@ interface AuditRow {status: number;}-const READ_ONLY = ["accounts:read", "runs:read", "reports:read", "workers:read", "queue:read", "audit:read"];+/** The preset that only reads: no emails, no prompts and no results. */+const READ_ONLY: readonly string[] = READ_ONLY_SCOPES;const EXPIRY = [{ value: "never", label: "Never expires" },diff --git a/src/lib/admin-scopes.ts b/src/lib/admin-scopes.tsnew file mode 100644index 00000000..9cfc9380--- /dev/null+++ b/src/lib/admin-scopes.ts@@ -0,0 +1,6 @@+/**+ * The Settings preset for an admin token that only reads (docs/admin-api.md): runs' facts, reports, workers, the queue+ * and the admin log. No emails (accounts:read), no prompts and no results (outputs:view): those need their own scopes.+ * The token form ticks these and the server describes the preset with the same list.+ */+export const READ_ONLY_SCOPES = ["runs:read", "reports:read", "workers:read", "queue:read", "audit:read"] as const;diff --git a/src/server/admin-tokens.ts b/src/server/admin-tokens.tsindex 3c57b08b..4abe74a3 100644--- a/src/server/admin-tokens.ts+++ b/src/server/admin-tokens.ts@@ -1,6 +1,7 @@import "server-only";import crypto from "node:crypto";import { authEnabled, hasAdminBearer, isOwnerRequest, LoginGuard, sessionCookieOf, validSession } from "./auth";+import { READ_ONLY_SCOPES as PRESET_READ_ONLY } from "@/lib/admin-scopes";import { db } from "./db";import { hit } from "./rate";@@ -52,12 +53,12 @@ export const SCOPE_LABELS: Record<Scope, string> = {"workers:write": "Pause, resume, change and revoke workers","workers:tokens": "Add workers and give them new tokens (a worker runs accounts' queued jobs, with their files)","queue:read": "See the queue and its settings",- "queue:write": "Change the queue's settings: the run ceiling, the owner's wait limit, fair share and the pick allowance",+ "queue:write": "Change the queue's settings: the run ceiling, the owner's wait limit, fair share, the pick allowance and the paused budget","audit:read": "See the admin log",};/** The Settings preset that only reads: no emails, no prompts and no results (those need their own scopes). */-export const READ_ONLY_SCOPES: Scope[] = ["runs:read", "reports:read", "workers:read", "queue:read", "audit:read"];+export const READ_ONLY_SCOPES: readonly Scope[] = PRESET_READ_ONLY;export const ADMIN_TOKEN_PREFIX = "fuobe_adm_";const SHAPE = /^fuobe_adm_[A-Za-z0-9_-]{43}$/;diff --git a/tests/admin-tokens.test.ts b/tests/admin-tokens.test.tsindex d7b7c1ef..a23f11b6 100644--- a/tests/admin-tokens.test.ts+++ b/tests/admin-tokens.test.ts@@ -664,4 +664,16 @@ describe("admin tokens: accounts' content needs its own scopes", () => {expect(admin.READ_ONLY_SCOPES).not.toContain("accounts:read");expect(admin.READ_ONLY_SCOPES).not.toContain("outputs:view");});++ it("the token form's Read only button and its first ticks are that same preset: no accounts:read, no outputs:view", async () => {+ const { READ_ONLY_SCOPES } = await import("@/lib/admin-scopes");+ expect(admin.READ_ONLY_SCOPES).toBe(READ_ONLY_SCOPES);+ expect([...READ_ONLY_SCOPES].sort()).toEqual(["audit:read", "queue:read", "reports:read", "runs:read", "workers:read"]);+ for (const s of READ_ONLY_SCOPES) expect(admin.SCOPES).toContain(s);+ // The page builds its preset from the shared list, and names no scope of its own for it.+ const page = fs.readFileSync(path.join(__dirname, "..", "src/components/admin-tokens.tsx"), "utf8");+ expect(page).toMatch(/import \{ READ_ONLY_SCOPES \} from "@\/lib\/admin-scopes"/);+ expect(page).toMatch(/const READ_ONLY: readonly string\[\] = READ_ONLY_SCOPES;/);+ expect(page).not.toMatch(/"accounts:read"/);+ });});