Repository navigation
connect-next 2/5: server tunnel ingress that verifies gate assertions - #6048
Merged
SawyerHood merged 1 commit intoOct 21, 2026
Merged
Conversation
SawyerHood
force-pushed
the
connect-next/2-server-ingress
branch
from
October 21, 2026 16:43
b96b8a8 to
77be18b
Compare
bb.server.internal_DO_NOT_USE_openTunnelIngress opens a per-audience loopback listener that only runs requests carrying a valid gate-signed assertion for this server, method and path. Gate keys come from BB_CONNECT_GATE_KEYS_URL. Adds the internal_DO_NOT_USE_ prefix rule to AGENTS.md and its audit entry.
SawyerHood
force-pushed
the
connect-next/2-server-ingress
branch
from
October 21, 2026 16:54
77be18b to
de40291
Compare
SawyerHood
added a commit
that referenced
this pull request
Oct 21, 2026
## Human comments ## What was wrong bb connect next needs its data plane: a gate on Fly that admits visitors to `https://<label>.next.getbb.app` with every rule the Cloudflare gate applies, terminates the frp tunnels bb machines dial, signs a per-request assertion for the server's ingress (PR 2), and routes a visitor to whichever Fly machine holds the label's tunnel. PR 3 of 5 (stack: account API → server ingress → gate → plugin → machine tunnels). Based on #6048. ## What changed - `apps/connect-next` (Fly app `bb-connect-next`): Node HTTP gate plus `frps` 0.71.0 as a loopback child (bind, vhost and server-plugin hooks `Login`/`NewProxy`/`CloseProxy`/`Ping`). It pipes `wss://tunnel.<domain>/~!frp` to frps, checks frp logins against the account API (a client may only claim its own label and shares), admits visitors with the Cloudflare gate's rules (owner session, desktop session, machine credential, next-resource MCP OAuth, Origin refusal, header/cookie stripping, Set-Cookie filtering, offline page with a 15 s redial grace), signs an Ed25519 `x-bb-gate-assertion` per request and WebSocket, and refreshes sessions like the Cloudflare gate. - Load fixes from the staging load tests: batched account API lookups and presence (coalesced, jittered refreshes, retry with backoff), stale-while-revalidate answer cache with last-good answers through account API outages, 16 resolve batches in flight, 3 s drain on shutdown with `fly-replay: elsewhere=true`, WebSocket close frames for frp sockets on shutdown, hard exit inside Fly's `kill_timeout`, open-file limit raised to 65,536. - Regions (`src/regions.ts`, `src/peer-server.ts`): peers over Fly's private network (`PEER_SECRET`), announcements and lookups, `fly-replay` to the holder with HMAC'd state, private-network forwarding for bodies Fly cannot replay, duplicate-tunnel resolution. - `fly.toml` `[[vm]]` is `performance-2x` / 4 GB: `flyctl deploy` applies it to every machine, and the load test showed shared CPUs cannot carry the gate. `docs/connect-next.md` (Machine size, Machine plan) says all regions use that size and that staging overrides it with `--vm-size shared-cpu-2x --vm-memory 1024` on its deploy command. - `Dockerfile`, workflow `.github/workflows/deploy-connect-next.yml` (manual `Deploy Connect Next`, pinned flyctl SHA-256). - `scripts/e2e-local.sh` (+ `e2e-local.ts`, `e2e-peer-gate.ts`): the whole path on one machine; it needs the plugin (PR 4) and machine tunnels (PR 5) to pass fully. No production deploy happens on merge: the workflow is manual. ## How you verified - `pnpm exec turbo run typecheck test --filter=@bb/connect-next`: 87/87 tests (units, plus real `frps`/`frpc` against a stand-in account API and bb server in `test/gate.e2e.test.ts`, the Fly replay stand-in in `test/fly.ts`). - `oxfmt --check`, `pnpm lint`: clean. - Staging (`bb-connect-next-staging`, `next.vibecodethis.site`): 2,500 real frpc tunnels. Before the load fixes a shared-cpu-2x 1GB machine sustained only ~30–40 req/s (CPU throttled), performance-2x 4GB held 2,500 tunnels at ~280 req/s with ~1.3× CPU headroom, and the account API was flooded by presence writes. After the fixes: visitor errors from the gate went from ~0.4% to 0, Worker load fell ~15×, no frp Login waits ran out on a mass reconnect, and a stop with 2,294 tunnels took 0.7 s. Details in `docs/connect-next.md` (Presence, shutdown and limits; Regions). - Local end to end: results on PR 5 (top of the stack). > AGENT GENERATED
alexandre-vl
added a commit
to alexandre-vl/bb
that referenced
this pull request
Oct 21, 2026
Main moved the SDK to 0.6.67 (get-bb#6048, get-bb#6051), so this branch's own type changes need the next version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Through bb connect next, a request reaches the bb server from a local
frpcthat the Fly gate drives, so it arrives on loopback. The main loopback port trusts local callers, so frpc cannot point at it: anyone who can reach the frp tunnel would be treated as local. The server needs a separate ingress that only accepts requests the gate signed for this server, and turns the gate's claims into the same request context the Cloudflare path produces (end-to-end auth: the gate cannot be bypassed by talking to frp directly, and the peer secret or a stolen tunnel alone reaches nothing).PR 2 of 5 (stack: account API → server ingress → gate → plugin → machine tunnels). Based on #6047.
What changed
apps/server/src/services/connect-next/tunnel-ingress.ts: per-audience loopback listener (ephemeral port, shared per audience, freed with the last handle). Every HTTP request and WebSocket upgrade must carry anx-bb-gate-assertionforserver:<serverId>, the request method and exact path and query; anything else is401and runs nothing. A verified request reaches the same app with loopback host/origin, authenticated only by the claims (getGateAuthKind); public install assertions reach only the install paths, without cookies or credentials. Verified tunnel traffic is never treated as coming from this machine (request-context.ts).gate-keys.ts: fetches and caches the gate key set fromBB_CONNECT_GATE_KEYS_URL(defaulthttps://getbb.app/.well-known/bb-connect-gate-keys.json), refetches once for an unknownkid, keeps the last good set when the URL fails, fails closed without keys.bb.server.internal_DO_NOT_USE_openTunnelIngress({ audience })(+ fake host support andInternalDoNotUsePluginTunnelIngress*types). Handles close when the plugin is disabled or unloaded.PLUGIN_SDK_VERSION0.6.65 → 0.6.66 (packages/domain,packages/plugin-sdk/package.json) for the new SDK member.packages/config:BB_CONNECT_GATE_KEYS_URL;docs/configuration.md.AGENTS.md: theinternal_DO_NOT_USE_prefix rule for first-party-only plumbing;docs/api_to_audit.mdentry naming its only caller (connect-next).plugin-authoring-docs.test.ts: the "every public export is documented in the authoring skill" check skipsInternalDoNotUse*types, which are deliberately not documented as plugin API.How you verified
pnpm exec turbo run typecheck --filter='...[connect-next/1-account-api]': 76/76 tasks pass.pnpm exec turbo run test --filter='[connect-next/1-account-api]':@bb/config101 passed / 1 skipped,@get-bb/plugin-sdk390/390,@bb/integration-tests77/77,@bb/server3,637 passed / 1 skipped (newtest/connect-next/tunnel-ingress.test.ts: verified requests by auth kind, refusals without/with wrong assertions, loopback host/origin for plugin routes, public install assertions, WebSocket upgrades for/wsand plugin sockets, key rotation and fail-closed, listener sharing, closing on plugin disable).frpsand the connect-next plugin'sfrpclives in PR 4, where the plugin exists.oxfmt --check,pnpm lint: clean.