Repository navigation
feat: per-user inference credential headers and sandbox research tooling (#368 phase 1) - #372
Conversation
mrsabath
left a comment
There was a problem hiding this comment.
Four-tier credential-header change, and the central factual claim checks out: api-key's default binding is X-API-Key: {key} (credential-store.ts:95), which inferenceAuthHeader maps to x-api-key, and the exchange's authHeader is threaded to turn-auth -> UpstreamCredential.header -> applyModelGateway, with each tier refusing unknown values rather than defaulting to one.
The "PUT cannot see the deployment default" justification for re-checking the endpoint at exchange time is real, not defensive duplication: baseUrl = endpoint ?? deps.config.defaultInferenceEndpoint (exchange.ts:119) resolves after PUT has already run, so the two checks genuinely see different values.
Cross-tier consistency verified in both directions. mocactl's KNOWN_KINDS field names match the server's KINDS registry (api-key -> key on both sides), so the mirrored form checks cannot drift from the authoritative ones on field naming. Secret hygiene is consistent too: every refusal path has a test asserting the value is not echoed, and MI1 R2 (the caller's key never entering process.env) gets a direct assertion rather than an implied one.
Two non-blocking notes inline. The operator-fallback one is a message-attribution problem, not a behavioural one.
On the failing proto check
Pre-existing on main, not caused by this PR. Identical job and identical step 10 ("Build and test remote-worker") on the same base commit 73f1bf41 that #371 sits on, where it is already failing on a push to main.
Worth one caveat I would not apply to #371: this PR does change remote-worker/ (both Dockerfiles, plus a new Go test), so it is not a priori unrelated to that job the way a TypeScript-only PR would be. The failure predates the branch, so it is not caused by it — but once main is green again, this is the PR worth re-checking rather than assuming clean.
Areas reviewed: TypeScript (harness, control-plane, knative-server, mocactl), Shell, Dockerfile, Go, CI
Commits: 7, all signed off, DCO passing
CI status: 12 pass, 1 fail (inherited from main)
One process note, not a review finding: the test plan's "live turn with a real Anthropic API key" is unchecked and deferred to phase 2, so the end-to-end path this PR exists to enable is verified against a local wire-level stand-in rather than api.anthropic.com. Stated openly in the description and reasonable for phase 1 — flagging only so it is not lost between phases.
| rec.sessionId, | ||
| ); | ||
| } | ||
| if (secretValue.startsWith('sk-ant-api') && host !== 'api.anthropic.com') { |
There was a problem hiding this comment.
This block sits at function scope, after the stored and operator-fallback branches merge, so secretValue and credentialName can both come from the fallback.
An operator who sets operatorInferenceToken to a raw sk-ant-api... key -- and the config comment calls it "the operator's own key" (handlers.ts:23) -- together with a gateway defaultInferenceEndpoint gets this handed to the end user:
credential 'operator-fallback' is an Anthropic API key, but its endpoint resolves to litellm.internal: set its endpoint to https://api.anthropic.com
The refusal is correct -- that key would 401 at the gateway, and refusing beats misdirecting the secret. But it is delivered to a user who does not own operator-fallback and cannot re-store it, and "set its endpoint" is unactionable for them.
The description lists "the operator-fallback refusal message is user-facing rather than operator-facing" as a known minor, but under the Bearer check above; this new check has the same shape. Worth either scoping both to if (stored) or branching the message on usedOperatorFallback so the operator-side case names the env var instead.
Note that exchange-auth-header.test.ts's "keeps the operator fallback on Bearer" case uses op-gw-token, which trips neither check -- so the suite does not currently cover this path.
Suggestion, not blocking.
There was a problem hiding this comment.
Fixed in fa6e555. Good catch: both direct-mode checks see the fallback's token, not only the new one.
When usedOperatorFallback is the source, the exchange now:
- refuses with
credential_unavailable(a deployment fault) instead ofcredential_required; - uses a message that names
SH_OPERATOR_INFERENCE_TOKEN/SH_DEFAULT_INFERENCE_ENDPOINTand tells the caller the operator has to fix it, or that they can store their own credential.
One consequence I hit while doing this: turn-auth's PASSTHROUGH admits caller-attributable codes only, so the data plane shows the caller a generic control plane returned 503. That's the right attribution, but it means the operator-facing text reached nobody. So the refusal also logs [control-plane] operator fallback misconfigured: …. The log line names the settings, never the token.
There are two new tests, one for each mismatch: a raw sk-ant-api operator key on a gateway default, and a Bearer operator token on an api.anthropic.com default. Each asserts the code, the message, the log, and that no token is echoed. That covers the path the op-gw-token case missed.
| Authorization: `Bearer ${authToken}`, | ||
| 'x-api-key': null, // strip x-api-key when using gateway Bearer auth | ||
| } as unknown as Record<string, string>, | ||
| headers: (authHeader === 'x-api-key' |
There was a problem hiding this comment.
authHeader is computed unconditionally above, but this header block is gated on authToken being truthy. For { mode: 'direct', value: '', header: 'x-api-key' } with no deployment token, authToken is falsy and no auth header is set at all -- the request goes upstream unauthenticated rather than failing loudly.
Unreachable today: the exchange refuses before it can return an empty secretValue (exchange.ts, the if (!secretValue) throw). The new model-gateway.test.ts case covering an empty value with a deployment token exercises the adjacent path, which is the one that actually matters.
Raising it only because the guarantee lives one tier away, in a function that otherwise validates its own inputs.
Nit.
There was a problem hiding this comment.
Leaving this one as is, deliberately.
An empty caller value falling through the chain predates this PR. It's pinned by model-gateway.test.ts's "treats an empty value as 'not set', like every other term in the chain" case, so that "" means unset uniformly across config, upstream credential and env.
What this PR adds is that the fall-through doesn't carry the header along. upstream is undefined for an empty value, so authHeader is 'authorization', and the new "never applies a header choice to the deployment token" case pins that.
As you say, the no-token-at-all request is unreachable from the exchange, which throws on an empty secretValue. Making applyModelGateway fail loud on an empty caller value would reverse a documented contract for every caller, not just this path. I'd rather do that as its own change if we want it.
An inference credential goes upstream as Authorization: Bearer or as x-api-key, per its binding. Refuse at PUT any other binding, a raw Anthropic key on Bearer, an Anthropic OAuth token, Bearer to api.anthropic.com, and an api.anthropic.com endpoint with a path. Refs rossoctl#368, rossoctl#362 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
applyModelGateway sent every per-caller credential as Authorization: Bearer and stripped x-api-key, so a raw Anthropic API key 401'd at api.anthropic.com. UpstreamCredential now names its header; absent still means Bearer. A wire-level test drives pi-ai's client against a local server. The caller's key stays out of the environment (MI1 R2). Refs rossoctl#368, rossoctl#362 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ta plane The exchange names the header a credential travels in (authHeader, present only for x-api-key), and turn-auth threads it into the upstream credential. The exchange refuses with credential_required: - a stored binding the inference path cannot send; - a Bearer credential whose resolved endpoint is api.anthropic.com (PUT cannot see the deployment default); - an x-api-key credential behind a Bearer-only injector. The compose smoke stores a raw Anthropic key as kind api-key. Refs rossoctl#368 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… rest The credential step names the two shapes that reach a model: a gateway token as kind bearer, or an Anthropic API key as kind api-key to https://api.anthropic.com. The form refuses, before submitting, the shapes the control plane refuses at PUT. Refs rossoctl#368 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…he sandbox curl-minimal and ca-certificates were inherited from ubi-minimal, never installed; they are now explicit (no size change). HOME was whatever the runtime chose for a uid with no passwd entry: podman's WORKDIR, Docker's /. It is now /home/sandbox, created like /workspace, so git config --global works under any runtime. A static test pins both Dockerfiles. Refs rossoctl#368 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ed raw keys Final-review fixes for rossoctl#368: - In placeholder mode the exchange never returns authHeader: the harness sends Bearer <placeholder> as before, and the injector picks the upstream header (AB1 inject_header). This replaces the refusal of x-api-key credentials there, which broke api-key credentials that worked before rossoctl#368. - In direct mode, a raw Anthropic key whose endpoint resolves anywhere but api.anthropic.com (e.g. an endpoint-less key on a gateway default) is refused with credential_required, instead of being sent to the gateway and 401ing. - UpstreamCredential's doc comment is back above the type, and no longer claims every pre-rossoctl#368 credential is Bearer. Refs rossoctl#368 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…rator Both direct-mode endpoint checks in the exchange also see the operator fallback's token. The refusal was right, but it told the caller to re-store 'operator-fallback', which they cannot do. When the fallback is the source, the exchange now: - refuses with credential_unavailable (a deployment fault) rather than credential_required; - names SH_OPERATOR_INFERENCE_TOKEN and SH_DEFAULT_INFERENCE_ENDPOINT; - logs the reason on the control plane. The data plane shows the caller only a generic 503, so the log is how the operator finds out. Neither the message nor the log carries the token. Addresses PR rossoctl#372 review. Refs rossoctl#368 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
062f027 to
fa6e555
Compare
Performed 2026-10-01 on the shared KVM rig at main @ 03d2ee8: every act held. One person played both users with two GitHub accounts on one laptop; two people on two laptops is not yet tried. The run's outputs replace the illustrative ones, and Act 5 is filled in. Step fixes it found: pull the sandbox image in 0a (setup-vm.sh never pulls; the rig's predated rossoctl#372), approve user 2's device code in a private window, list session ids in 3a (the TUI titles both users' sessions by the same prompt), point 4c at the hostname and kernel suffix (host and guest are both 6.18.44), and the records' order in 0d. Fix list items 4-9 are new. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…#415) An agent's first `git commit` in a sandbox failed with exit 128 ("Please tell me who you are") until it configured an identity itself -- observed live on the VM demo (docs/demos/vm-multi-user-demo.md, fix list 5), on both P4 sessions and on the container tier. Each workaround cost a tool call and a model round, in front of an audience. Fix both leaf images the way the issue proposes: a system gitconfig (/etc/gitconfig, user.name "MOCA sandbox" / user.email [email protected]), which applies to ANY uid the images can run as -- including the arbitrary gid-0 uid under nonroot-v2 that #372's writable HOME prepares but cannot pre-configure -- and which a user's or agent's own higher-precedence config still overrides. The P4 rootfs inherits it for free, being exported from this image by build-rootfs.sh. Guards, per the issue: - research_tooling_test.go: a static pin of the exact RUN instruction (and its position before the USER drop), plus a runtime check that extracts the printf's format string, installs it as a scratch environment's ONLY git config, and runs a real no-prior-config commit -- so a gitconfig the line still prints but git silently ignores fails CI, not the next demo. - build-snapshot.sh: check_git_identity runs a real empty commit (with user.useConfigOnly=true, so an unconfigured git fails instead of auto-guessing) in the booted guest of both VMM arms, before quiescing -- a rootfs built from an image that lost its gitconfig now fails the snapshot build, not the demo. build-snapshot.test.sh pins the gate's contract (existence, both arms, probe->check->quiesce order, useConfigOnly, real commit, #415 pointer). Verified: go test ./... in remote-worker (including mutation tests on the new guards: commented-out RUN, RUN-after-USER, and a typo'd section header all fail), hadolint clean on both Dockerfiles, shellcheck -S warning clean, build-snapshot.test.sh and build-rootfs.test.sh PASS. Co-Authored-By: Claude Code <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
`podman run` resolves an image reference only when the host has no copy of it, so a mutable `:latest` pulled once is never re-resolved -- every later `setup-vm.sh` run starts the sandboxes on it. On the 2026-10-01 KVM rig that copy predated #372: HOME was the shared /workspace rather than /home/sandbox, and nothing in the bring-up's output hinted the containers were not what main builds. `build-rootfs.sh` had the same bug in a worse place: `podman image exists || podman pull` pulled only on a host with no copy, and a snapshot is built once and run for a long time, so a stale rootfs outlived the image it was meant to track. Both now pull before use, fail closed on a failed pull, and take SH_SKIP_PULL=1 as the documented override for an offline host or a locally built image -- the convention #349 established for `deploy/compose/install.sh`. setup-vm.sh pulls before start_sandboxes, because `podman run --replace` recreates each container from whatever the reference resolves to at that moment. Both also log the resolved image id and creation time rather than the tag asked for: `:latest` is the same string on a current and a pre-#372 host, so the id is what answers "is this host on the current image?". Tests: setup-vm.test.sh gains the pull, the fail-closed refusal, the skip path and an uninspectable image warning, plus a main() ordering assertion that the pull precedes the first container; build-rootfs.test.sh asserts the image is re-resolved every build (and that the `image exists` short-circuit is gone, not merely reordered), that a failed pull refuses before exporting, and that SH_SKIP_PULL builds from the local copy but refuses when there is none. Fixes #414 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: cwiklik <[email protected]>
Phase 1 of #368 (VM demo C, epic #370): the parts that don't depend on #366. Closes #362 item 3.
Summary
A raw Anthropic API key now works as a per-user inference credential.
applyModelGatewayalways sent a caller's credential asAuthorization: Bearerand strippedx-api-key. api.anthropic.com reads API keys only fromx-api-key, so ask-ant-api…key got an opaque 401.401 invalid x-api-keyon the Bearer path).bindingnow chooses the header:inference,inferenceAuthHeader(binding, field)accepts exactlyAuthorization: Bearer {f}andx-api-key: {f}.authHeader: 'x-api-key'in direct mode only. Absent means Bearer, the pre-VM demo C: per-user inference credentials and a curl/git research turn in the P6 container sandbox #368 wire shape.turn-auththreads it intoUpstreamCredential.headerand refuses unknown values.applyModelGatewaysends it. The caller's key lives only in per-model headers, never inprocess.env(MI1 §5 R2).Bearer <placeholder>, and the injector picks the upstream header.Shapes that would 401 are refused with a message naming the fix, never mid-turn.
PUT /v1/credentials, the control plane refuses:sk-ant-api…on Bearer;sk-ant-oat…(pi-ai adds the OAuth betas only when the token is its own apiKey);api.anthropic.comendpoint;api.anthropic.comwith a path (/v1would become/v1/v1/messages).credential_requiredis returned for:SH_DEFAULT_INFERENCE_ENDPOINT) is api.anthropic.com;bearer, or an Anthropic API key as kindapi-keywith endpointhttps://api.anthropic.com.ANTHROPIC_API_KEYas kindapi-key.The sandbox image guarantees its research tooling.
curl-minimalandca-certificateswere inherited from ubi-minimal and are now installed explicitly, in bothremote-worker/DockerfileandDockerfile.runtime. No size change: 258.34 MB vs 258.42 MB.HOME=/home/sandbox, created like/workspace. Before this,HOMEwas whatever the runtime picked for a uid with no passwd entry: podman used the WORKDIR, so dotfiles landed in the shared/workspace; Docker and containerd use/, wheregit config --globalfails.Behaviour changes to note
api-key(default bindingX-API-Key) now goes asx-api-keyin direct mode, where it used to go as Bearer. LiteLLM accepts either. A gateway that reads only Bearer needs the credential re-stored as kindbearer.oauth2-tokencredentials and control planes that omitauthHeaderare unchanged.How MI1 S2 absorbs this
inferenceAuthHeaderand the write-time refusals describe the credential, not the delivery mode, so they stay.moca-egress, which injects the real secret under that header.Deferred to phase 2 (after #366 merges)
control-plane.env.example. Possibly also anSH_OPERATOR_INFERENCE_HEADER, because today the fallback is Bearer only.deploy/vmresearch smoke (git clone+curl -o) and its runbook prompt.deploy/vm/README.mdnote on open egress and instance metadata (deploy/vm: sandboxes can reach cloud instance metadata (169.254.169.254) #357).sk-ant-api…key on the VM.Known minors, not fixed here:
https://api.anthropic.com/v1isn't path-checked.Test plan
harness/test/raw-anthropic-key-wire.test.ts: pi-ai's client against a local server. It seesx-api-keyand no Authorization for an x-api-key credential, and Bearer for a gateway token.packages/control-plane/test/inference-shape.test.tspackages/control-plane/test/exchange-auth-header.test.tspackages/knative-server/test/turn-auth-header.test.tscredential-form.test.tsremote-worker/cmd/worker/research_tooling_test.go, mutation-checkedmake lint,make typecheckandmake testare green.podman buildofremote-worker/Dockerfile, then in the running image:HOME=/home/sandbox, even with--workdir /tmp;git config --globalworks as uid 1001 and as an arbitrary gid-0 uid;curl https://example.comreturns 200, andgit cloneworks.🤖 Generated with Claude Code