Repository navigation
Description
Problem
Tower's tunnel client delivers every tunnel-borne request to exactly one place: Tower's own port. There is no way to expose a second local HTTP+WebSocket service (for example a VS Code server-web build serving a browser IDE) through the same tunnel. The only workaround today is to stop Tower and let another process take over the tunnel, which takes the dashboard offline.
The Codev IDE fork has validated, end to end, that a server-web workbench behind Tower and the cloud proxy boots in the browser with the Codev sidebar in IDE mode. What it needs from Tower is small and generic.
Scope
- Prefix forward. A configured prefix (e.g.
/ide/) on Tower routes tohttp://127.0.0.1:<port>/…— plain HTTP inservers/tower-routes.ts handleRequest()and WebSocket upgrades inservers/tower-websocket.ts(raw pipe; the workbench opens two WS connections under its base path with?reconnectionToken=). Strip the prefix before forwarding, or pass it asx-forwarded-prefix— the VS Code server honoursx-forwarded-prefix/x-forwarded-host/x-forwarded-proto. - Header hygiene on the forward. Strip
x-forwarded-portandx-original-host(a leaked upstream port makes the browser dial the wrong WebSocket port); stampx-forwarded-host/x-forwarded-protofrom the tunnel's public authority when tunnel-borne. - Origin guard.
isWebSocketAllowed(utils/server-utils.ts) must accept the tunnel's public host for the forwarded prefix, as it does for the dashboard. - Lifecycle.
afx ide start | stop | status [--workspace <path>]spawns the local server (--host 127.0.0.1 --port <p> --server-base-path <prefix> --connection-token-file <tower-owned file> --accept-server-license-terms), records the port, and Tower auto-starts it when the prefix is hit if configured. Mirror the pattern ofapps/vscode/src/tower-starter.ts. - Optional but cheap: gzip/brotli on the forward for text responses. The workbench boot is ~21 MB uncompressed and the VS Code server sends no compression; compressing here avoids relying on the relay's edge.
- Config surface. Where the prefix → port mapping lives (
~/.agent-farm/config or per-workspace), and/api/tunnel/*stays local-only as today.
Non-goals
- Serving the IDE's static assets from anywhere other than the local server (a static/dynamic split is a relay-side decision).
- Unifying Tower's PTY bridge with the workbench's own terminals.
Acceptance
- With a local VS Code server-web build on port N and the prefix configured,
https://<relay>/t/<tower>/ide/boots the workbench through the tunnel while the dashboard at/t/<tower>/keeps working; both remote WebSockets connect withremoteAuthority= the relay's host; nows://localhostattempts. afx ide statusreports port + PID;afx ide stoptears it down; Tower restart does not orphan it.
Auth model (added after architect review — this supersedes the "Origin guard" bullet's silence on auth)
The forwarded prefix is key-authenticated, not a public carve-out. It sits behind Tower's request-auth choke point like every other non-public route (advisory GHSA-xvjp-7748-v88v: shared local key + Host allowlist). Tunnel-borne requests already arrive stamped with the local key and a rewritten Host by TunnelClient (#1588), so the IDE prefix needs no exception: the check runs first, the forward runs second. Do not add the prefix to the public-route list; the only sanctioned carve-out precedent is the nonce-authenticated OAuth callback (#1571), and the IDE path has no equivalent one-shot secret.
Consequences for the design:
- The forward is a post-auth handler. Loopback callers on the laptop must present the local key too, exactly as they do for
/api/*; the IDE server's own connection token (Tower-owned token file) is a second, inner layer and not a substitute. - Build the auth decision behind a swappable seam. tower: per-session remote credential for cloud-proxied Tower access #1589 (per-session remote credential) is expected to replace the local-key stamp for remote browsers. The forward should call one "is this request authorised for prefix P?" function whose implementation can move from local-key to per-session credential without touching the proxying code. Header stripping/stamping happens after that seam, never before.
- The origin guard (
isWebSocketAllowed) remains in addition to, not instead of, the key check.
Activity
amrmelsayed commentedon Sep 9, 2026
Routing note from the tower contract seat (resent here after an
afx sendtruncation — fittingly, the #1567-class defect; the running local Tower predates PR #1644):The forward must compose with Tower's request-auth choke point, not bypass it. Since the 3.3.1 hardening (GHSA advisory), every non-public route requires the shared local key plus the Host check — one HTTP choke point all routes pass through — and #1588 stamps those onto tunnel-borne requests. An
/ide/prefix that skips the key check would reopen the exact hole 3.3.1 closed, through the same tunnel. So the origin-guard section here should state explicitly which of the two sanctioned shapes the IDE path takes:Additionally: build the forward's auth behind a swappable seam. #1589 (per-session remote credential for cloud-proxied access) is open and is expected to replace the shared-local-key stamp for remote browsers; a forward hard-wired to today's key shape would need rework the moment that lands.
amrmelsayed commentedon Sep 11, 2026
Scope addition from the fork side, agreed in principle by the fork's owner: besides routing, Tower should install the IDE server on demand — download the release artifact matching the host platform/arch and the installed Codev version into Tower's own directory, verify its checksum, and keep it (the Remote-SSH pattern: the client never builds anything on the host). The fork is adding a CI pipeline that publishes those artifacts as GitHub Release assets (
codev-ide-server-<platform>-<arch>-<version>-<sha>.tar.gz+.sha256). Suggestafx ide install [--version]alongsidestart|stop|status, with the artifact base URL configurable. Routing (this issue as filed) stays the un-substitutable half; install-on-demand can be its own sub-lane.amrmelsayed commentedon Sep 11, 2026
Contract-seat notes on the install-on-demand scope addition (endorsed overall; routing-first sequencing agreed — the forward remains the un-substitutable half and should land first):
.sha256ships from the same origin as the tarball, so verification protects transfer integrity, not source compromise. That's acceptable for a GitHub-Releases origin — but the issue should say so explicitly rather than let "verified" imply more. If stronger provenance is ever wanted, that's a separate decision (signing), not a bigger hash.afx ide status;codev doctorsurfaces it. A silent config edit should never silently change where executable code comes from.afx ide statuslists installed versions, and either anafx ide install --pruneor a doctor note covers stale ones. Not a blocker — just don't let ~/.agent-farm become an unbounded binary graveyard silently.FYI received re codev-cloud's prefix CSP + forwarded headers being live in production — noted that once the forward lands, the manual launcher path retires entirely.
amrmelsayed commentedon Sep 11, 2026
On it! Working on this with the PIR protocol (plan + dev-approval gates before PR).
[PIR #1668] Plan draft
[PIR #1668] Plan revised: fixed /ide/ + ?folder single-server model, …
[PIR #1668] Plan revised: drop config file (global.db registration), …
[PIR #1668] Plan: ~/.agent-farm record for IDE lifecycle, no DB change
[PIR #1668] Plan draft
[PIR #1668] Plan revised: fixed /ide/ + ?folder single-server model, …
[PIR #1668] Plan revised: drop config file (global.db registration), …
[PIR #1668] Plan: ~/.agent-farm record for IDE lifecycle, no DB change
[PIR #1668] IDE server record, lifecycle, forward, and auth seam
[PIR #1668] Wire /ide/ forward into Tower routing, WS upgrade, boot r…
6 remaining items
amrmelsayed commentedon Sep 15, 2026
Dev-run finding (Tower on
builder/pir-1668, real server-web build, cloud tower):/t/<tower>/ide/returns 403 Forbidden.Root cause: Tower spawns the IDE server with
--connection-token-file(ide-record.ts→ensureIdeConnectionToken), butide-forward.tsnever presents that token upstream —buildForwardHeaders,forwardIdeHttpandforwardIdeWebSocketcarry notkn/cookie handling. So Tower's own key check passes and the VS Code server then rejects the request.Local repro against Tower on 4100 (with
codev-tower-key):GET /ide/GET /ide/?tkn=<token>GET /ide/+Cookie: vscode-tkn=<token>With key + cookie supplied by the client, a headless Chromium boot through the forward brings up the full workbench in ~5 s with the explorer populated — so the rest of the forward (headers, WS upgrade, prefix routing) is sound. The defect is only the missing token.
Fix options for the builder:
vscode-tkn=<token>into theCookieheader inbuildForwardHeaders(HTTP and WS upgrade alike). The server embeds the token into the page when the root request carries it, so the management/ext-host WebSocket handshake (msg1.auth) then validates too.--without-connection-tokenand drop the token file, since plan §D2 already makes the Tower key the whole boundary.Either way, do not rely on the browser holding the token: the server's own
Set-CookieusesPath=<server-base-path>(/ide), which never matches/t/<tower>/ide/through the relay. (a) keeps defense in depth; recommended.Merge is on hold until this is fixed and the dev-run repeated.
amrmelsayed commentedon Sep 15, 2026
Fix ruling from the tower contract seat on the dev-run 403 (report above): option (a) — inject
vscode-tkn=<token>into the Cookie header inbuildForwardHeadersfor both HTTP and WS upgrade, merge-not-clobber. Option (b) rejected for a reason the report doesn't state: the connection token is the auth boundary for direct127.0.0.1:8200access —--without-connection-tokenwould leave an unauthenticated any-folder IDE open to any local process, bypassing Tower's key entirely. §D2's key-is-the-boundary applies to the forward path; the token guards the path that skips Tower. Both stay. The report's Path=/ide cookie observation is exactly why forward-layer injection is the correct fix layer (the browser can never hold the cookie through the relay). Regression test required: injected cookie on both paths + merge semantics. Merge holds until codev-ide's cloud re-test passes, per the owner.[PIR #1668] Inject IDE connection-token cookie on the forward (fix cl…
[PIR #1668] Tests: connection-token cookie injection + merge-not-clob…
[PIR #1668] Thread: cloud 403 defect, cookie-injection fix, option-b …
[PIR #1668] Thread: cloud pass evidence + PR verification prep
[PIR #1668] Review + retrospective
[PIR #1668] Address CMAP: lsof off the forward hot path, stop escalat…
[PIR #1668] Tests: tunnel blocklist regex, /ide/ routed-auth, connect…
[PIR #1668] Review: CMAP corrections + honest evidence attribution; r…
[PIR #1668] Thread: CMAP iter 1 verdicts + fixes, pr gate pending
Merge pull request #1683 from cluesmith/builder/pir-1668
docs(release-notes): tower /ide/ forward + afx ide lifecycle (#1668, PR
[Spec 1658][Phase: phase_9] Never-ready IDE server stopped on POSIX t…