Repository navigation
feat: add edge model proxy so the child never holds the raw provider key - #5
Conversation
# Conflicts: # CHANGELOG.md # README.md # worker-configuration.d.ts # worker/index.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 43cd6f82ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (typeof env.MODEL_SIGNING_SECRET !== "string" || new TextEncoder().encode(env.MODEL_SIGNING_SECRET).byteLength < 32) { | ||
| throw new Error("model proxy is enabled but MODEL_SIGNING_SECRET is not configured"); | ||
| } |
There was a problem hiding this comment.
Fail closed when the upstream key is absent
When CRABHELM_MODEL_PROXY=on and MODEL_SIGNING_SECRET is present but OPENAI_API_KEY is unset or blank, this path still mints and installs a model token even though /model/* later returns 503 because modelProxyConfigured() requires the upstream key. The admission check blocks new claws in that configuration, but already-issued bootstrap tokens can still hit credentials.env during an existing install or credential rotation and leave the child with unusable credentials; include the raw provider key in this fail-closed check before signing.
Useful? React with 👍 / 👎.
… head 879812f) The validator's surviving block is body-truthfulness, not code: the "How tested" section asserts a run count that does not reconcile with the runs it lists. No tree change is owed -- `git status` in the worktree is clean and `.github/workflows/tag-on-merge.yml` is byte-identical to its source, as the validator's own prior rounds confirmed. Measured, repo-wide, on 2026-10-15 (the filter the body names, `name == charly/pr-validator`): 14:50:01Z completed/failure 14:12:33Z completed/failure 13:06:51Z completed/failure 12:48:02Z completed/failure 11:56:03Z completed/failure Five runs exist. The corrected body enumerates all five so the count and the list agree; it also sources the digest it cites with the command that produces it, or drops it. Missed control: I read a validator verdict as stale after grepping for a specific string and not finding it -- promoting a negative result about one string into a positive claim about the verdict's relevance. A re-run replays a workflow run's stored event payload and does not re-read the current PR body, so the corrected body can only reach the validator through a new head. This commit exists to create that head; it carries the round's RCA rather than a tree change, because the tree owes none. Assisted-by: dsh DeepSeek deepseek-v4.1-flash (analysed on a live system)
What & why
Today the child VM is handed the raw org-wide
OPENAI_API_KEYincredentials.envand calls the provider directly. That key is unrevocable per-claw and identical across the fleet — the single biggest credential-exposure gap, and the one thingredhat-et/claw-operatorsolves with its credential proxy (the agent pod never holds a real provider key).This adds the Crabhelm equivalent — an edge model proxy — behind a flag:
When
CRABHELM_MODEL_PROXY=on:credentials.envdelivers a per-claw, audience-bound model token (typ:"model",aud:"crabhelm-model",clawId, TTL = substrate lifetime) asOPENAI_API_KEY, plusCRABHELM_MODEL_BASE_URL, instead of the raw key.bootstrap-child.shsetsmodels.providers.openai.baseUrltohttps://crabhelm-runtime.openclaw.ai/model/v1, rerouting the built-inopenai/*provider through the Worker. (Verified against OpenClaw source: for a built-in provider theOPENAI_BASE_URLenv is ignored — the config override is required.)worker/model-proxy.ts, mounted at/model/*on the runtime host) verifies the model token, strips the caller'sAuthorization, injects the realOPENAI_API_KEY, and forwards to a single fixed upstream (api.openai.com) over an endpoint allowlist (/v1/chat/completions,/v1/responses,/v1/responses/compact,/v1/embeddings,GET /v1/models). Streaming (SSE) passes straight through.Net: the raw provider key never leaves Cloudflare, and each claw receives independently scoped access bounded to its substrate lifetime instead of the same org-wide key on every VM.
When off (default): new credential delivery returns exactly
OPENAI_API_KEY=<raw>and appliance bootstrap clears a previously managed proxy base URL. The edge route keeps accepting already-issued tokens during rollback while the signing secret remains configured, avoiding an immediate outage.Security properties (tested)
api.openai.com— never caller-influenced (SSRF-safe); client auth stripped, real key injected, upstream auth/cookies never echoed.MODEL_SIGNING_SECRETthrows at credential delivery.Testing
pnpm checkgreen (120 tests). Newtests/model-proxy.test.ts(16 tests) covers readiness gating, auth, route/method/SSRF allowlisting, Worker-first deployment routing, response compaction, key injection + client-auth stripping, internal-identity filtering, bounded streaming, 502 on upstream failure, and credential-delivery on/off + fail-closed.tests/bootstrap.test.tsexecutes both proxy setup and missing-override rollback paths.Before enabling (why draft)
wrangler secret put MODEL_SIGNING_SECRET(≥32 bytes).bootstrap-child.sh).CRABHELM_MODEL_PROXY=onon staging, provision one claw, and confirm the existing live inference probe passes end-to-end through the proxy before enabling in production.For rollback, set the flag off and rebuild + re-pin affected claws so bootstrap clears the managed base URL and restores the raw key. Keep
MODEL_SIGNING_SECRETconfigured through the longest issued token TTL (4 hours by default, 24 hours maximum) so in-flight old claws remain usable during the transition.Follow-ups (noted, not in scope)