Versions 149 to 150
new file, 253 lines
1+// Per-agent keys, ported from the platform's worker/src/keys.ts. They run when AGENT_KEYS is "on" and
2+// KEY_HMAC_SECRET is set. Each key belongs to one agent of one project; the project's Durable Object keeps only the
4+
10+
15+
18+
31+
36+
43+
50+
54+
59+
69+
71+ return typeof presented === "string" && presented.startsWith(KEY_PREFIX) && presented.length > KEY_PREFIX.length;
73+
82+ const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(message)));
85+
93+
99+
109+
114+
120+
148+
156+
171+
175+
177+ * Checks a presented key against one project. The URL's agent must match the key's agent: a mismatch is a 403, and
178+ * the agent is not rewritten. A missing secret is a 503 that names no key. Failures are counted per address and
189+ if (!secret) return { ok: false, status: 503, error: "the key secret (KEY_HMAC_SECRET) is not set", dirty: false };
193+ return { ok: false, status: 429, error: "too many failed keys; try again shortly", dirty: false };
199+ state.fails[addr] = !cur || now - cur.at >= FAIL_WINDOW_MS ? { n: 1, at: now } : { n: cur.n + 1, at: cur.at };
231+
234+
236+ * Whether a key's role allows a request. A reader only reads. A writer also writes, but only on its own agent's
237+ * routes (/a/:agent/..., where checkKey has matched the agent), and blob uploads, which a record needs. Owner-only
242+ request: { write: boolean; agent: string | undefined; route: string | undefined; method?: string },
249+ if (request.method === "PUT" && /^blobs\/[0-9a-f]{64}$/.test(request.route ?? "")) return { ok: true };
251+ return { ok: false, status: 403, error: "a writer's key writes only on its own agent's routes" };
- MCP
- compare on this site's /mcp
- CLI
- abso diff 149 150 server/src/keys.ts --json
- JSON
- /christopher/abso-core/compare/149..150?file=server%2Fsrc%2Fkeys.ts&format=json