Repository navigation
fix(server): under MOCA_TENANCY=multi, refuse SH_MODEL_HEADERS and a Vertex ADC file at boot - #833
Conversation
Under MOCA_TENANCY=multi, scrubAmbientCredentials deletes every provider
credential pi reads from the environment, but two ambient sources survive
it:
- SH_MODEL_HEADERS is sent on every caller's model request on the custom
openai-completions path, and its ${VAR} interpolation reads the process
environment. An inline secret, or a variable named outside the scrub's
shapes (${LITELLM_KEY}), stays and spends one operator's credential for
every tenant. No check can tell a secret header from a harmless one, so
multi now refuses to boot with it set.
- With GOOGLE_APPLICATION_CREDENTIALS scrubbed, pi-ai falls back to
$HOME/.config/gcloud/application_default_credentials.json, and the kept
GOOGLE_CLOUD_PROJECT/LOCATION let a google-vertex envelope run on it.
A scrub cannot remove a file, so multi now refuses to boot while it
exists.
Single tenancy is unchanged; both cases have tests. The configuration
reference and the MI1 R2 cell describe the new refusals.
Part of rossoctl#363 (its two multi-tenant boot refusals)
Assisted-By: Claude Code
Signed-off-by: Rong Chang <[email protected]>
Part of rossoctl#363 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
Adds two MOCA_TENANCY=multi boot refusals in prepareServerProcess: any non-empty SH_MODEL_HEADERS, and a Vertex ADC file at $HOME/.config/gcloud/application_default_credentials.json. I checked both against pi-ai's env-api-keys.ts at the pinned pi-fork commit (2c28be5). With GOOGLE_APPLICATION_CREDENTIALS scrubbed, hasVertexAdcCredentials falls back to _join(_homedir(), ".config", "gcloud", "application_default_credentials.json"), which is the path vertexAdcFile builds. The refusals are wired into both callers (server.ts startServer, worker.ts), and single tenancy is unchanged. Tests cover the multi and single cases for both, and add a drift guard. One nit: the R2 spec row this PR edits still cites a package path that no longer exists.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (server), Tests, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (k8s-kind-e2e still pending at review time)
| | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| | R1 | The sandbox receives an **explicit environment allowlist** (`LANG`, `LC_ALL`, `LC_CTYPE`, `TZ`), never the worker's process environment. It is applied in `createPodBashOps`, which both the `bash` tool and the `user_bash` hook reach — no `pi-fork` change | a planted secret-shaped variable never appears in any `Exec.command`, through the real bash tool — `packages/k8s-sandbox/test/extension.test.ts`; the allowlist prefix built by `createPodBashOps`, `test/operations.test.ts`; the allowlist itself, `test/sandbox-env.test.ts` | | ||
| | R2 | `applyModelGateway` seeds `ANTHROPIC_API_KEY` only with the constant sentinel, never a caller's token. A shared `prepareServerProcess()` runs in `startServer()`, the P6 worker and the async-run job (`leaf-job.ts`); under `multi` it deletes every provider credential pi can read from the environment (any `*_API_KEY`, `*_AUTH_TOKEN` or `*_OAUTH_TOKEN`, `HF_TOKEN`, `COPILOT_GITHUB_TOKEN`, Bedrock's `AWS_*` sources and `GOOGLE_APPLICATION_CREDENTIALS`), leaving only the sentinel, and refuses `SH_LOCAL_TOOLS=1` and `SH_REQUIRE_AUTH` other than `true`. Under `single` an operator's own ambient key is left in place | a token-less call after an authenticated one sees only the sentinel, and a caller credential on a non-Anthropic model throws — `harness/test/model-gateway.test.ts`; the multi scrub deletes the OAuth token, which outranks the sentinel, `single` keeps an operator key, and `multi` refuses both settings — `packages/knative-server/test/server-process.test.ts`; all three entry points call `prepareServerProcess` — `test/worker-boot.test.ts` | | ||
| | R2 | `applyModelGateway` seeds `ANTHROPIC_API_KEY` only with the constant sentinel, never a caller's token. A shared `prepareServerProcess()` runs in `startServer()`, the P6 worker and the async-run job (`leaf-job.ts`); under `multi` it deletes every provider credential pi can read from the environment (any `*_API_KEY`, `*_AUTH_TOKEN` or `*_OAUTH_TOKEN`, `HF_TOKEN`, `COPILOT_GITHUB_TOKEN`, Bedrock's `AWS_*` sources and `GOOGLE_APPLICATION_CREDENTIALS`), leaving the sentinel, and refuses `SH_LOCAL_TOOLS=1`, `SH_REQUIRE_AUTH` not `true`, `SH_MODEL_HEADERS` and a Vertex ADC file. `single` retains an operator's key | a token-less call after an authenticated one sees only the sentinel, and a caller credential on a non-Anthropic model throws — `harness/test/model-gateway.test.ts`; the multi scrub deletes the OAuth token, which outranks the sentinel, `single` keeps an operator key, and `multi` refuses all four — `packages/knative-server/test/server-process.test.ts`; all three entry points call `prepareServerProcess` — `test/worker-boot.test.ts` | |
There was a problem hiding this comment.
nit: This row now says multi refuses all four, but the test it cites, packages/knative-server/test/server-process.test.ts, no longer exists. The file is packages/server/test/server-process.test.ts. The stale path was already on main, but this line is being rewritten anyway, so it would be cheap to fix it here.
There was a problem hiding this comment.
Fixed in this push: the R2 row now cites packages/server/test/server-process.test.ts, and so do the R3 and R4 rows and the S1 note further down, which carried the same stale packages/knative-server/... path from before the rename. Prettier re-padded the table to the shorter cell; no other text changed.
Assisted-By: Claude Code
…t.ts The test moved with the knative-server rename; the R2-R4 rows and the S1 note still named the old path (review nit). Part of rossoctl#363 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837, rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824), egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer (rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers (rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors (rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821). Conflicts (one): - deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843) rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA row after SBX_PROFILE, then re-padding the table with prettier. The fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly. Merged without markers, checked: setup.sh keeps the fork's SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS; both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases beside upstream's. The fork's RUNBOOK, README and template-onboarding docs say nothing about sandbox lifetime, refusal bursts, login errors or the create rollback, so none needed a correction; GUIDE.md is unchanged and GUIDE.pdf is not regenerated. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Part of #363: its two multi-tenant boot refusals. The issue stays open for the items listed under "Out of scope".
What changed and why
Under
MOCA_TENANCY=multi,scrubAmbientCredentialsdeletes every provider credential pi reads from the environment. Two ambient sources survive that scrub.prepareServerProcess(packages/server/src/server-process.ts) now refuses to boot with either one, the same way it already refusesSH_LOCAL_TOOLS=1. Each error message names the variable or file and says why.SH_MODEL_HEADERS. These headers are sent on every caller's model request on the customopenai-completionspath, andparseModelHeadersfills${VAR}values from the process environment. A variable outside the scrub's patterns (for example${GATEWAY_KEY}), or a secret written inline, stays in the process. Every tenant's requests would then spend one operator's credential. No check can tell a secret header from a harmless one, somultirefuses any non-emptySH_MODEL_HEADERS. This is the first option the issue offers. Refusing only${VAR}values would still let an inline secret through.GOOGLE_APPLICATION_CREDENTIALSis scrubbed, pi-ai'shasVertexAdcCredentialsfalls back to$HOME/.config/gcloud/application_default_credentials.json.GOOGLE_CLOUD_PROJECTandGOOGLE_CLOUD_LOCATIONare deliberately kept, so agoogle-vertex/runsenvelope would run on that shared file. A scrub cannot remove a file, somultirefuses to boot while the file exists. The check runs after the scrub, so the path it tests is the one pi will read.vertexAdcFile(env)builds the same path pi builds (os.homedir(), which is$HOMEon POSIX).SH_MODEL_HEADERSwith interpolation and their own gcloud login.docs/reference/configuration.mdupdates theMOCA_TENANCYandSH_MODEL_HEADERSrows and the paragraph on the scrub. The MI1 spec's R2 cell (docs/specs/2026-09-28-moca-multi-user-isolation-design.md) lists the two new refusals. That cell's "every provider credential" claim is now accurate, as the issue requested.Tests
New tests in
packages/server/test/server-process.test.ts:under multi tenancy refuses SH_MODEL_HEADERS, interpolated or inline (#363)covers both{"Authorization":"Bearer ${GATEWAY_KEY}"}and an inline literal.under single tenancy keeps SH_MODEL_HEADERS and its interpolation source (#363)under multi tenancy refuses a Vertex application-default credentials file (#363)pointsHOMEat a temp directory that holds the file. It also setsGOOGLE_APPLICATION_CREDENTIALS, to show that scrubbing it does not close the gap.under single tenancy boots with a Vertex application-default credentials file (#363)vertexAdcFile is the path pi-ai falls back to (drift guard)reads pi-ai'senv-api-keys.tsand fails if pi moves its fallback path.The existing multi success-path test now uses an empty
HOME. Without that, a developer's own gcloud login could make it fail.Before and after (
vitest run test/server-process.test.ts):server-process.tsfrom main:Tests 3 failed | 24 passed (27). The two refusal tests fail withexpected [Function] to throw an error, and the drift guard fails withvertexAdcFile is not a function. Both single-tenant tests pass, which confirms single-tenant behavior was the same before this change.Tests 27 passed (27).Also run:
@moca/serverfull suite: 33 files, 582 tests passed.@moca/servertsc --noEmit: clean.python3 scripts/check-doc-links.py: 212 files, 0 broken links.Out of scope
This PR covers only the two multi-tenant boot refusals. The issue's other items, and their state on main:
/workloads: already done. GET has been read-only since the workload rewrite, and test: pin the GET/delete and double-delete workload lifecycle races (#445) #549 pins it. The issue's box is ticked.ensure_exec_listener'send_with_newlinepin: still open, as far as a read of the test file shows. Theensure_exec_listenerfixtures indeploy/vm/tests/setup-vm.test.shwrite arelay.envthat ends in a newline. Onlyensure_exec_tokenhas a fixture with no final newline.claimName's|| multiterm: appears moot.claimNameand that term no longer appear inpackages/server/srcafter the workload rewrite.handleCreateWorkload"wherever callers are told apart" wording is gone from main.run-turn.ts:836-848cite is gone.makeDefaultValidateTokencite still readsmain.ts:268-283, but the function is now at:501.executeTurn".deploy/vm/README.mdstill says "(step 3 below)".Every commit is signed off (DCO).
Assisted-By: Claude Code