Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
a641aae
test: cover hosted user onboarding
lawrencecchen Jul 31, 2026
e702574
feat: onboard hosted Subrouter users with Stack Auth
lawrencecchen Jul 31, 2026
b0c50d0
test: cover onboarding review regressions
lawrencecchen Jul 31, 2026
be727eb
fix: harden hosted onboarding state transitions
lawrencecchen Jul 31, 2026
e9d12a3
test: isolate hosted health fixture
lawrencecchen Jul 31, 2026
6fe3c5b
test: cover unavailable hosted login configuration
lawrencecchen Jul 31, 2026
4f19a15
fix: explain unavailable hosted login
lawrencecchen Jul 31, 2026
2ffa6e3
test: cover resumable Codex provider auth
lawrencecchen Jul 31, 2026
266f41f
fix: keep Codex remote auth across resumes
lawrencecchen Jul 31, 2026
8b87e0b
test: prohibit SSH credential uploads
lawrencecchen Jul 31, 2026
674d6b9
test: detect unusable GCP account pools
lawrencecchen Jul 31, 2026
b571a76
test: close account import security gaps
lawrencecchen Jul 31, 2026
40140d8
test: make coalescing overlap deterministic
lawrencecchen Jul 31, 2026
de8d1c6
test: allow loaded hosts to run GCS fakes
lawrencecchen Jul 31, 2026
1767efd
test: keep user servers free of SSH services
lawrencecchen Jul 31, 2026
9442fd1
fix: upload server accounts over protected HTTP
lawrencecchen Jul 31, 2026
aa38ab3
test: cover concurrent account import safety
lawrencecchen Jul 31, 2026
1643d2b
fix: serialize protected account imports
lawrencecchen Jul 31, 2026
d8cc1c5
test: serialize server control token updates
lawrencecchen Jul 31, 2026
1104d01
fix: serialize server control token updates
lawrencecchen Jul 31, 2026
dcd1539
test: prevent Claude credential rollback
lawrencecchen Jul 31, 2026
35e6364
fix: serialize Claude credential rotation
lawrencecchen Jul 31, 2026
0cce2fa
test: close account import state races
lawrencecchen Jul 31, 2026
b215520
fix: make account state mutations atomic
lawrencecchen Jul 31, 2026
aecabe6
test: pin account lifecycle ownership
lawrencecchen Jul 31, 2026
941d89b
fix: own account state across worker lifecycles
lawrencecchen Jul 31, 2026
d6a4c17
test: close final account ownership gaps
lawrencecchen Jul 31, 2026
81b268c
fix: make account snapshots transactionally coherent
lawrencecchen Jul 31, 2026
2c6cd8e
test: enforce scoped proxy authority
lawrencecchen Jul 31, 2026
c53efbb
fix: separate import and proxy authority
lawrencecchen Jul 31, 2026
20a467b
test: bound websocket proxy resources
lawrencecchen Jul 31, 2026
ceb9508
fix: bound websocket proxy resources
lawrencecchen Jul 31, 2026
bb35253
test: bound supervised worker retirement
lawrencecchen Jul 31, 2026
cbc8313
fix: bound supervised worker retirement
lawrencecchen Jul 31, 2026
fd8d749
test: define hardened docker deployments
lawrencecchen Jul 31, 2026
e0c5c65
feat: add hardened docker deployments
lawrencecchen Jul 31, 2026
925823e
test: reserve container memory headroom
lawrencecchen Jul 31, 2026
d137181
fix: reserve container memory headroom
lawrencecchen Jul 31, 2026
f31ed1d
test: require live Codex GCP deploy gate
lawrencecchen Aug 1, 2026
b98a697
feat: deploy GCP through live Codex gate
lawrencecchen Aug 1, 2026
f4be212
test: pin GCP live upgrade evidence
lawrencecchen Aug 1, 2026
7b0c456
test: reproduce Docker team config mismatch
lawrencecchen Aug 1, 2026
bacf8d2
fix: make Docker team config portable
lawrencecchen Aug 1, 2026
ddf8dd0
feat: verify GCP deploys with live transports
lawrencecchen Aug 1, 2026
2768b55
Merge hosted Stack onboarding into GCP deploy
lawrencecchen Aug 1, 2026
f9b8a7a
test: cover GCP leases and local egress mode
lawrencecchen Jul 31, 2026
1ed2047
feat: preserve hosted and local-egress modes
lawrencecchen Aug 1, 2026
103cce5
test: require public GCP routing and read-only listing
lawrencecchen Aug 1, 2026
08cc598
test: require HTTPS upgrade observation
lawrencecchen Aug 1, 2026
a4dc5ee
fix: route GCP dogfood through public endpoints
lawrencecchen Aug 1, 2026
79893e1
test: allow end-user login against staging
lawrencecchen Aug 1, 2026
34106c9
feat: support public staging login
lawrencecchen Aug 1, 2026
d0bc537
Merge remote-tracking branch 'origin/main' into fix/server-login-http…
lawrencecchen Aug 1, 2026
d0fe9dc
test: exercise Docker profiles under memory cap
lawrencecchen Aug 1, 2026
0cac3b8
test: fix Docker API key fixture
lawrencecchen Aug 1, 2026
f1dd3e4
test: wait for supervisor generation changes
lawrencecchen Aug 1, 2026
2e98c6c
fix: await supervisor generation activation
lawrencecchen Aug 1, 2026
ae37e5d
test: keep tenant account reads scoped
lawrencecchen Aug 1, 2026
6d299a3
fix: authorize tenant account reads
lawrencecchen Aug 1, 2026
0fc3950
test: preserve observer upstream routing
lawrencecchen Aug 1, 2026
4306194
fix: preserve observer upstream routing
lawrencecchen Aug 1, 2026
6ee5863
test: cover deployment hardening failures
lawrencecchen Aug 3, 2026
c7de656
test: preserve runtime continuity across upgrades
lawrencecchen Aug 3, 2026
b29140e
test: expose credential integrity gaps
lawrencecchen Aug 3, 2026
78d338a
fix: preserve credential integrity under contention
lawrencecchen Aug 3, 2026
c1addc2
test: cover Claude routing and removal rollback
lawrencecchen Aug 3, 2026
5340c19
test: expand runtime continuity regressions
lawrencecchen Aug 3, 2026
44aa718
fix: route and remove Claude credentials consistently
lawrencecchen Aug 3, 2026
9d58a02
fix: preserve runtime continuity across deployments
lawrencecchen Aug 3, 2026
afc0d57
test: bound websocket copy buffers
lawrencecchen Aug 3, 2026
b9366c8
fix: budget websocket copy buffers before reads
lawrencecchen Aug 3, 2026
0477ee0
test: expose supervisor retirement status
lawrencecchen Aug 3, 2026
5d71da6
fix: report supervisor retirement lifecycle
lawrencecchen Aug 3, 2026
3654764
fix: harden hosted release deployments
lawrencecchen Aug 3, 2026
e87705d
test: canonicalize hosted account rotations
lawrencecchen Aug 3, 2026
9fe6fb9
fix: canonicalize hosted account rotations
lawrencecchen Aug 3, 2026
ea87665
test: require structured deployment evidence
lawrencecchen Aug 3, 2026
b17cb16
feat: split deployment evidence phases
lawrencecchen Aug 3, 2026
8a58b54
feat: gate production transitions on golden evidence
lawrencecchen Aug 3, 2026
ff62c0d
fix: keep activation rollbackable through commit
lawrencecchen Aug 3, 2026
16a8c55
test: close hosted onboarding review gaps
lawrencecchen Aug 3, 2026
1bd35c0
test: validate hosted repair uploads
lawrencecchen Aug 3, 2026
9f0b6db
test: hide hosted lease persistence failures
lawrencecchen Aug 3, 2026
7a7b0c9
fix: close hosted onboarding review gaps
lawrencecchen Aug 3, 2026
237ecec
feat: normalize staging predecessor with evidence
lawrencecchen Aug 3, 2026
ec71d1c
test: cover fresh VM topology and normalization reruns
lawrencecchen Aug 3, 2026
eeba202
feat: provision verified front topology on fresh VMs
lawrencecchen Aug 3, 2026
ab2cf74
test: add local production continuity golden gate
lawrencecchen Aug 3, 2026
6a5d6dc
test: pin golden continuity acceptance gates
lawrencecchen Aug 3, 2026
276dc2f
feat: enforce production golden continuity gate
lawrencecchen Aug 3, 2026
85f8462
test: bind deployment installer to release evidence
lawrencecchen Aug 3, 2026
b61f561
fix: deploy the attested front installer
lawrencecchen Aug 3, 2026
7db5000
test: bound failed topology activation cleanup
lawrencecchen Aug 3, 2026
e1233a4
fix: make topology activation cleanup one-shot
lawrencecchen Aug 3, 2026
7b243a1
test: require legacy lease POST evidence
lawrencecchen Aug 3, 2026
6b82f96
fix: bind local leases to legacy POST
lawrencecchen Aug 3, 2026
99df22c
test: validate golden fixtures with production schema
lawrencecchen Aug 3, 2026
a1573ca
fix: make deterministic golden evidence canonical
lawrencecchen Aug 3, 2026
be34403
test: require active fresh VM acceptance evidence
lawrencecchen Aug 3, 2026
b73ef5e
feat: require active fresh VM acceptance proof
lawrencecchen Aug 3, 2026
f1eca6a
test: bind deploy targets to URL and VM identity
lawrencecchen Aug 3, 2026
8cf9aca
test: reject golden continuity evidence gaps
lawrencecchen Aug 3, 2026
78bae59
fix: bind deployment evidence to live targets
lawrencecchen Aug 3, 2026
f4fd79b
test: reject dropped golden health probes
lawrencecchen Aug 3, 2026
3b0770d
test: cover golden runtime evidence shapes
lawrencecchen Aug 3, 2026
07afec1
test: cover macOS deployment temp collisions
lawrencecchen Aug 3, 2026
87cbe48
test: cover portable VM creation temp files
lawrencecchen Aug 3, 2026
8dad35a
fix: make deployment temp files portable
lawrencecchen Aug 3, 2026
fac1291
test: cover continuous golden runtime checks
lawrencecchen Aug 3, 2026
8e27567
test: reject chained HTTP socket overlap
lawrencecchen Aug 3, 2026
f1f00ac
test: bound deployment script subprocesses
lawrencecchen Aug 3, 2026
e01b7dc
test: reap deployment process groups
lawrencecchen Aug 3, 2026
9f68c1c
fix: enforce golden runtime continuity
lawrencecchen Aug 3, 2026
85fcc6f
test: isolate deployment scripts with system bash
lawrencecchen Aug 3, 2026
2ab1453
test: cover golden continuity input helper
lawrencecchen Aug 3, 2026
630d0a1
test: cover deployment contract CLI
lawrencecchen Aug 3, 2026
5d142a2
feat: add deployment contract CLI
lawrencecchen Aug 3, 2026
14e20b5
fix: centralize deployment script contracts
lawrencecchen Aug 3, 2026
bd153d5
test: gate golden streams on lifecycle phases
lawrencecchen Aug 3, 2026
b25cdf2
fix: make golden sampling lifecycle deterministic
lawrencecchen Aug 3, 2026
eae6f45
test: require process readiness before sampling
lawrencecchen Aug 3, 2026
f9c1c0d
fix: synchronize golden process registration
lawrencecchen Aug 3, 2026
3f85e12
test: require request drain before fake streams
lawrencecchen Aug 3, 2026
84193d7
fix: drain fake request bodies before streaming
lawrencecchen Aug 3, 2026
66bdbc3
test: require sender completion before fake streams
lawrencecchen Aug 3, 2026
2548ec9
fix: rendezvous on outbound request completion
lawrencecchen Aug 3, 2026
42cab9f
test: avoid durable sync in request rendezvous
lawrencecchen Aug 3, 2026
7900e4a
test: allow resume identifiers to repeat across observers
lawrencecchen Aug 3, 2026
81255ca
fix: scope resume freshness to observers
lawrencecchen Aug 3, 2026
d98874d
test: require observer writer lifecycle drain
lawrencecchen Aug 3, 2026
65f278b
fix: drain observer evidence lifecycle
lawrencecchen Aug 3, 2026
f792572
test: scope fake stream release to session
lawrencecchen Aug 3, 2026
7249ef0
fix: scope fake stream release ownership
lawrencecchen Aug 3, 2026
0e75b6b
test: exclude orderly probe cancellation
lawrencecchen Aug 3, 2026
bfd4783
fix: omit canceled probe samples
lawrencecchen Aug 3, 2026
5796d98
test: serialize probes per target
lawrencecchen Aug 3, 2026
27903df
fix: use persistent health probe workers
lawrencecchen Aug 3, 2026
4651d07
test: require resumable immutable releases
lawrencecchen Aug 3, 2026
2b406b5
fix: make immutable releases resumable
lawrencecchen Aug 3, 2026
4518013
test: reject ambiguous release lookup failures
lawrencecchen Aug 3, 2026
c7d88f5
fix: fail closed on release lookup errors
lawrencecchen Aug 3, 2026
2841568
test: require secure published Docker defaults
lawrencecchen Aug 3, 2026
691cabc
fix: secure published Docker defaults
lawrencecchen Aug 3, 2026
d95ebed
test: exercise initialized Docker Compose secrets
lawrencecchen Aug 3, 2026
b720daf
fix: preserve private Compose secrets
lawrencecchen Aug 3, 2026
b8e06a2
test: keep Docker state out of build cache
lawrencecchen Aug 3, 2026
0bf0386
fix: exclude Docker state from build context
lawrencecchen Aug 3, 2026
88f6b70
test: keep health probes on cadence
lawrencecchen Aug 3, 2026
19871cf
fix: launch health probes on cadence
lawrencecchen Aug 3, 2026
271e035
test: await probe shutdown on errors
lawrencecchen Aug 3, 2026
9764618
fix: await all health probes on shutdown
lawrencecchen Aug 3, 2026
8b036ed
test: require local daemon startup cleanup
lawrencecchen Aug 3, 2026
7396db5
fix: reap failed local daemon startups
lawrencecchen Aug 3, 2026
5035151
test: make daemon cleanup stress reliable
lawrencecchen Aug 3, 2026
9a104c2
test: reject golden readiness busy loops
lawrencecchen Aug 3, 2026
cbd7a77
fix: latch golden session readiness
lawrencecchen Aug 3, 2026
c472c68
test: require distinct socket continuity snapshots
lawrencecchen Aug 3, 2026
29cfe68
fix: prove candidate socket across retirement
lawrencecchen Aug 3, 2026
42ef883
test: preserve socket identity coverage
lawrencecchen Aug 3, 2026
786853a
test: require durable candidate socket proof
lawrencecchen Aug 3, 2026
4a2eb4a
fix: validate durable candidate socket proof
lawrencecchen Aug 3, 2026
b0baaee
test: keep retirement ordering on one clock
lawrencecchen Aug 3, 2026
bd59ad7
fix: compare local retirement timestamps
lawrencecchen Aug 3, 2026
738cfc2
test: require kernel-assigned daemon ports
lawrencecchen Aug 3, 2026
44fe537
fix: let kernel assign golden daemon port
lawrencecchen Aug 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.github
.DS_Store
**/*.log
**/*.tmp
deploy/docker/secrets
dist
tmp
125 changes: 125 additions & 0 deletions .github/workflows/gcp-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: GCP Deploy

on:
push:
branches: [main]
workflow_dispatch:
inputs:
deploy_environment:
description: "GCP environment to deploy"
required: true
default: "staging"
type: choice
options:
- staging
- production

permissions:
contents: read
id-token: write

concurrency:
group: gcp-deploy-${{ github.event_name == 'workflow_dispatch' && inputs.deploy_environment || 'staging' }}
cancel-in-progress: false

env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
SUBROUTER_GCP_PROJECT: ${{ vars.SUBROUTER_GCP_PROJECT }}
SUBROUTER_GCP_ZONE: ${{ vars.SUBROUTER_GCP_ZONE }}
SUBROUTER_DEPLOY_BINARY: ${{ github.workspace }}/dist/subrouter-linux-amd64
SUBROUTER_CLIENT_BINARY: ${{ github.workspace }}/dist/subrouter-linux-amd64
SUBROUTER_DEPLOY_REVISION: ${{ github.sha }}
SUBROUTER_CODEX_BIN: codex
SUBROUTER_CODEX_MODEL: gpt-5.6-sol

jobs:
deploy-staging:
name: Deploy and live-upgrade staging
if: github.event_name == 'push' || inputs.deploy_environment == 'staging'
runs-on: ubuntu-latest
environment: subrouter-staging
env:
SUBROUTER_GCP_INSTANCE: subrouter-staging
SUBROUTER_PUBLIC_HEALTH_URL: https://subrouter-staging.cmux.dev/healthz
steps:
- uses: actions/checkout@v6

