Repository navigation
feat: Agent-hidden repository secrets via microsandbox placeholder injection (OM-84) - #505
chriswritescode-dev wants to merge 10 commits into
Conversation
| export function buildSandboxModifySecretArgs(name: string, secret: SandboxSecretSpec): string[] { | ||
| return ['modify', name, '--secret', `${secret.envVar}@${secret.allowedHosts.join(',')}`] | ||
| } |
There was a problem hiding this comment.
Unverified modify semantics
The rotation command passes only ENV@hosts. It does not pass the HMAC placeholder or the headers-only substitution setting. If msb's CLI fills in its own placeholder or substitution defaults when the secret is modified, the live config no longer matches sandboxSecretEntryMismatch. Every value rotation would then lead to a VM recreate on the next attestation. In the gap before that, the placeholder the agent holds would not be substituted. The fake msb treats modify as a no-op, so the tests cannot catch this. Check against msb's real modify behavior, or attest right after modify succeeds.
| const sessionHiddenSecrets = this.repoEnvService | ||
| ? (await this.repoEnvService.resolveForDirectory(target.locationDirectory)).hiddenSecrets | ||
| : [] |
There was a problem hiding this comment.
Transient failure recreates VM
resolveForDirectory swallows errors and returns an empty result, so a temporary resolution failure looks the same as "no hidden secrets". The spec then has secrets: [], which changes secretSetKey and forces bootSessionSandbox. Attestation then fails with "network.secrets must be empty", and the VM is removed and recreated, killing the agent's running processes. The next call recreates it again with the secrets restored. Consider separating "resolution failed" from "no secrets", for example by keeping the last known secret set or skipping the reconcile when resolution failed.
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
User description
Follow-up to OM-83. A repository secret can now be marked Hide from agents with a list of allowed hosts, and no agent process gets its real value. Host agent shells get an empty string. Sandboxed agent shells get a random per-VM placeholder, and microsandbox swaps in the real value at the network boundary only for HTTPS requests to the allowed hosts (https://docs.microsandbox.dev/security/secrets). Repository terminals and project actions still get the real value.
What changed
Storage and API
agent_hiddenandallowed_hoststosecrets.SetSecretRequestSchemaacceptsagentHiddenandallowedHosts:*.domainwildcards. Schemes, ports, paths, IPs and single-label wildcards such as*.comare rejected.agentHiddenkeeps the stored flag and hosts. See "For the reviewer".One resolver for every caller
RepoEnvService.resolveForDirectorytakes aHiddenSecretPolicy:withholdis the default and gives an empty value.revealis used by terminals.placeholderis used by the sandbox.Sandbox (
sandbox/command.ts,sandbox/runtime.ts)OCM_SECRET_<NAME>, built from the session's location repository.ocm-secret-plus 32 hex characters of HMAC-SHA256(AUTH_SECRET, VM name + secret name). It looks random, differs per VM, and stays the same across Manager restarts.--secret-conffile holds only a$msb_envreference, and substitution is limited to request headers.msb create.msb create,msb startandmsb modifythrough the child process env.sandboxSecretsMismatch) used to reject anynetwork.secrets. It now requires exactly the expected set and rejects any of these differences: an extra, missing or duplicate entry, an inline value, a wrong env source, a wrong placeholder, a host set that differs or allows any host, query or body substitution, passthrough hosts, orrequire_tls_identity: false.msb modify --secret. If msb refuses, the VM is recreated./.msb/tls/ca.pemis imported into the guest user's NSS db withcertutil, so Chromium and Playwright trust it.Dockerfile.sandboxaddslibnss3-tools.UI
useSetSecretsendsagentHiddenonly when it is defined.Validation
Handback validation
e273a6be-b7c1-4326-b82f-2142a1026877passed onc1b8220bplus four review-fix commits (d6e5ef0b,8f23959a,f0efe260,94d38226).The production build ran against OpenCode 2.4.2 and was driven in Playwright on desktop (1280×720) and mobile (iPhone 13). All 10 checks passed in both views:
Bearer ${{secrets.X}}becomesBearer.pnpm lint,pnpm typecheckandpnpm testpass (backend 223 files, frontend 4143 tests). The 14 Bun internal-sandbox tests also pass.check_designconforms.The axe-core audit found no new accessibility violations.
pr-agent ran 5 review rounds. Its fixes were:
*.<tld>wildcards are rejected.AUTH_SECRET.The remaining findings were declined as owner decisions: recreating the VM on a refused modify, terminals getting the real value, values passed by host-env reference, and dropping the hidden set when
.ocm/project.jsonis untrusted.For the reviewer
/dev/kvm. Placeholder injection in the guest, the--secret-confcreate, attestation against the realmsb inspectshape,msb modifyrotation and the NSS CA import are covered only by the mocked-msb unit tests. The post-merge KVM check from the plan still applies, after theDockerfile.sandboximage is republished withlibnss3-tools. It should also confirm that the msb host process environment does not leakOCM_SECRET_*.agentHiddenclears the flag. The API instead keeps the stored flag and hosts when the field is omitted, so a script that only rotates a value cannot un-hide a secret by accident. The UI always sends the flag. Confirm keep-on-omit as the contract, or ask for the plan's behavior.AUTH_SECRETis required. Placeholders are derived from it. Rotating it changes every placeholder, which recreates each VM that has hidden secrets once.space-y-1). On mobile it reads as part of the hint.space-y-3would separate them.Agent documents
PR Type
Enhancement, Tests
Description
Add agent-hidden secret storage and validation
agent_hiddenandallowed_hostsResolve hidden secrets per caller policy
Inject secrets into microsandbox VMs
--secret-conf, header-only substitutionmodify, trust interception CAAdd UI controls and comprehensive tests
Diagram Walkthrough
File Walkthrough
10 files
Add hidden secret and allowed-host validation schemasPersist hidden flags and expose hidden bindingsResolve hidden secrets differently per caller policyBuild secret conf, placeholders, and attestation checksInject, sync, and attest sandbox VM secretsForward hidden options through the secret PUT routeReveal hidden secret values to local terminalsAddagent_hiddenandallowed_hostscolumnsAdd hide-from-agents controls and badgesBuild secret requests with hidden fields1 files
Register the secrets agent-hidden migration1 files
Installlibnss3-toolsfor CA trust8 files
Test hidden secret persistence and scoped resolutionTest withhold, reveal, and placeholder policiesTest secret conf, placeholders, and attestationTest sandbox secret creation, rotation, and recreationTest hidden secret API validation and preservationEmulate microsandbox secret storage and modifyTest hidden secret form and list renderingTest migration defaults and idempotent column adds7 files