Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

relay: Dockerfile, Caddy and compose for a node, CI job scoped to relay/

milind-sonib881e5633434
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e52e3d3333..4ebeb5a2fa 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -452,6 +452,37 @@ jobs:
- run: pnpm control-plane:test
- run: pnpm control-plane:dry-run
+ relay:
+ needs: static
+ if: contains(needs.static.outputs.jobs, '"relay"')
+ # relay/ is its own pnpm root with its own lockfile, so this installs only the relay's dependencies. The nightly run
+ # fuzzes the pre-auth path for ten minutes, a pull request for twenty seconds.
+ name: relay typecheck + tests + fuzz + audit
+ runs-on: ubuntu-latest
+ timeout-minutes: 20
+ defaults:
+ run:
+ working-directory: relay
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - uses: pnpm/action-setup@ff378ebe6b225b0680b81c1ad4498ae0d1d3a5e3 # v6.0.10
+ with:
+ package_json_file: relay/package.json
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 24
+ cache: pnpm
+ cache-dependency-path: relay/pnpm-lock.yaml
+ - run: pnpm install --frozen-lockfile
+ - name: Audit the production dependencies
+ run: pnpm audit --prod --audit-level high
+ - run: pnpm check
+ - run: pnpm test
+ env:
+ RELAY_FUZZ_MS: ${{ github.event_name == 'schedule' && '600000' || '20000' }}
+
deploy-composio-broker:
# Only deploys on push to upstream main. PRs run the control-plane tests
# but do not deploy: the wiring is exercised end-to-end only by a merged
diff --git a/relay/.dockerignore b/relay/.dockerignore
new file mode 100644
index 0000000000..7e95812e37
--- /dev/null
+++ b/relay/.dockerignore
@@ -0,0 +1,5 @@
+node_modules
+test
+load
+deploy
+*.md
diff --git a/relay/Dockerfile b/relay/Dockerfile
new file mode 100644
index 0000000000..3783e68161
--- /dev/null
+++ b/relay/Dockerfile
@@ -0,0 +1,18 @@
+# syntax=docker/dockerfile:1
+# Built from relay/ alone: docker build -t omb-relay relay/
+FROM node:24-bookworm-slim@sha256:01d566e8d94d8c619591d78652babfccd3c6992a3dffa9ed5ab39e11cf6c70e9 AS deps
+WORKDIR /app
+RUN npm install --global [email protected]
+COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
+RUN pnpm install --frozen-lockfile --prod --ignore-scripts --config.node-linker=hoisted
+
+# No shell and no package manager at runtime. The files stay root-owned, so the relay cannot change its own code.
+FROM gcr.io/distroless/nodejs24-debian12:nonroot@sha256:14d42e2511532589a7c7e01a753667a74fcc96266e137e8125006b87b0c32d0a
+WORKDIR /app
+COPY --from=deps /app/node_modules ./node_modules
+COPY package.json ./
+COPY src ./src
+USER 65532:65532
+ENV NODE_ENV=production
+EXPOSE 8080
+CMD ["--disable-warning=ExperimentalWarning", "src/main.ts"]
diff --git a/relay/deploy/Caddyfile b/relay/deploy/Caddyfile
new file mode 100644
index 0000000000..27987de2e0
--- /dev/null
+++ b/relay/deploy/Caddyfile
@@ -0,0 +1,20 @@
+# TLS for one relay node. Caddy is the only peer the relay trusts for X-Forwarded-For, and with no trusted_proxies here
+# Caddy replaces whatever X-Forwarded-For a client sends with the client's own address. No `log` directive: access logs
+# stay off.
+{
+ admin off
+ servers {
+ protocols h1
+ timeouts {
+ read_header 10s
+ idle 2m
+ }
+ }
+}
+
+{$RELAY_DOMAIN} {
+ header -Server
+ reverse_proxy 127.0.0.1:8080 {
+ stream_close_delay 5m
+ }
+}
diff --git a/relay/deploy/compose.yaml b/relay/deploy/compose.yaml
new file mode 100644
index 0000000000..c9a1690765
--- /dev/null
+++ b/relay/deploy/compose.yaml
@@ -0,0 +1,56 @@
+# One relay node. Both services use the host's network: the relay listens on 127.0.0.1:8080 only and sees Caddy as
+# 127.0.0.1, and Caddy sees each client's real address on 443.
+name: omb-relay
+
+services:
+ relay:
+ image: ${RELAY_IMAGE:?RELAY_IMAGE must name the relay image}
+ network_mode: host
+ env_file: relay.env
+ environment:
+ RELAY_HOST: 127.0.0.1
+ RELAY_PORT: "8080"
+ user: "65532:65532"
+ read_only: true
+ cap_drop: [ALL]
+ security_opt: ["no-new-privileges:true"]
+ pids_limit: 256
+ mem_limit: 3g
+ ulimits:
+ nofile: { soft: 65536, hard: 65536 }
+ # The relay tells hosts it is restarting and exits within 5 s of SIGTERM.
+ stop_grace_period: 10s
+ restart: unless-stopped
+ logging:
+ driver: journald
+ options: { tag: omb-relay }
+ healthcheck:
+ test: ["CMD", "/nodejs/bin/node", "-e", "fetch('http://127.0.0.1:8080/healthz').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]
+ interval: 15s
+ timeout: 3s
+ retries: 3
+
+ caddy:
+ image: caddy:2.10.2@sha256:c3d7ee5d2b11f9dc54f947f68a734c84e9c9666c92c88a7f30b9cba5da182adb
+ network_mode: host
+ environment:
+ RELAY_DOMAIN: ${RELAY_DOMAIN:?RELAY_DOMAIN must be this node's hostname}
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile:ro
+ - caddy-data:/data
+ - caddy-config:/config
+ read_only: true
+ tmpfs: [/tmp]
+ cap_drop: [ALL]
+ cap_add: [NET_BIND_SERVICE]
+ security_opt: ["no-new-privileges:true"]
+ pids_limit: 256
+ restart: unless-stopped
+ depends_on: [relay]
+ logging:
+ driver: journald
+ options: { tag: omb-relay-caddy }
+
+volumes:
+ caddy-data:
+ caddy-config:
diff --git a/relay/package.json b/relay/package.json
index b1bd6a05f2..6c9bab745c 100644
--- a/relay/package.json
+++ b/relay/package.json
@@ -16,11 +16,10 @@
"typescript": "5.9.3"
},
"scripts": {
- "start": "node src/main.ts",
+ "start": "node --disable-warning=ExperimentalWarning src/main.ts",
"check": "tsc -p tsconfig.json",
- "test": "node --test --test-concurrency=1 test/*.test.ts",
- "fuzz": "node --test test/fuzz.test.ts",
- "load": "node load/load.ts",
+ "test": "node --disable-warning=ExperimentalWarning --test --test-concurrency=1 test/*.test.ts",
+ "load": "node --disable-warning=ExperimentalWarning load/load.ts",
"audit": "pnpm audit --prod --audit-level high"
}
}
diff --git a/relay/src/hosts.ts b/relay/src/hosts.ts
index 81a8729dd3..de81cd9264 100644
--- a/relay/src/hosts.ts
+++ b/relay/src/hosts.ts
@@ -127,7 +127,7 @@ function checkToken(ctx: Context, token: string, expectHid?: string): TokenResul
/** Closes every session of `entry` whose phone the current admission set no longer holds. */
function enforceAdmission(ctx: Context, entry: HostEntry): void {
- for (const session of [...entry.sessions.values()]) {
+ for (const session of entry.sessions.values()) {
if (!ctx.hosts.admitted(entry, session.admHash)) session.end(Close.NotFound);
}
}
diff --git a/relay/src/server.ts b/relay/src/server.ts
index a54494f878..67d0b34866 100644
--- a/relay/src/server.ts
+++ b/relay/src/server.ts
@@ -194,8 +194,8 @@ export async function startRelay(config: RelayConfig, options: RelayOptions = {}
server.close();
server.closeIdleConnections();
const retry = JSON.stringify({ retryInMs: limits.restartPhoneRetryMs });
- for (const entry of [...ctx.hosts.all()]) {
- for (const session of [...entry.sessions.values()]) {
+ for (const entry of ctx.hosts.all()) {
+ for (const session of entry.sessions.values()) {
sessions += 1;
session.end(Close.Unavailable, retry);
}
diff --git a/relay/src/splice.ts b/relay/src/splice.ts
index 2c76ec205c..276df8f9f6 100644
--- a/relay/src/splice.ts
+++ b/relay/src/splice.ts
@@ -197,7 +197,7 @@ export class Session {
private overBudget(): void {
this.ctx.metrics.inc("relay_host_budget_exceeded_total");
this.ctx.log({ ev: "budget", hid8: this.entry.hid8 });
- for (const session of [...this.entry.sessions.values()]) session.end(Close.Limited);
+ for (const session of this.entry.sessions.values()) session.end(Close.Limited);
}
/** One of the two sockets closed: the other gets the same code when it is one the ends use with each other. */
diff --git a/scripts/ci-scope.mjs b/scripts/ci-scope.mjs
index 173228779a..85e8b8436d 100644
--- a/scripts/ci-scope.mjs
+++ b/scripts/ci-scope.mjs
@@ -10,7 +10,7 @@ import { fileURLToPath } from "node:url";
// event runs it), and the subsets in VITEST_SUBSETS.
export const SELECTABLE_JOBS = [
"vitest", "behavior-evals", "packaged-server", "windows-cua", "electron-smokes", "cloudflared-linux-arm64",
- "foss", "control-plane", "ui-smoke", "browser-identity", "package-linux", "browser-driver",
+ "foss", "control-plane", "ui-smoke", "browser-identity", "package-linux", "browser-driver", "relay",
];
// The server imports Electron and renderer modules, and the macOS smokes run
@@ -20,7 +20,7 @@ const SERVER_CHECKS = [
"build", "linux-tests", "host-tests", "behavior-evals", "packaged-server", "foss", "electron-smokes",
"ui-smoke", "browser-identity", "browser-driver", "package-linux",
];
-const EVERY_CHECK = [...SERVER_CHECKS, "windows-cua", "cloudflared-linux-arm64", "control-plane"];
+const EVERY_CHECK = [...SERVER_CHECKS, "windows-cua", "cloudflared-linux-arm64", "control-plane", "relay"];
/** What a pull request's change in each area can affect. */
export const AREA_CHECKS = {
@@ -33,6 +33,10 @@ export const AREA_CHECKS = {
// The Windows CUA job starts these the way the installed app does, then lends the PC's screen through them.
"windows-computer-control": [...SERVER_CHECKS, "windows-cua"],
"control-plane": ["control-plane"],
+ // The relay is its own package with its own lockfile; nothing outside relay/ reaches it except the shared vectors,
+ // which it keeps a pinned copy of.
+ relay: ["relay"],
+ "e2e-vectors": [...SERVER_CHECKS, "relay"],
everything: EVERY_CHECK,
};
@@ -85,10 +89,12 @@ const AREAS = [
[/^scripts\/.+\.test\.[cm]?[jt]sx?$/, "script-tests"],
[/^src\/locales\/(?:(?!en\.json$)[^/]+\.json|[^/]+\.test\.ts)$/, "locales"],
[/^(?:src|public)\/|^[^/]+-preview\.html$/, "web"],
+ [/^companion\/src\/e2e\/vectors\//, "e2e-vectors"],
[/^(?:server|shared|enterprise|companion|evals|skills|deploy|cloudflare\/composio-broker)\/|^(?:Dockerfile|\.dockerignore|compose\.yaml)$/, "server"],
[/^electron\/(?:cua|cua-failure|cua-connection|capabilities|screen-status|shared-cua-connection|shared-computer-access|lent-screen-tools|lent-screen-failures|paced-typing)\.[cm]js$/, "windows-computer-control"],
[/^(?:electron|build)\/|^(?:electron-builder\.yml|index\.html|rail\.html)$/, "desktop"],
[/^cloudflare\/control-plane\//, "control-plane"],
+ [/^relay\//, "relay"],
];
export function areaOf(file) {
diff --git a/scripts/ci-scope.test.ts b/scripts/ci-scope.test.ts
index a05dfaf0db..23207df2a6 100644
--- a/scripts/ci-scope.test.ts
+++ b/scripts/ci-scope.test.ts
@@ -137,6 +137,16 @@ describe("CI path scope", () => {
expect(selectCiScope(["cloudflare/control-plane/src/index.ts"])).toEqual({ areas: ["control-plane"], checks: ["control-plane"] });
});
+ it.each([["relay/src/server.ts"], ["relay/pnpm-lock.yaml"], ["relay/Dockerfile"], ["relay/deploy/Caddyfile"], ["relay/README.md"]])(
+ "runs only the relay job for the relay's %j", (file) => {
+ expect(selectCiScope([file])).toEqual({ areas: ["relay"], checks: ["relay"] });
+ });
+
+ it("runs the server's checks and the relay's for the shared E2E vectors, which the relay keeps a pinned copy of", () => {
+ expect(selectCiScope(["companion/src/e2e/vectors/v1.json"])).toEqual({ areas: ["e2e-vectors"], checks: [...checks("server"), "relay"].sort() });
+ expect(selectCiScope(["companion/src/e2e/noise.ts"])).toEqual({ areas: ["server"], checks: checks("server") });
+ });
+
it("selects every area's checks for a change across areas", () => {
expect(selectCiScope(["src/App.tsx", "src/locales/de.json", "cloudflare/control-plane/src/index.ts"]))
.toEqual({ areas: ["control-plane", "locales", "web"], checks: ["build", "control-plane", "linux-tests", "locale-tests", "ui-smoke"] });