- uses: actions/setup-go@v6
with:
go-version-file: go.mod

- uses: actions/setup-node@v6
with:
node-version: "24"

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ vars.SUBROUTER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.SUBROUTER_GCP_DEPLOY_SERVICE_ACCOUNT }}

- uses: google-github-actions/setup-gcloud@v3

- name: Build deploy candidate
run: |
mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o dist/subrouter-linux-amd64 ./cmd/subrouter
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved

- name: Install pinned Codex CLI
run: npm install --global @openai/codex@0.146.0

- name: Deploy with live Codex drain gate
run: deploy/gcp/deploy-live-upgrade.sh

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: A successful GCP deployment can leave the VM’s required readiness state or user-facing path unverified: staging checks a separate Cloudflare service, and production skips the optional public check. Add a GCP-specific authenticated/IAP or tailnet verification for both /_subrouter/health and /_subrouter/ready before the workflow succeeds.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/workflows/gcp-deploy.yml, line 72:

<comment>A successful GCP deployment can leave the VM’s required readiness state or user-facing path unverified: staging checks a separate Cloudflare service, and production skips the optional public check. Add a GCP-specific authenticated/IAP or tailnet verification for both `/_subrouter/health` and `/_subrouter/ready` before the workflow succeeds.</comment>

<file context>
@@ -0,0 +1,125 @@
+        run: npm install --global @openai/codex@0.146.0
+
+      - name: Deploy with live Codex drain gate
+        run: deploy/gcp/deploy-live-upgrade.sh
+
+      - name: Upload continuity evidence
</file context>


