Skip to content

fix(server): under MOCA_TENANCY=multi, refuse SH_MODEL_HEADERS and a Vertex ADC file at boot - #833

Merged
webchang merged 3 commits into
rossoctl:mainfrom
webchang:pr/i363-multi-refusals
Nov 16, 2026
Merged

webchang merged 3 commits into
rossoctl:mainfrom
webchang:pr/i363-multi-refusals

Conversation

@webchang

Copy link
Copy Markdown
Member

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, scrubAmbientCredentials deletes 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 refuses SH_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 custom openai-completions path, and parseModelHeaders fills ${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, so multi refuses any non-empty SH_MODEL_HEADERS. This is the first option the issue offers. Refusing only ${VAR} values would still let an inline secret through.
  • Vertex application-default credentials file. Once GOOGLE_APPLICATION_CREDENTIALS is scrubbed, pi-ai's hasVertexAdcCredentials falls back to $HOME/.config/gcloud/application_default_credentials.json. GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION are deliberately kept, so a google-vertex /runs envelope would run on that shared file. A scrub cannot remove a file, so multi refuses 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 $HOME on POSIX).
  • Single tenancy is unchanged: an operator can still use SH_MODEL_HEADERS with interpolation and their own gcloud login.
  • Docs: docs/reference/configuration.md updates the MOCA_TENANCY and SH_MODEL_HEADERS rows 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) points HOME at a temp directory that holds the file. It also sets GOOGLE_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's env-api-keys.ts and 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):

  • With the test changes and server-process.ts from main: Tests 3 failed | 24 passed (27). The two refusal tests fail with expected [Function] to throw an error, and the drift guard fails with vertexAdcFile is not a function. Both single-tenant tests pass, which confirms single-tenant behavior was the same before this change.
  • With the fix: Tests 27 passed (27).

Also run:

  • @moca/server full suite: 33 files, 582 tests passed.
  • @moca/server tsc --noEmit: clean.
  • python3 scripts/check-doc-links.py: 212 files, 0 broken links.
  • pre-commit (prettier, gitleaks): passed.

Out of scope

This PR covers only the two multi-tenant boot refusals. The issue's other items, and their state on main:

  • GET write-back race on /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's end_with_newline pin: still open, as far as a read of the test file shows. The ensure_exec_listener fixtures in deploy/vm/tests/setup-vm.test.sh write a relay.env that ends in a newline. Only ensure_exec_token has a fixture with no final newline.
  • claimName's || multi term: appears moot. claimName and that term no longer appear in packages/server/src after the workload rewrite.
  • Comment and doc fixes:
    • The handleCreateWorkload "wherever callers are told apart" wording is gone from main.
    • The spec's run-turn.ts:836-848 cite is gone.
    • Still open: the spec's makeDefaultValidateToken cite still reads main.ts:268-283, but the function is now at :501.
    • Still open: the R3/R4 cells still say "the solve and verdict leaves", and the amendment still says the prompt leaf runs "through executeTurn".
    • Still open: deploy/vm/README.md still says "(step 3 below)".

Every commit is signed off (DCO).

Assisted-By: Claude Code

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]>
@webchang
webchang requested a review from pdettori as a code owner November 16, 2026 20:37
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 16, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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]>
@webchang
webchang merged commit 3786d30 into rossoctl:main Nov 16, 2026
17 checks passed
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
webchang added a commit to webchang/moca that referenced this pull request Nov 17, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants