Repository navigation
Fix server account login to use protected HTTP #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 31 commits
a641aae
e702574
b0c50d0
be727eb
e9d12a3
6fe3c5b
4f19a15
2ffa6e3
266f41f
8b87e0b
674d6b9
b571a76
40140d8
de8d1c6
1767efd
9442fd1
aa38ab3
1643d2b
d8cc1c5
1104d01
dcd1539
35e6364
0cce2fa
b215520
aecabe6
941d89b
d6a4c17
81b268c
2c6cd8e
c53efbb
20a467b
ceb9508
bb35253
cbc8313
fd8d749
e0c5c65
925823e
d137181
f31ed1d
b98a697
f4be212
7b0c456
bacf8d2
ddf8dd0
2768b55
f9b8a7a
1ed2047
103cce5
08cc598
a4dc5ee
79893e1
34106c9
d0bc537
d0fe9dc
0cac3b8
f1dd3e4
2e98c6c
ae37e5d
6d299a3
0fc3950
4306194
6ee5863
c7de656
b29140e
78d338a
c1addc2
5340c19
44aa718
9d58a02
afc0d57
b9366c8
0477ee0
5d71da6
3654764
e87705d
9fe6fb9
ea87665
b17cb16
8a58b54
ff62c0d
16a8c55
1bd35c0
9f0b6db
7a7b0c9
237ecec
ec71d1c
eeba202
ab2cf74
6a5d6dc
276dc2f
85f8462
b61f561
7db5000
e1233a4
7b243a1
6b82f96
99df22c
a1573ca
be34403
b73ef5e
f1eca6a
8cf9aca
78bae59
f4fd79b
3b0770d
07afec1
87cbe48
8dad35a
fac1291
8e27567
f1f00ac
e01b7dc
9f68c1c
85fcc6f
2ab1453
630d0a1
5d142a2
14e20b5
bd153d5
b25cdf2
eae6f45
f9c1c0d
3f85e12
84193d7
66bdbc3
2548ec9
42cab9f
7900e4a
81255ca
d98874d
65f278b
f792572
7249ef0
0e75b6b
bfd4783
5796d98
27903df
4651d07
2b406b5
4518013
c7d88f5
2841568
691cabc
d95ebed
b720daf
b8e06a2
0bf0386
88f6b70
19871cf
271e035
9764618
8b036ed
7396db5
5035151
9a104c2
cbd7a77
c472c68
29cfe68
42ef883
786853a
4a2eb4a
b0baaee
bd59ad7
738cfc2
44fe537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 | ||
|
|
||
| - 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Prompt for AI agents |
||
|
|
||
| - 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 | ||
|
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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| .DS_Store | ||
| deploy/docker/secrets/ | ||
| /subrouter | ||
| bin/ | ||
| !npm/bin/ | ||
|
|
||
| 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"] | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: GCP prompt removed the Prompt for AI agents |
||
| 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 | ||
| ``` | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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: | ||
|
|
||
|
|
@@ -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: | ||
|
|
@@ -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: | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.