- name: Upload continuity evidence
if: always()
uses: actions/upload-artifact@v5
with:
name: gcp-staging-live-upgrade-${{ github.run_attempt }}
path: artifacts/gcp-live-upgrade
if-no-files-found: warn

deploy-production:
name: Deploy and live-upgrade production
if: github.event_name == 'workflow_dispatch' && inputs.deploy_environment == 'production'
runs-on: ubuntu-latest
environment: subrouter-production
env:
SUBROUTER_GCP_INSTANCE: subrouter-team
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
steps:
- uses: actions/checkout@v6

- uses: actions/setup-go@v6
with:
go-version-file: go.mod

- uses: actions/setup-node@v6
with:
node-version: "24"

- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v3
with:
workload_identity_provider: ${{ vars.SUBROUTER_GCP_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ vars.SUBROUTER_GCP_DEPLOY_SERVICE_ACCOUNT }}

- uses: google-github-actions/setup-gcloud@v3

- name: Build deploy candidate
run: |
mkdir -p dist
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -o dist/subrouter-linux-amd64 ./cmd/subrouter

- name: Install pinned Codex CLI
run: npm install --global @openai/codex@0.146.0

- name: Deploy with live Codex drain gate
run: deploy/gcp/deploy-live-upgrade.sh

- name: Upload continuity evidence
if: always()
uses: actions/upload-artifact@v5
with:
name: gcp-production-live-upgrade-${{ github.run_attempt }}
path: artifacts/gcp-live-upgrade
if-no-files-found: warn
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
deploy/docker/secrets/
/subrouter
bin/
!npm/bin/
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# syntax=docker/dockerfile:1.7

