capsite/toybox: a switchboard, the vats' only way out
A vat granted a host (PUT /<vat>?egress=<host> on the admin socket) gets Egress as its globalOutbound, with the host in ctx.props where the vat can't change it. Egress forwards matching requests, WebSocket upgrades included, to the switchboard and refuses the rest with a 403; with no grant, fetch still throws. The switchboard is a separate workerd: a Switchboard DO that calls fetch and returns the response, so a 101's webSocket passes through. toybox reaches it over a unix socket in HTTP proxy style, which keeps the full URL, scheme included. Its network service is the outer fence, with TLS trusting the browser CAs; systemd units for it join toybox's, and only the toybox group can open its socket. The loaded Worker is now named by vat and incarnation, not by code hash: the same code with a different grant must not share a Worker. The new incarnation table sits beside the old ones; vats installed before it read as incarnation 0 with no grant. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
88739d9495
commit
7bf6eb44c7
13 files changed
+279
-51
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { DurableObject } from "cloudflare:workers";
|
||||
|
||||
/** `?url=<target>` fetches it; with `&ws=1`, opens a WebSocket there and reports the echo of "hello". */
|
||||
export class App extends DurableObject {
|
||||
async fetch(request) {
|
||||
const params = new URL(request.url).searchParams;
|
||||
const target = params.get("url");
|
||||
try {
|
||||
if (!params.has("ws")) return new Response(`got: ${await (await fetch(target)).text()}\n`);
|
||||
const resp = await fetch(target, { headers: { Upgrade: "websocket" } });
|
||||
const ws = resp.webSocket;
|
||||
if (!ws) return new Response(`no websocket: ${resp.status} ${await resp.text()}`);
|
||||
ws.accept();
|
||||
const reply = new Promise((resolve) => ws.addEventListener("message", (e) => resolve(e.data)));
|
||||
ws.send("hello");
|
||||
const got = await reply;
|
||||
ws.close();
|
||||
return new Response(`echo: ${got}\n`);
|
||||
} catch (e) {
|
||||
return new Response(`refused: ${e.message}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user