Skip to content

Commit bb1ce58

Browse files
authored
refactor(gateway): remove obsolete reverse worker tunnel (#125465)
* refactor(gateway): remove reverse worker tunnel * test(gateway): align worker transport expectations * docs(gateway): clarify cloud worker ingress
1 parent 05b9b39 commit bb1ce58

37 files changed

Lines changed: 205 additions & 1549 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,8 +3083,7 @@ src/gateway/server-reload-utils.ts 1
30833083
src/gateway/server-resident-registry.ts 1
30843084
src/gateway/server-restart-sentinel-agent-delivery.ts 3
30853085
src/gateway/server-runtime-handles.ts 11
3086-
src/gateway/server-runtime-state-prepare.ts 3
3087-
src/gateway/server-runtime-state.ts 1
3086+
src/gateway/server-runtime-state-prepare.ts 2
30883087
src/gateway/server-session-events.ts 4
30893088
src/gateway/server-startup-bootstrap.ts 1
30903089
src/gateway/server-startup-config-helpers.ts 1

‎docs/gateway/cloud-workers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ The bundled Crabbox provider does not support Cloud Worker Desktop after node tr
239239

240240
## Security model
241241

242-
- **Closed worker ingress.** In worker-turn mode, workers speak a dedicated protocol over their authenticated node connection with a closed method allowlist — a worker cannot call operator RPCs.
242+
- **Closed worker ingress.** In worker-turn mode, the enrolled node launches the worker child, which dials the Gateway's authenticated public worker route and speaks a dedicated protocol with a closed method allowlist — a worker cannot call operator RPCs.
243243
- **Gateway-owned tool authority.** In worker-turn mode, the Gateway projects current profile, provider, agent, group, sender, sandbox, delegation, inherited, and runtime-cap policy over the worker's fixed coding-tool catalog before every turn. The launch envelope carries only that final closed-vocabulary subset. Explicitly capped scheduled turns reuse their trusted owner-group context without sending that identity to the box or reapplying a fresh sender overlay. Tools outside the worker catalog remain unavailable; an empty result runs with no tools.
244244
- **Minted credentials, hashed at rest.** Each dispatch mints a worker credential; the Gateway stores only its hash. Credential rotation and owner-epoch fencing guarantee at most one live owner per session — a stale worker that reconnects is fenced, never merged.
245245
- **Environment-bound enrollment.** One short-lived node-only setup credential is bound to the durable environment before allocation. Its first authenticated Ed25519 device identity is recorded atomically with setup completion; replay cannot substitute an unrelated node.

‎docs/plan/cloud-workers.md‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
---
2-
summary: Run agent sessions on ephemeral SSH-reachable machines with gateway-proxied inference and live sidebar streaming.
3-
title: Cloud workers plan
2+
summary: Historical design record for cloud workers before convergence onto node-backed worker turns.
3+
title: Cloud workers historical plan
44
read_when:
5-
- Designing or implementing cloud worker provisioning, worker mode, or session handoff
6-
- Changing environments.*, the worker protocol, transcript ingestion, or inference proxy RPCs
7-
- Reviewing security posture of remote agent execution
5+
- Reviewing the design history behind cloud worker provisioning and session placement
6+
- Comparing the superseded SSH reverse-tunnel proposal with the current node-backed architecture
87
---
98

109
## Status
1110

12-
Proposal, revision 3. Not implemented. Direction agreed 2026-07; revision 2 incorporated adversarial review findings (dedicated worker protocol, placement/environment state machines, git-aware inbound sync, one-way v1 handoff, controlled-egress security wording). Revision 3 settles the sync ownership model (worker authors commits, gateway adopts and publishes), adds a no-git plain sync mode, fixes worker exec at full-within-box, moves internet policy to provision time, and restores agent dispatch to milestone 3.
11+
Superseded historical proposal. The implemented architecture is documented in [Runners and execution environments](/plan/runners) and [Cloud workers](/gateway/cloud-workers): Crabbox provisions a node-backed `worker-turn` lease, the worker child dials the Gateway's authenticated public worker route, and workspace transfer uses the node channel. The former dedicated loopback listener, SSH reverse-forward carrier, and SSH-launched worker-turn path have been removed. SSH remains a separate `remote-exec` workspace transport and desktop carrier.
12+
13+
The sections below preserve the pre-convergence design record and are not the current runtime contract.
1314

1415
## Problem
1516

@@ -94,9 +95,11 @@ No bespoke worker artifact, and no dependence on npm availability:
9495

9596
Worker mode (`openclaw worker`) is an entry point, not a fork: connection handling plus the embedded agent runner, with session persistence and model calls backed by gateway RPCs. It must not start gateway surfaces: no channels, no plugin auto-start beyond the session toolset, throwaway state dir, no local auth profiles.
9697

97-
### 3. Transport: everything over SSH
98+
### 3. Historical transport proposal: everything over SSH
99+
100+
This section describes the superseded carrier. Current `worker-turn` environments use authenticated node connectivity; only `remote-exec` workspace operations retain pinned SSH.
98101

99-
The gateway owns connectivity; the worker requires nothing but sshd:
102+
The original proposal had the gateway own connectivity while the worker required nothing but sshd:
100103

101104
- Gateway opens SSH to the worker (credentials from the provider lease, host key pinned from provisioning output — no `StrictHostKeyChecking=no`) and establishes a reverse tunnel forwarding a worker-local socket to the gateway's WS endpoint.
102105
- Control/model traffic and workspace transfer use separate SSH connections with the same pinned trust material so rsync cannot head-of-line-block token streams.

‎docs/plan/runners.md‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,7 @@ channel.
132132

133133
### Worker ingress on the public endpoint (milestone 5)
134134

135-
Today the worker ingress is a dedicated loopback-only listener reached via
136-
`ssh -R`; the main ingress rejects worker frames. For node runners the same
137-
admission is exposed on a path-tagged upgrade route on the public TLS
138-
endpoint (`connectionKind = "worker"` forced by route instead of listener).
139-
The loopback listener stays for SSH-provisioned cloud workers until
140-
milestone 10.
135+
Worker admission is exposed only on a path-tagged upgrade route on the public TLS endpoint (`connectionKind = "worker"` is forced by the route). Node-hosted worker children dial that endpoint directly. The former loopback listener and SSH reverse-forward carrier were removed after Crabbox converged onto node-backed worker turns; SSH remains only for `remote-exec` workspace transport and separately owned desktop tunnels.
141136

142137
Hardening that ships with the exposure, not after it:
143138

‎src/gateway/server-http-upgrades.ts‎

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ import type { PreauthConnectionBudget } from "./server/preauth-connection-budget
4141
import { markPublicWorkerIngress } from "./server/public-worker-ingress-context.js";
4242
import {
4343
GATEWAY_WS_CONNECTION_KIND_PROPERTY,
44-
GATEWAY_WS_PREAUTH_BUDGET_PROPERTY,
45-
GATEWAY_WS_WORKER_INGRESS_PROPERTY,
4644
type GatewayIngressWebSocket,
4745
type GatewayWsClient,
4846
} from "./server/ws-types.js";
@@ -269,7 +267,6 @@ export function attachGatewayUpgradeHandler(opts: {
269267
ingressName: "Worker",
270268
prepareSocket: (workerSocket) => {
271269
workerSocket[GATEWAY_WS_CONNECTION_KIND_PROPERTY] = "worker";
272-
workerSocket[GATEWAY_WS_WORKER_INGRESS_PROPERTY] = "public";
273270
markPublicWorkerIngress(workerSocket, {
274271
clientIp: requestClientIp,
275272
rateLimiter: publicRateLimiter,
@@ -442,35 +439,3 @@ export function attachGatewayUpgradeHandler(opts: {
442439
});
443440
});
444441
}
445-
446-
/** Attach the loopback-only worker ingress and force every accepted socket into worker mode. */
447-
export function attachWorkerGatewayUpgradeHandler(params: {
448-
httpServer: HttpServer;
449-
wss: WebSocketServer;
450-
preauthConnectionBudget: PreauthConnectionBudget;
451-
log?: { warn: (message: string) => void };
452-
}): void {
453-
params.httpServer.on("upgrade", (req, socket, head) => {
454-
try {
455-
handleBudgetedGatewayWebSocketUpgrade({
456-
req,
457-
socket,
458-
head,
459-
wss: params.wss,
460-
preauthConnectionBudget: params.preauthConnectionBudget,
461-
preauthBudgetKey: req.socket.remoteAddress,
462-
ingressName: "Worker",
463-
prepareSocket: (workerSocket) => {
464-
workerSocket[GATEWAY_WS_CONNECTION_KIND_PROPERTY] = "worker";
465-
workerSocket[GATEWAY_WS_PREAUTH_BUDGET_PROPERTY] = params.preauthConnectionBudget;
466-
workerSocket[GATEWAY_WS_WORKER_INGRESS_PROPERTY] = "loopback";
467-
},
468-
});
469-
} catch (error) {
470-
params.log?.warn(
471-
`worker websocket upgrade failed: ${error instanceof Error ? error.message : String(error)}`,
472-
);
473-
socket.destroy();
474-
}
475-
});
476-
}

‎src/gateway/server-http.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,4 @@ export function createGatewayHttpServer(opts: {
645645
return httpServer;
646646
}
647647

648-
export {
649-
attachGatewayUpgradeHandler,
650-
attachWorkerGatewayUpgradeHandler,
651-
} from "./server-http-upgrades.js";
648+
export { attachGatewayUpgradeHandler } from "./server-http-upgrades.js";

‎src/gateway/server-lifecycle.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export async function prepareGatewayLifecycle(params: {
5151
const { runtime, port, log, logCron, diagnosticsEnabled, shutdownRuntime } = params;
5252
const {
5353
minimalTestGateway,
54-
workerGatewayEndpoint,
5554
transportBridge,
5655
sessionMessageSubscribers,
5756
isConnectionActive,
@@ -88,7 +87,6 @@ export async function prepareGatewayLifecycle(params: {
8887
bindDeviceNodeControl,
8988
workerPlacementRuntime,
9089
} = runtime;
91-
workerGatewayEndpoint.resolve = transportBridge.getWorkerIngressEndpoint;
9290
const subscribeSessionMessageEvents: GatewayRequestContext["subscribeSessionMessageEvents"] = (
9391
connId,
9492
sessionKey,

‎src/gateway/server-runtime-state-prepare.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ export async function prepareGatewayKernelState(params: {
122122
!(nodeCommandConfig?.deny ?? []).some(
123123
(command) => command.trim() === NODE_DESKTOP_STREAM_COMMAND,
124124
);
125-
const workerGatewayEndpoint = {
126-
resolve: (() => undefined) as () => { host: "127.0.0.1" | "::1"; port: number } | undefined,
127-
};
128125
const desktopSessionRegistry =
129126
shouldStartWorkerEnvironmentService || hostDesktopEnabled || nodeDesktopObserveAvailable
130127
? createDesktopSessionRegistry()
@@ -155,7 +152,6 @@ export async function prepareGatewayKernelState(params: {
155152
const workerModule = await loadWorkerEnvironmentStartupModule();
156153
return await workerModule.createGatewayWorkerEnvironmentRuntime({
157154
getPluginRegistry: () => pluginRuntime.registry,
158-
resolveWorkerGateway: () => workerGatewayEndpoint.resolve(),
159155
desktopSessionRegistry,
160156
startup: workerEnvironmentStartup,
161157
log,
@@ -573,11 +569,9 @@ export async function prepareGatewayKernelState(params: {
573569
sessionEventSubscribers,
574570
sessionMessageSubscribers,
575571
isConnectionActive,
576-
getWorkerIngressEndpoint: transportBridge.getWorkerIngressEndpoint,
577572
getTailscaleIngressEndpoint: transportBridge.getTailscaleIngressEndpoint,
578573
getMcpAppSandboxPort: transportBridge.getMcpAppSandboxPort,
579574
ensureSandboxHostPort: transportBridge.ensureSandboxHostPort,
580575
getPortalService: transportBridge.getPortalService,
581-
workerGatewayEndpoint,
582576
};
583577
}

‎src/gateway/server-runtime-state.ts‎

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// Gateway HTTP/WebSocket runtime state factory.
22
// Builds one server runtime with lazy plugin route handlers.
3-
import {
4-
createServer as createHttpServer,
5-
type IncomingMessage,
6-
type Server as HttpServer,
7-
type ServerResponse,
8-
} from "node:http";
9-
import type { AddressInfo } from "node:net";
3+
import type { IncomingMessage, Server as HttpServer, ServerResponse } from "node:http";
104
import type { Duplex } from "node:stream";
115
import { WebSocketServer } from "ws";
126
import { resolveSandboxHostPort } from "../agents/sandbox-host.js";
@@ -33,11 +27,7 @@ import { createSandboxHostHttpServer } from "./mcp-app-sandbox-http.js";
3327
import { isLoopbackHost, resolveGatewayListenHosts } from "./net.js";
3428
import { createGatewayPortalService, type GatewayPortalService } from "./portals/portal-service.js";
3529
import { MAX_PREAUTH_PAYLOAD_BYTES } from "./server-constants.js";
36-
import {
37-
attachGatewayUpgradeHandler,
38-
attachWorkerGatewayUpgradeHandler,
39-
createGatewayHttpServer,
40-
} from "./server-http.js";
30+
import { attachGatewayUpgradeHandler, createGatewayHttpServer } from "./server-http.js";
4131
import type { GatewayRequestContext } from "./server-methods/types.js";
4232
import type { HookClientIpConfig, HooksRequestHandler } from "./server/hooks-request-handler.js";
4333
import { listenGatewayHttpServer } from "./server/http-listen.js";
@@ -149,7 +139,6 @@ export async function createGatewayHttpTransport(params: {
149139
wss: WebSocketServer;
150140
preauthConnectionBudget: PreauthConnectionBudget;
151141
portalService: GatewayPortalService;
152-
getWorkerIngressEndpoint: () => { host: "127.0.0.1"; port: number } | undefined;
153142
getTailscaleIngressEndpoint: () => GatewayTailscaleIngressEndpoint | undefined;
154143
getMcpAppSandboxPort: () => number | undefined;
155144
ensureSandboxHostPort: () => Promise<number>;
@@ -285,7 +274,6 @@ export async function createGatewayHttpTransport(params: {
285274
maxPayload: MAX_PREAUTH_PAYLOAD_BYTES,
286275
});
287276
const preauthConnectionBudget = createPreauthConnectionBudget();
288-
const workerPreauthConnectionBudget = createPreauthConnectionBudget();
289277

290278
const httpServers: HttpServer[] = [];
291279
const gatewayHttpServers: HttpServer[] = [];
@@ -371,21 +359,6 @@ export async function createGatewayHttpTransport(params: {
371359
httpServers.push(tailscaleHttpServer);
372360
}
373361
let tailscaleIngressEndpoint: GatewayTailscaleIngressEndpoint | undefined;
374-
let workerIngressPort: number | undefined;
375-
const workerHttpServer = params.workerIngressEnabled
376-
? createHttpServer((_req, res) => {
377-
res.statusCode = 404;
378-
res.end("Not Found");
379-
})
380-
: undefined;
381-
if (workerHttpServer) {
382-
attachWorkerGatewayUpgradeHandler({
383-
httpServer: workerHttpServer,
384-
wss,
385-
preauthConnectionBudget: workerPreauthConnectionBudget,
386-
log: params.log,
387-
});
388-
}
389362
const httpServer = gatewayHttpServers[0];
390363
if (!httpServer) {
391364
throw new Error("Gateway HTTP server failed to start");
@@ -541,20 +514,6 @@ export async function createGatewayHttpTransport(params: {
541514
if (params.cfg.mcp?.apps?.enabled === true) {
542515
await startSandboxHost();
543516
}
544-
if (workerHttpServer) {
545-
await listenGatewayHttpServer({
546-
httpServer: workerHttpServer,
547-
bindHost: "127.0.0.1",
548-
port: 0,
549-
retryEaddrinuse: false,
550-
});
551-
const address = workerHttpServer.address() as AddressInfo | null;
552-
if (!address || typeof address === "string") {
553-
throw new Error("Worker gateway ingress failed to resolve its loopback port");
554-
}
555-
workerIngressPort = address.port;
556-
httpServers.push(workerHttpServer);
557-
}
558517
startListeningComplete = true;
559518
})();
560519
await startListeningPromise;
@@ -567,10 +526,6 @@ export async function createGatewayHttpTransport(params: {
567526
wss,
568527
preauthConnectionBudget,
569528
portalService,
570-
getWorkerIngressEndpoint: () =>
571-
workerIngressPort === undefined
572-
? undefined
573-
: { host: "127.0.0.1" as const, port: workerIngressPort },
574529
getTailscaleIngressEndpoint: () => tailscaleIngressEndpoint,
575530
getMcpAppSandboxPort: () => mcpAppSandboxPort,
576531
ensureSandboxHostPort,

‎src/gateway/server-transport-bridge.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export function createGatewayTransportBridge() {
1212
},
1313
current: () => current,
1414
getPortalService: () => current?.portalService,
15-
getWorkerIngressEndpoint: () => current?.getWorkerIngressEndpoint(),
1615
getTailscaleIngressEndpoint: () => current?.getTailscaleIngressEndpoint(),
1716
getMcpAppSandboxPort: () => current?.getMcpAppSandboxPort(),
1817
ensureSandboxHostPort: async () => {

0 commit comments

Comments
 (0)