FROM golang:1.24-bookworm AS build

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .

ARG TARGETOS=linux
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -trimpath -ldflags="-s -w" -o /out/subrouter ./cmd/subrouter && \
mkdir -p /out/state

FROM gcr.io/distroless/static-debian12:nonroot

COPY --from=build /out/subrouter /usr/local/bin/subrouter
COPY --from=build --chown=65532:65532 /out/state /var/lib/subrouter

ENV HOME=/var/lib/subrouter \
SUBROUTER_STATE_DIR=/var/lib/subrouter \
GOMEMLIMIT=192MiB \
GOMAXPROCS=2

USER 65532:65532
EXPOSE 31415
VOLUME ["/var/lib/subrouter"]
HEALTHCHECK --interval=10s --timeout=3s --start-period=5s --retries=3 \
CMD ["/usr/local/bin/subrouter", "probe", "--url", "http://127.0.0.1:31415"]
ENTRYPOINT ["/usr/local/bin/subrouter"]
CMD ["serve", "--addr", "0.0.0.0:31415", "--sessions", "/var/lib/subrouter/sessions.json"]
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,43 @@ Subrouter is a local AI coding-agent proxy. It routes traffic across Codex accou

## Install

### Agent setup prompt
### GCP setup prompt

Paste this into Claude, Codex, or another coding agent that has SSH access to your server and a local browser for OAuth:
Paste this into Claude, Codex, or another coding agent with GCP operator access and a local browser for OAuth:

```text
Set up Subrouter as a shared production service.

Inputs:
- Server SSH target: <user@host>
- GCP project, zone, and instance: <project> <zone> <instance>
- Server URL reachable from my machine: http://<tailnet-ip-or-dns>:31415
- Local server nickname: team

Rules:
- Do not copy ~/.codex/auth.json or local ~/.subrouter/codex/accounts/*.json to the server.
- Server OAuth accounts must be created with fresh server-owned login flows.
- Do not print access tokens, refresh tokens, API keys, id tokens, or admin tokens.
- Never use SSH, SCP, or gcloud to transfer account credentials.
- Keep the listener private to Tailscale/VPC. Do not expose it to the public internet.
- Use the released Subrouter binary unless I explicitly ask you to build from source.

Steps:
1. On this local machine, create an admin token variable without printing it:
TOKEN="$(openssl rand -hex 32)"
2. Install the release on the server:
ssh <user@host> 'curl -fsSL https://github.com/manaflow-ai/subrouter/releases/latest/download/install.sh | sudo sh'
3. Install the systemd service with the local admin token and verify it over loopback:
ssh <user@host> "sudo sr install-systemd --addr 0.0.0.0:31415 --admin-token '$TOKEN'"
ssh <user@host> 'curl -fsS http://127.0.0.1:31415/_subrouter/health'
ssh <user@host> 'curl -fsS http://127.0.0.1:31415/_subrouter/ready'
4. Save the same admin token locally in Subrouter server config without printing it. This also writes Codex routing defaults to `CODEX_HOME/config.toml` or `~/.codex/config.toml`:
sr server add team --url http://<tailnet-ip-or-dns>:31415 --admin-token "$TOKEN" --default
5. Create server-owned Codex OAuth chains:
sr server sync team --device-auth
1. Configure the GCP project and publish the released service with deploy/gcp/publish-subrouter.sh. The installer must generate and provision its protected account-import token without printing it.
2. Verify from this client machine:
sr server status team

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: GCP prompt removed the sr server add team step but still runs sr server status team (step 2) and sr server sync team (step 3). Both commands fail with server "team" not found because the local nickname is never registered; add the server-registration step with its URL and --account-import-token before verification.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At README.md, line 39:

<comment>GCP prompt removed the `sr server add team` step but still runs `sr server status team` (step 2) and `sr server sync team` (step 3). Both commands fail with `server "team" not found` because the local nickname is never registered; add the server-registration step with its URL and `--account-import-token` before verification.</comment>

<file context>
@@ -13,49 +13,43 @@ Subrouter is a local AI coding-agent proxy. It routes traffic across Codex accou
-   sr server sync team --device-auth
+1. Configure the GCP project and publish the released service with deploy/gcp/publish-subrouter.sh. The installer must generate and provision its protected account-import token without printing it.
+2. Verify from this client machine:
+   sr server status team
+   curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/health
+   curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/ready
</file context>

curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/health
curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/ready
3. Create server-owned Codex OAuth chains:
sr server sync team
Follow each OAuth flow. Do not upload local refresh tokens.
6. Verify:
4. Verify:
sr server status team
curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/health
curl -fsS http://<tailnet-ip-or-dns>:31415/_subrouter/ready
ssh <user@host> 'journalctl -u subrouter --since "30 min ago" --no-pager | grep -Ei "WARN|ERROR|failed|401|502|503|no usable|refresh_token" | tail -n 200 || true'
7. Report:
5. Report:
- systemd active/running status
- health and readiness result
- number of registered Codex OAuth accounts
- any warning/error log lines, without secrets
- the exact command I should use for Codex through Subrouter
```

Expand Down Expand Up @@ -160,6 +154,8 @@ GET /_subrouter/drain-status
GET /_subrouter/accounts
GET /_subrouter/account-status
POST /_subrouter/account-status
GET /_subrouter/account-import
POST /_subrouter/account-import
GET /_subrouter/usage-status
GET /_subrouter/sessions
GET /_subrouter/dashboard
Expand All @@ -176,12 +172,13 @@ sudo sr install-systemd --addr 0.0.0.0:31415 --admin-token "$TOKEN"
sr server add team --url http://100.64.0.1:31415 --admin-token "$TOKEN" --default
```

When `SUBROUTER_ADMIN_TOKEN` or `--admin-token` is set, non-loopback requests to sensitive `/_subrouter/*` endpoints must send `Authorization: Bearer <token>` or `X-Subrouter-Admin-Token: <token>`. Loopback stays trusted so server-local hot reloads continue to work.
When `SUBROUTER_ADMIN_TOKEN` or `--admin-token` is set, non-loopback requests to sensitive `/_subrouter/*` endpoints must send `Authorization: Bearer <token>` or `X-Subrouter-Admin-Token: <token>`. Loopback stays trusted for ordinary admin endpoints. Account onboarding uses a distinct `SUBROUTER_ACCOUNT_IMPORT_TOKEN`; that token authorizes only `GET` and `POST /_subrouter/account-import` and cannot access admin APIs or proxy traffic.

## GCP deployment

See [deploy/gcp/README.md](deploy/gcp/README.md) for the small GCP + Tailscale Subrouter deployment flow.
See [docs/production.md](docs/production.md) for the production checklist before running a shared server.
See [deploy/docker/README.md](deploy/docker/README.md) for hardened local-account and cmux.com team containers.

Transcript recording is off by default. To persist raw Subrouter transcripts, pass a transcript directory:

Expand Down Expand Up @@ -299,7 +296,7 @@ On first run, Subrouter migrates legacy `~/.codex-accounts` state into `~/.subro
Server-owned OAuth accounts must be created with fresh logins because Codex refresh tokens rotate. Do not copy local OAuth account files to a server. To compare local OAuth emails with a configured server, validate server refresh-token chains, and reauth missing or invalid accounts on the server, run:

```bash
sr server sync team --device-auth
sr server sync team
```

To only show the diff:
Expand All @@ -310,7 +307,7 @@ sr server diff team

`sr server sync` prints the plan and asks before opening login. Use `--yes` for unattended sync, `--email you@example.com` to reauth one email, or `--all` to replace every local OAuth email on the server with a new server-owned refresh-token chain. The server status check may refresh valid server-owned OAuth chains in place because Codex refresh tokens rotate.

Account uploads hot-reload the live server process after writing the new server-owned account file. Existing proxy and WebSocket connections keep running.
Account login first checks the protected endpoint with `GET`, then sends the new credential with authenticated `POST`. It never transfers credentials with SSH, SCP, or gcloud. The server validates and atomically stores the credential, hot-reloads the account pool, and leaves existing HTTP and WebSocket proxy connections running. Use `--device-auth` only when the browser and CLI cannot share a localhost callback, such as a headless or remote shell.

Account-management commands are built into the `subrouter` binary:

Expand Down Expand Up @@ -365,7 +362,7 @@ One hosted Subrouter can serve many isolated users, each with their own account

Clients authenticate by base URL prefix, because agent CLIs can only override base URLs: point Codex at `https://host/t/<key>/v1` and Claude Code at `ANTHROPIC_BASE_URL=https://host/t/<key>`. The key is also accepted as a Bearer token or `x-api-key` header (Claude Code's `ANTHROPIC_AUTH_TOKEN` lands there). Account selection, sticky sessions, usage scoring, and transcripts are all scoped to the tenant's pool; an unknown or revoked key gets a 401. Requests without a tenant key keep the legacy single-tenant behavior.

`sr server add <name> --url <url> --tenant-key srt_...` stores the key on a server entry, after which `sr codex`, `sr claude push`, `sr server login/sync`, and the status commands operate on that tenant's pool automatically. Tenant CRUD lives on the admin-gated `/_subrouter/tenants` endpoints; tenant-scoped reads (`/t/<key>/_subrouter/{accounts,account-status,usage-status,sessions}`) are authorized by the tenant key itself.
`sr server add <name> --url <url> --tenant-key srt_...` stores the key on a server entry, after which `sr codex`, `sr claude push`, `sr server login/sync`, and the status commands operate on that tenant's pool automatically. Tenant CRUD lives on the admin-gated `/_subrouter/tenants` endpoints; tenant-scoped reads and account import (`/t/<key>/_subrouter/{accounts,account-status,usage-status,sessions,account-import}`) are authorized by the tenant key itself.

## Selection policy

Expand Down
13 changes: 13 additions & 0 deletions cmd/subrouter/cloud_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ func TestTeamProxyUsesDedicatedLocalSecret(t *testing.T) {
}
}

func TestLocalCredentialModeUsesDedicatedProxyAuthentication(t *testing.T) {
config := broker.Config{
CredentialSource: broker.CredentialSourceLocal,
LocalProxyToken: "dedicated-local-secret",
}
if got := cloudServerProxyToken(config); got != "dedicated-local-secret" {
t.Fatalf("server token = %q, want dedicated local secret", got)
}
if got := cloudClientProxyToken(config, localBaseURL()); got != "dedicated-local-secret" {
t.Fatalf("client token = %q, want dedicated local secret", got)
}
}

func TestTeamCodexIgnoresMalformedLegacyServerStore(t *testing.T) {
saveReadyCloudConfig(t)
local := healthServer(t, http.StatusOK)
Expand Down
Loading