feat: bind direct accounts and hash effective launch policy
16 files changed,
+4,331
−26
docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md+2,092 −0internal/release/manifest.go+11 −0internal/runner/config.go+10 −0internal/runner/config_test.go+26 −0internal/runner/connections.go+80 −8internal/runner/connections_test.go+43 −0internal/runner/containment/egress.go+5 −2internal/runner/containment/egress_test.go+21 −0internal/runner/containment/linux.go+88 −8internal/runner/containment/linux_test.go+43 −0internal/runner/containment/recovery.go+1 −1internal/runner/provider/accounts.go+566 −0internal/runner/provider/accounts_test.go+433 −0internal/runner/provider/policy.go+584 −0internal/runner/provider/policy_test.go+312 −0internal/runner/provider/types.go+16 −7
CI passed — run details
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md| index a4f4d1b2..a57b4546 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| @@ -4351,3 +4351,2095 @@ No new user-facing strings, protocol responses, diagnostics or `copy.go` entries |
| No new concerns or failing gates. Provider certification remains the existing Task 11b release gate. Tests closed their listeners, stopped their namespace processes and removed their owned TMPDIR trees. No separate scratch, background server or credential home was created. No push, merge, deployment or other worktree access occurred. The controller owns review and push. |
| The final fixture reads the response through EOF so a split TCP read cannot cause a false failure. After that test-only adjustment, `CGO_ENABLED=0 go test /home/paulca/amadan.net/oficina/equipo-plan-2b/internal/runner/containment -run '^TestEgressLongScratchRoot$' -count=1` passed (`ok amadan.net/oficina/equipo/internal/runner/containment 0.061s`), and `git diff --check` remained clean. |
| + |
| + |
| +## Task 4: Bind direct accounts and hash effective launch policy |
| + |
| +Status: DONE_WITH_CONCERNS. |
| +Commit subject: `feat: bind direct accounts and hash effective launch policy`. |
| +Branch: `plan-2b`. No push, merge, deployment, provider prompt, sign-in or enrolment. |
| + |
| +### What changed |
| + |
| +`provider.OpenAccount` opens only the configured dedicated source home. The lease pins the directory with openat2, holds a directory flock across attempts and refresh, requires private modes and complete expected identity metadata, and stages only the selected provider's login plus identity metadata into a private runtime home. Files are 0600 and directories are 0700. No credential material is put into a workspace, public manifest or journal. |
| + |
| +`HomeRules` makes refusals explicit. The production default covers the user's `.claude` and `.codex`; the path rule covers every `.paseo/zerosub/homes` tree. Path checks precede login access. Symlink components are refused, directory inode comparisons catch explicit interactive-home aliases and their descendants, and mountinfo root checks catch bind aliases of forbidden trees. Tests inject only owned fake directories. The real defaults receive a path-only test. No real login file was read, copied or statted, and no real interactive credential home was accessed by these tests. |
| + |
| +Only a live lease can return a binding with dedicated-home authority. The exported boolean is omitted from JSON and is insufficient on its own: `VerifiedDedicatedHome` checks an unexported lease reference, the exact binding and the pinned source. Both containment and its egress boundary reject forged provenance. Configured bindings, connection data and JSON input cannot grant auth-host access. Auth hosts still require Task 3's installed network contract; this task installs none. |
| + |
| +`Preflight` compares CLI-observed identity with the enrolled binding. `Validate`, `BeginTurn` and `EndTurn` detect source replacement, identity changes and credential generation changes. The private generation includes file identity and timestamps, so atomic replacement with identical bytes still requires preflight. A same-identity generation between turns returns `ErrPreflightRequired`; successful preflight restages and validates that login before another bind/turn. Failed refresh remains unavailable for dispatch without choosing another account. A different identity returns `ErrIdentity`; an unexplained active-turn change returns `ErrContainment`. `CommitRefresh` checks the staged login's observed identity, then atomically writes and fsyncs only the dedicated login under the same lease. It leaves preflight required. Private token digests stay in memory and never enter the public tuple. |
| + |
| +Claude identity is trust-on-first-use: Paul confirms the CLI-observed account metadata at enrolment, and future observations must match that binding. This is not independent remote attestation. |
| + |
| +`BuildPolicy` constructs its environment rather than inheriting it. Only the selected provider paths and permitted locale/terminal entries reach Policy.Env. The manifest additionally records containment's fixed PATH, HOME, TMPDIR and proxy variables. Injected API/routing/proxy/socket/parent-agent variables are rejected. Generated JSON settings and MCP artifacts use fixed namespace paths `/config/equipo-settings.json` and `/config/equipo-mcp.json`. |
| + |
| +The canonical manifest covers exact argv, nonsecret environment, runtime-file contents and mount targets, selected source home and expected identity, denied paths, exact egress hosts, exact tool lists, settings, MCP, start/resume thread policy, turn policy, outer mounts, shared namespace arguments, disabled hooks/plugins, managed-directory masking and explicit omission of per-turn authority overrides. Duplicate JSON keys and secret-bearing settings keys are rejected. Turn policy admits only non-authority effort/summary parameters; supplied authority or unknown fields are rejected. Instruction files have a separate hash and affect the concrete manifest, not the isolation policy. Only validated workspace, scratch and generated runtime-home roles are normalized for certification; the dedicated source home and other runtime/protected inputs stay exact. |
| + |
| +Runtime-file imports also refuse credential filenames, forbidden interactive sources and inode aliases. An auth.json or hardlink to it cannot become a public file digest. Executables with multiple hardlinks are conservatively refused by this file-import check. |
| + |
| +`ValidateReadback` requires the exact effective settings/MCP/thread/turn policy, disabled hooks/plugins, no remote control, and only Equipo's generated layer plus any explicitly mounted managed layers. Unsupported/ignored provider settings still need provider-specific normalization and sentinel certification in Tasks 5, 6 and 11b. |
| + |
| +`AttestLaunch` checks the lease, concrete policy, argv, selection, current runtime-file digests, generated config, environment and mounts. Containment then hashes its actual constructed namespace arguments, pinned regular-file digests and concrete scratch/socket paths. The durable containment record now stores separate `PolicyHash`, concrete `ManifestHash` and `EgressHash`. A runtime source changed between BuildPolicy and mount pinning fails its digest check. The actual host launcher and bubblewrap binaries must appear in the direct policy's RuntimeFiles. The attempt lifetime context contract is documented on `provider.ProcessHost`. |
| + |
| +`AccountBinding` adds ProviderHome, ExpectedIdentity and PersonID. `DiscoverDirect` reads only these configured bindings, opens a lease and runs a no-prompt identity probe. Duplicate LocalID/model matches and inconsistent person/account associations fail closed. Input model order, LocalID and person association are preserved. Legacy discovery remains available for the later cutover. Release metadata gains typed direct-policy certificates without manufacturing a certification entry. |
| + |
| +### Files |
| + |
| +- `internal/runner/provider/accounts.go`, `accounts_test.go`: account leases, explicit refusals, private staging, identity/generation checks and refresh. |
| +- `internal/runner/provider/policy.go`, `policy_test.go`: canonical policy/attempt manifests, generated config, readback, launch and pinned-file validation. |
| +- `internal/runner/provider/types.go`: expected identity, runtime/source binding fields, unexported provenance, separate hashes and attempt-context documentation. |
| +- `internal/runner/config.go`, `config_test.go`: configured direct binding and private runtime-root checks. |
| +- `internal/runner/connections.go`, `connections_test.go`: direct configured discovery and association/order checks. |
| +- `internal/runner/containment/egress.go`, `egress_test.go`: verified dedicated-home authority and exact network binding. |
| +- `internal/runner/containment/linux.go`, `linux_test.go`, `recovery.go`: final constructed namespace hash, pinned-file checks, separate persisted policy hash and regression tests. |
| +- `internal/release/manifest.go`: direct policy certificate type and manifest field. |
| +- This appended controller report and the requested ignored local task report. |
| + |
| +### Adapter integration and interpretations |
| + |
| +1. Input Binding.Home is the dedicated credential source. Input Binding.Expected must contain AccountID, HomeID and ProviderVersion, and RuntimeRoot must be the runner's private `<scratch>/homes`. The source must already exist with `equipo-identity.json` and the provider's login file: `.credentials.json` for Claude or `auth.json` for Codex. OpenAccount never creates a dedicated source or signs in. Use `lease.Binding()` afterward: Home is then the private runtime home and CredentialHome retains the exact dedicated source. |
| +2. BuildPolicy preserves every requested PolicyInputs field and adds Argv, Env, Workspace, Scratch and InstructionFiles. Concrete argv and attempt paths are necessary to attest the constructed launch and cannot be inferred from the original field list. Supply all executable/helper/MCP/managed runtime files, including the actual runner and bubblewrap binaries, as read-only RuntimeFiles. The primary argv executable must be one of those targets. Env permits only LANG, LC_ALL and TERM overrides. BuildPolicy may run during the no-prompt preflight callback; prompt admission remains blocked until that callback succeeds. |
| +3. The raw ThreadPolicy object must contain the exact canonical start and resume policy parameters. Both are hashed verbatim after JSON canonicalization. TurnPolicy is policy-only, not prompts, thread IDs or general RPC data. It pins the omission of authority overrides. Adapters must use the returned settings and hashes, inspect account/read and config/read(includeLayers:true) for Codex, and normalize actual provider readback into ConfigReadback. Provider-specific native configuration rendering belongs to Tasks 5 and 6; the generic builder stages the attested JSON artifacts at fixed namespace paths. |
| +4. Keep the lease throughout the session's attempts and refresh. Before each turn/resume, validate identity/generation, inspect effective provider policy and re-attest the launch; use BeginTurn/EndTurn around the active interval. After ErrPreflightRequired, re-run Preflight and bind the validated configuration before the next prompt. To accept a harness login refresh, call CommitRefresh with a no-prompt identity probe, then fresh Preflight. Callback probes run without the lease mutex so they can build policy and launch status checks, while another check or turn cannot start. |
| +5. Runtime homes are lease-owned and Close removes them. Provider adapters and Task 7 must retain their durable session/capture records and keep the lease for any resume that needs the current private session files. Cross-lease session restoration is not implemented by this account/policy layer. |
| +6. Masked managed directories remain Task 2's private /etc overlays. An explicitly required managed file must be listed in RuntimeFiles and its readback layer must be `managed:<exact namespace target>`. Unlisted user/project/managed layers are rejected rather than silently overriding operator requirements. |
| +7. The final containment hash required small edits beyond the brief's principal file list. Without them, Task 3's boolean still granted authority and Task 2's ManifestHash still held only the reusable policy hash. These edits keep existing disconnected/check-launch fixtures working while enforcing the new manifest on dedicated direct launches. Legacy discovery and old launch contracts are not a direct-provider rollout; Task 11a still owns cutover/removal. |
| +8. The task's explicit rules override generic copy-review, writing delegation and handoff workflows. No copy-review skill/server, subagent, live model call or .claude/HANDOFF.md was used. The local report is ignored under .superpowers; the complete evidence is committed here. |
| + |
| +### RED evidence |
| + |
| +All commands below ran from `/home/paulca/amadan.net/oficina/equipo-plan-2b` on branch `plan-2b`, with `CGO_ENABLED=0`, on-disk TMPDIR `/home/paulca/t/e2b` and default Go caches. |
| + |
| +Initial tests were written before implementation. The first meaningful RED was: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner -run 'TestAccountHome|TestAccountUnavailable|TestEffectivePolicy|TestUnexpectedConfig|TestPrivateHome' -count=1 |
| +``` |
| + |
| +```text |
| +undefined: HomeRules |
| +unknown field Expected in struct literal of type Binding |
| +unknown field RuntimeRoot in struct literal of type Binding |
| +undefined: IdentityFile |
| +undefined: AccountLease |
| +undefined: PolicyInputs |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider [build failed] |
| +ok amadan.net/oficina/equipo/internal/runner [no tests to run] |
| +``` |
| + |
| +An earlier test-file brace typo was corrected before this run; that parser error is not claimed as behavioral evidence. Supplemental tests for refresh, launch attestation and configured discovery similarly failed to compile before their APIs existed. An intermediate configured-discovery failure (`runner.invalid`) exposed missing JSON tags on Identity; the tags were added and both legacy and direct binding tests now pass. |
| + |
| +The behavioral RED commands were: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run 'TestEgressRejectsForgedDedicatedHome|TestNamespaceConcreteManifestHash' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestEgressRejectsForgedDedicatedHome |
| + caller boolean granted dedicated-home authority |
| +--- FAIL: TestNamespaceConcreteManifestHash |
| + policy hash substituted for concrete manifest hash |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner -run 'TestUnexpectedConfigInputs|TestEffectivePolicyPreflightLaunch|TestAccountHomeConfiguredRuntime' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigInputs/missing_binary |
| + unsafe policy input accepted |
| +--- FAIL: TestUnexpectedConfigInputs/network_number |
| + unsafe policy input accepted |
| +--- FAIL: TestEffectivePolicyPreflightLaunch |
| + preflight could not launch status check provider_identity_mismatch |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/containment -run 'TestEffectivePolicyHostBinary|TestNamespaceManifestInputs' -count=1 |
| +``` |
| + |
| +```text |
| +p.ValidateRuntimeBinaries undefined |
| +m.namespaceManifest undefined |
| +FAIL [build failed] |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyManifestBoundary$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyManifestBoundary |
| + outer mount policy missing from manifest |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run 'TestAccountHomeRuntimeAliasNoSideEffects|TestAccountHomeFileGuards' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestAccountHomeRuntimeAliasNoSideEffects |
| + interactive directory changed <nil> |
| +--- FAIL: TestAccountHomeFileGuards/metadata_duplicate |
| + unsafe account input accepted |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestPrivateHomeRejectsCredentialMount$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestPrivateHomeRejectsCredentialMount |
| + credential source entered public manifest |
| +``` |
| + |
| +After guarding the credential path, the same command exposed the inode alias: |
| + |
| +```text |
| +--- FAIL: TestPrivateHomeRejectsCredentialMount |
| + credential inode alias entered public manifest |
| +``` |
| + |
| +### GREEN evidence |
| + |
| +Final exact brief command, after all fixes and restoration of every mutation: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner -run 'TestAccountHome|TestAccountUnavailable|TestEffectivePolicy|TestUnexpectedConfig|TestPrivateHome' -count=1 |
| +``` |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider 3.560s |
| +ok amadan.net/oficina/equipo/internal/runner 0.005s |
| +``` |
| + |
| +Related regression command after the account, policy and containment fixes: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner ./internal/runner/containment ./internal/release -run 'TestAccountHome|TestAccountUnavailable|TestEffectivePolicy|TestUnexpectedConfig|TestPrivateHome|TestDirect|TestConnectionsBindings|TestRunnerConfig|TestEgress|TestNamespaceConcreteManifestHash|TestNamespaceManifestInputs' -count=1 |
| +``` |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider 3.674s |
| +ok amadan.net/oficina/equipo/internal/runner 0.012s |
| +ok amadan.net/oficina/equipo/internal/runner/containment 0.737s |
| +? amadan.net/oficina/equipo/internal/release [no test files] |
| +``` |
| + |
| +A final schema test was added before supplying the direct certificate's snake_case JSON tags: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run '^TestEffectivePolicyReleaseManifest$' -count=1 |
| +``` |
| + |
| +RED (exit 1): |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyReleaseManifest |
| + missing manifest field provider |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.003s |
| +``` |
| + |
| +GREEN after adding the tags (exit 0): |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner 0.003s |
| +``` |
| + |
| +`git diff --check` passed. gofmt reported no pending formatting for the new files; all changed Go files were formatted. No full suite, make ci, race suite, network provider test or live gate ran. |
| + |
| +### Mutation evidence |
| + |
| +60 distinct guards/manifest inputs have a compiled, named failing test. Every mutation was applied alone and restored from the exact saved source before the next mutation. The scratch driver was run as `python3 /home/paulca/t/e2b/task4-mutations/run.py`, with corrected/supplemental cases in `rerun.py`; the two credential-import cases used the same save/mutate/run/restore sequence. Scratch drivers and logs are removed after copying their evidence here. |
| + |
| +Five initial mutations were not evidence: active classification changed the wrong duplicate branch, readiness was masked by the earlier generation check, the mount fixture also changed argv, and the malformed manifest hit another identity check. Those four initially passed; tests/targets were tightened. The fifth, ignored-settings comparison, left unused locals and did not compile; the corrected mutation explicitly uses `_ = a` and `_ = b`. All five were rerun and produced the named compiled failures below. No compile failure is counted as a successful mutation. |
| + |
| +#### Mutation 1: home replacement |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace the body of `func (l *AccountLease) sourceUnchanged() bool` with: |
| + |
| +```go |
| +return true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/replacement$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.05s) |
| + --- FAIL: TestAccountHomeMutation/replacement (0.04s) |
| + accounts_test.go:182: replacement accepted: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 45ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.047s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 2: directory lock |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +e = unix.Flock(int(dir.Fd()), unix.LOCK_EX|unix.LOCK_NB) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +e = error(nil) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/lock$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.04s) |
| + --- FAIL: TestAccountHomeMutation/lock (0.04s) |
| + accounts_test.go:192: concurrent lease accepted: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 43ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.045s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 3: dedicated provenance |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace the body of `func (b Binding) VerifiedDedicatedHome() bool` with: |
| + |
| +```go |
| +return b.DedicatedHome |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeBinding/dedicated_provenance$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeBinding (0.00s) |
| + --- FAIL: TestAccountHomeBinding/dedicated_provenance (0.00s) |
| + accounts_test.go:57: input boolean granted authority |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 4: shared inode |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace the body of `func (r HomeRules) refusedInode(info os.FileInfo) bool` with: |
| + |
| +```go |
| +return false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeBinding/shared_and_aliases$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeBinding (0.00s) |
| + --- FAIL: TestAccountHomeBinding/shared_and_aliases (0.00s) |
| + accounts_test.go:126: shared inode accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 5: default path refusals |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace the body of `func (r HomeRules) RefusesPath(path string) bool` with: |
| + |
| +```go |
| +return false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeBinding/real_defaults_path_only$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeBinding (0.00s) |
| + --- FAIL: TestAccountHomeBinding/real_defaults_path_only (0.00s) |
| + accounts_test.go:133: default shared home accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 6: credential file mode |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || info.Mode().Perm() != 0600 |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeBinding/private_modes$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeBinding (0.02s) |
| + --- FAIL: TestAccountHomeBinding/private_modes (0.02s) |
| + accounts_test.go:145: public credentials accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 22ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.023s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 7: identity recheck |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || id != l.source.Expected |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/identity_change$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.04s) |
| + --- FAIL: TestAccountHomeMutation/identity_change (0.04s) |
| + accounts_test.go:222: got provider_preflight_required want provider_identity_mismatch |
| +FAIL |
| +rastrillo-budget/v1 ran 42ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.044s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 8: generation recheck |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if generation != l.generation { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && generation != l.generation { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/successful_refresh$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.05s) |
| + --- FAIL: TestAccountHomeMutation/successful_refresh (0.05s) |
| + accounts_test.go:222: got <nil> want provider_preflight_required |
| +FAIL |
| +rastrillo-budget/v1 ran 47ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.049s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 9: active mutation classification |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if generation != l.generation { |
| + l.ready = false |
| + if l.active { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if generation != l.generation { |
| + l.ready = false |
| + if false && l.active { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/active_change$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.04s) |
| + --- FAIL: TestAccountHomeMutation/active_change (0.04s) |
| + accounts_test.go:223: got provider_preflight_required want provider_account_containment |
| +FAIL |
| +rastrillo-budget/v1 ran 44ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.045s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 10: runtime credential recheck |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if runtimeErr != nil || sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && (runtimeErr != nil || sha256.Sum256(runtimeRaw) != l.runtimeGeneration) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeRuntimeGuards/runtime_active_mutation$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeRuntimeGuards (0.04s) |
| + --- FAIL: TestAccountHomeRuntimeGuards/runtime_active_mutation (0.04s) |
| + accounts_test.go:311: active runtime mutation accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 43ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.044s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 11: preflight readiness |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if !l.ready { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !l.ready { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountUnavailableDoesNotFailover$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountUnavailableDoesNotFailover (0.18s) |
| + --- FAIL: TestAccountUnavailableDoesNotFailover/provider_account_maintenance (0.06s) |
| + accounts_test.go:170: calls=1 prompts=1 |
| + --- FAIL: TestAccountUnavailableDoesNotFailover/provider_identity_mismatch (0.06s) |
| + accounts_test.go:170: calls=1 prompts=1 |
| + --- FAIL: TestAccountUnavailableDoesNotFailover/quota (0.06s) |
| + accounts_test.go:170: calls=1 prompts=1 |
| +FAIL |
| +rastrillo-budget/v1 ran 185ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.186s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 12: preflight failure |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if probeErr != nil { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && probeErr != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeMutation/failed_refresh$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeMutation (0.06s) |
| + --- FAIL: TestAccountHomeMutation/failed_refresh (0.06s) |
| + accounts_test.go:236: provider_identity_mismatch |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.064s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 13: runtime symlink |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +e == nil && stat.Mode&unix.S_IFMT != unix.S_IFREG |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +false && e == nil && stat.Mode&unix.S_IFMT != unix.S_IFREG |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeRuntimeGuards/runtime_symlink$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeRuntimeGuards (0.06s) |
| + --- FAIL: TestAccountHomeRuntimeGuards/runtime_symlink (0.06s) |
| + accounts_test.go:291: runtime symlink accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 64ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 14: safe environment |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +(k != "LANG" && k != "LC_ALL" && k != "TERM") |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/ANTHROPIC_API_KEY$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.10s) |
| + --- FAIL: TestUnexpectedConfigLayer/ANTHROPIC_API_KEY (0.04s) |
| + policy_test.go:159: injected environment accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 104ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.105s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 15: readback layers |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || !reflect.DeepEqual(actual, layers) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/user$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.06s) |
| + --- FAIL: TestUnexpectedConfigLayer/user (0.00s) |
| + policy_test.go:145: unexpected config accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 64ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.066s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 16: remote control |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +r.RemoteControl || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/remote$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.06s) |
| + --- FAIL: TestUnexpectedConfigLayer/remote (0.00s) |
| + policy_test.go:145: unexpected config accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 64ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 17: disabled hooks |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +!r.HooksDisabled || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/hooks$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.06s) |
| + --- FAIL: TestUnexpectedConfigLayer/hooks (0.00s) |
| + policy_test.go:145: unexpected config accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 18: disabled plugins |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +!r.PluginsDisabled || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/plugins$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.06s) |
| + --- FAIL: TestUnexpectedConfigLayer/plugins (0.00s) |
| + policy_test.go:145: unexpected config accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 64ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 19: ignored settings |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if e != nil || !bytes.Equal(a, b) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = a |
| + _ = b |
| + if e != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer/ignored$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.06s) |
| + --- FAIL: TestUnexpectedConfigLayer/ignored (0.00s) |
| + policy_test.go:146: unexpected config accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 64ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.066s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 20: per-turn overrides |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace the body of `func validTurnPolicy(raw json.RawMessage) bool` with: |
| + |
| +```go |
| +return true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.22s) |
| + policy_test.go:167: turn override sandboxPolicy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 224ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.225s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 21: unverified policy binding |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if !b.VerifiedDedicatedHome() { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if b.provenance == nil { return Policy{}, nil }; if !b.VerifiedDedicatedHome() { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestUnexpectedConfigLayer$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestUnexpectedConfigLayer (0.20s) |
| + policy_test.go:173: unverified binding accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 202ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.204s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 22: hash binary |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Files=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/binary$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/binary (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 23: hash settings |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Settings=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/settings$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/settings (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 82ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.083s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 24: hash routing |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.EgressHosts=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/routing$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/routing (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 25: hash tools |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Tools=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/tools$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/tools (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 82ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.084s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 26: hash mcp |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.MCP=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/mcp$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.09s) |
| + --- FAIL: TestEffectivePolicyHash/mcp (0.09s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 87ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.089s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 27: hash managed |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Files=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/managed$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/managed (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 28: hash env |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Env=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/env$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/env (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 85ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.086s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 29: hash mount |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Files=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/mount$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/mount (0.08s) |
| + policy_test.go:77: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 85ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.087s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 30: hash thread-start |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.ThreadPolicy=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/thread-start$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/thread-start (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.084s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 31: hash thread-resume |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.ThreadPolicy=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/thread-resume$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/thread-resume (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 82ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.083s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 32: hash turn |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.TurnPolicy=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/turn$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/turn (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.084s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 33: hash provider-version |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.ProviderVersion="" |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/provider-version$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/provider-version (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 34: hash launcher-version |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.LauncherVersion="" |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/launcher-version$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/launcher-version (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 35: hash bwrap-version |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.BwrapVersion="" |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/bwrap-version$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.08s) |
| + --- FAIL: TestEffectivePolicyHash/bwrap-version (0.08s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 83ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.085s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 36: hash argv |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Argv=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/argv$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.09s) |
| + --- FAIL: TestEffectivePolicyHash/argv (0.09s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 86ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.088s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 37: hash denied |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.DeniedPaths=nil |
| + raw, manifestHash, e := hashJSON(m) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/denied$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.09s) |
| + --- FAIL: TestEffectivePolicyHash/denied (0.09s) |
| + policy_test.go:76: manifest change not hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 88ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.090s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 38: workspace role |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +m.Workspace = "$WORKSPACE" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +m.Workspace = m.Workspace |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/canonical_and_concrete$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.11s) |
| + --- FAIL: TestEffectivePolicyHash/canonical_and_concrete (0.11s) |
| + policy_test.go:92: workspace role or concrete hash wrong |
| +FAIL |
| +rastrillo-budget/v1 ran 110ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.112s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 39: instruction digest |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +_, instructionHash, _ := hashJSON(instructions) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +instructionHash := "constant" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHash/instructions_separate$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHash (0.09s) |
| + --- FAIL: TestEffectivePolicyHash/instructions_separate (0.09s) |
| + policy_test.go:116: instructions not separately hashed |
| +FAIL |
| +rastrillo-budget/v1 ran 89ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.090s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 40: launch arguments |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || !reflect.DeepEqual(m.Argv, argv) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation/argv$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.07s) |
| + --- FAIL: TestEffectivePolicyLaunchAttestation/argv (0.00s) |
| + policy_test.go:209: changed launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 68ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.070s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 41: launch env |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if !reflect.DeepEqual(expectedEnv, p.Env) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !reflect.DeepEqual(expectedEnv, p.Env) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation/env$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.07s) |
| + --- FAIL: TestEffectivePolicyLaunchAttestation/env (0.00s) |
| + policy_test.go:209: changed launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 66ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.068s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 42: launch mounts |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if !reflect.DeepEqual(expectedMounts, p.Mounts) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !reflect.DeepEqual(expectedMounts, p.Mounts) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation/mount$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.07s) |
| + --- FAIL: TestEffectivePolicyLaunchAttestation/mount (0.00s) |
| + policy_test.go:209: changed launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 67ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.069s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 43: manifest integrity |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if digest(p.Manifest) != p.ManifestHash { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && digest(p.Manifest) != p.ManifestHash { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation/manifesthash$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.06s) |
| + --- FAIL: TestEffectivePolicyLaunchAttestation/manifesthash (0.00s) |
| + policy_test.go:212: changed launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.064s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 44: policy hash integrity |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if policyHash != p.Hash { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && policyHash != p.Hash { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation/policyhash$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.06s) |
| + --- FAIL: TestEffectivePolicyLaunchAttestation/policyhash (0.00s) |
| + policy_test.go:209: changed launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 62ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.064s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 45: network binding |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace the body of `func (p Policy) ValidateNetwork(name string, hosts []string) error` with: |
| + |
| +```go |
| +return nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyLaunchAttestation$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyLaunchAttestation (0.06s) |
| + policy_test.go:214: egress drift accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 46: host binary inclusion |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace the body of `func (p Policy) ValidateRuntimeBinaries(paths ...string) error` with: |
| + |
| +```go |
| +return nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyHostBinary$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyHostBinary (0.06s) |
| + policy_test.go:272: unhashed host binary accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 47: pinned digest |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace the body of `func (p Policy) ValidateFileDigest(path, hash string) error` with: |
| + |
| +```go |
| +return nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestEffectivePolicyManifestBoundary$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyManifestBoundary (0.06s) |
| + policy_test.go:285: changed pinned file digest accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 63ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.065s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 48: duplicate binding |
| + |
| +File: `internal/runner/connections.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || seen[key] |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run ^TestAccountHomeConfiguredDiscovery$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeConfiguredDiscovery (0.00s) |
| + connections_test.go:133: second matching binding accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 2ms |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.004s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 49: runtime config path |
| + |
| +File: `internal/runner/config.go`. |
| + |
| +Replace the body of `func (c Config) DirectBinding(b AccountBinding) (provider.Binding, error)` with: |
| + |
| +```go |
| +return provider.Binding{Home:b.ProviderHome,Expected:b.ExpectedIdentity},nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run ^TestAccountHomeConfiguredRuntime$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeConfiguredRuntime (0.00s) |
| + config_test.go:146: unsafe runtime root accepted: / |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 50: egress provenance |
| + |
| +File: `internal/runner/containment/egress.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if l.Binding.DedicatedHome && !l.Binding.VerifiedDedicatedHome() { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && l.Binding.DedicatedHome && !l.Binding.VerifiedDedicatedHome() { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestEgressRejectsForgedDedicatedHome$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEgressRejectsForgedDedicatedHome (0.00s) |
| + egress_test.go:329: egress accepted forged provenance |
| +FAIL |
| +rastrillo-budget/v1 ran 2ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.003s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 51: persist concrete hash |
| + |
| +File: `internal/runner/containment/linux.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +ManifestHash: manifestHash, |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +ManifestHash: l.Policy.Hash, |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestNamespaceConcreteManifestHash$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceConcreteManifestHash (0.05s) |
| + linux_test.go:647: policy hash substituted for concrete manifest hash |
| +FAIL |
| +rastrillo-budget/v1 ran 47ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.048s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 52: directory mode |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace the body of `func privateDirectory(f *os.File) bool` with: |
| + |
| +```go |
| +return true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeFileGuards/directory_mode$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeFileGuards (0.02s) |
| + --- FAIL: TestAccountHomeFileGuards/directory_mode (0.02s) |
| + accounts_test.go:380: unsafe account input accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 23ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.024s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 53: credential hardlink |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || st.Nlink != 1 |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeFileGuards/credential_hardlink$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeFileGuards (0.02s) |
| + --- FAIL: TestAccountHomeFileGuards/credential_hardlink (0.02s) |
| + accounts_test.go:380: unsafe account input accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 23ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.025s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 54: duplicate metadata |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +metadata, e = canonical(metadata) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +metadata, e = metadata,nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeFileGuards/metadata_duplicate$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeFileGuards (0.02s) |
| + --- FAIL: TestAccountHomeFileGuards/metadata_duplicate (0.02s) |
| + accounts_test.go:380: unsafe account input accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 22ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.024s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 55: controlled generation |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +digest := sha256.Sum256(bytes.Join([][]byte{metadata, raw, state}, nil)) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = state |
| + digest := sha256.Sum256(bytes.Join([][]byte{metadata, raw}, nil)) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeRuntimeGuards/same_bytes_new_generation$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeRuntimeGuards (0.04s) |
| + --- FAIL: TestAccountHomeRuntimeGuards/same_bytes_new_generation (0.04s) |
| + accounts_test.go:302: atomic generation not detected |
| +FAIL |
| +rastrillo-budget/v1 ran 43ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.044s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 56: observed identity |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if id != l.source.Expected { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && id != l.source.Expected { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomePreflightGuards/observed_identity$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomePreflightGuards (0.04s) |
| + --- FAIL: TestAccountHomePreflightGuards/observed_identity (0.04s) |
| + accounts_test.go:393: wrong CLI identity accepted <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 43ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.044s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 57: probe stable generation |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if before != after { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && before != after { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomePreflightGuards/generation_during_probe$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomePreflightGuards (0.04s) |
| + --- FAIL: TestAccountHomePreflightGuards/generation_during_probe (0.04s) |
| + accounts_test.go:403: unstable probe accepted <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 43ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.044s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 58: runtime no side effects |
| + |
| +File: `internal/runner/provider/accounts.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +root, e := makePrivateRoot(b.RuntimeRoot) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = os.MkdirAll(b.RuntimeRoot,0700) |
| + root, e := makePrivateRoot(b.RuntimeRoot) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestAccountHomeRuntimeAliasNoSideEffects$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeRuntimeAliasNoSideEffects (0.00s) |
| + accounts_test.go:356: interactive directory changed <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 59: credential source import |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| +if credentialSource(m.Source, b) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && credentialSource(m.Source, b) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestPrivateHomeRejectsCredentialMount$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestPrivateHomeRejectsCredentialMount (0.07s) |
| + policy_test.go:302: credential source entered public manifest |
| +FAIL |
| +rastrillo-budget/v1 ran 67ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.069s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 60: credential inode import |
| + |
| +File: `internal/runner/provider/policy.go`. |
| + |
| +Replace: |
| + |
| +```go |
| + || stat.Nlink != 1 |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run ^TestPrivateHomeRejectsCredentialMount$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestPrivateHomeRejectsCredentialMount (0.07s) |
| + policy_test.go:310: credential inode alias entered public manifest |
| +FAIL |
| +rastrillo-budget/v1 ran 69ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.071s |
| +FAIL |
| +``` |
| + |
| +### User-facing strings |
| + |
| +No UI or prose runtime strings were added, and copy.go is unchanged. New internal error codes are `provider_account_busy`, `provider_account_maintenance`, `provider_preflight_required`, `provider_account_containment` and `provider_policy_rejected`. Existing `provider_identity_mismatch` is reused. If later adapters expose these states to people, their copy.go entries need individual pending markers and the release copy pass. Tests and this controller report contain explanatory text only. |
| + |
| +### Concerns and remaining integration |
| + |
| +- No real dedicated homes exist yet. Enrolment must create them and record Paul-confirmed expected identity. No production credential provenance or live refresh was certified here. |
| +- Tasks 5 and 6 must use the lease admission/readback checks for every turn and resume, include their exact binary/helper/tool/MCP/RPC inputs and render native provider configuration. Task 7 owns durable capture and any cross-lease session restoration. Task 11a owns removal of legacy discovery and launch paths. |
| +- Full sandbox/sentinel certification and an installed, certified provider auth hostname remain Task 11b release gates. DirectPolicies remains empty in the embedded release manifest. |
| +- Refusal tests cover injected fake paths, symlink aliases and inode identity. No privileged host bind mount was created. The production mountinfo alias rule is exercised without touching real shared credential homes. |
| + |
| +All source changes are restored after mutations. Tests use owned temporary files only. No server, watcher, background provider, model process or review agent remains. No README, other worktree, default branch or production configuration was changed. |
diff --git a/internal/release/manifest.go b/internal/release/manifest.go| index 66179e66..544fb19a 100644 |
| --- a/internal/release/manifest.go |
| +++ b/internal/release/manifest.go |
| @@ -9,7 +9,18 @@ import ( |
| //go:embed manifest.json |
| var manifest string |
| +// PolicyCertificate certifies a constructed direct policy. No account tokens, |
| +// token hashes or per-attempt paths belong in release metadata. |
| +type PolicyCertificate struct { |
| + Provider string `json:"provider"` |
| + ProviderVersion string `json:"provider_version"` |
| + LauncherVersion string `json:"launcher_version"` |
| + BwrapVersion string `json:"bwrap_version"` |
| + PolicyHash string `json:"policy_hash"` |
| +} |
| + |
| type Manifest struct { |
| + DirectPolicies []PolicyCertificate `json:"direct_policies,omitempty"` |
| LauncherVersion string `json:"launcher_version,omitempty"` |
| BwrapVersion string `json:"bwrap_version,omitempty"` |
| PolicyVersion string `json:"policy_version,omitempty"` |
diff --git a/internal/runner/config.go b/internal/runner/config.go| index 551bda6b..e5c85bc8 100644 |
| --- a/internal/runner/config.go |
| +++ b/internal/runner/config.go |
| @@ -11,6 +11,7 @@ import ( |
| "amadan.net/oficina/equipo/internal/release" |
| "amadan.net/oficina/equipo/internal/runner/paseo" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| "amadan.net/oficina/equipo/internal/runnerproto" |
| "golang.org/x/sys/unix" |
| ) |
| @@ -122,3 +123,12 @@ func checkNode(ctx context.Context, path string) error { |
| } |
| return nil |
| } |
| + |
| +// DirectBinding supplies configured provenance inputs. Only OpenAccount can |
| +// validate them and grant DedicatedHome through the returned lease Binding. |
| +func (c Config) DirectBinding(b AccountBinding) (provider.Binding, error) { |
| + if !filepath.IsAbs(c.ScratchRoot) || filepath.Clean(c.ScratchRoot) != c.ScratchRoot || c.ScratchRoot == "/" || containsPath(b.ProviderHome, c.ScratchRoot) || containsPath(c.ScratchRoot, b.ProviderHome) { |
| + return provider.Binding{}, provider.ErrPolicy |
| + } |
| + return provider.Binding{ID: b.ID, Home: b.ProviderHome, AccountID: b.AccountID, Provider: b.Provider, Expected: b.ExpectedIdentity, RuntimeRoot: filepath.Join(c.ScratchRoot, "homes")}, nil |
| +} |
diff --git a/internal/runner/config_test.go b/internal/runner/config_test.go| index 6221073e..e5f3dfb5 100644 |
| --- a/internal/runner/config_test.go |
| +++ b/internal/runner/config_test.go |
| @@ -1,8 +1,10 @@ |
| package runner |
| import ( |
| + "amadan.net/oficina/equipo/internal/release" |
| "context" |
| "crypto/x509" |
| + "encoding/json" |
| "io" |
| "net/http" |
| "os" |
| @@ -132,3 +134,27 @@ func TestRunnerHTTPClientTLSFailure(t *testing.T) { |
| t.Fatal("TLS failure bypassed", err, calls) |
| } |
| } |
| + |
| +func TestAccountHomeConfiguredRuntime(t *testing.T) { |
| + c := configFixture(t) |
| + b := AccountBinding{ProviderHome: filepath.Join(t.TempDir(), "dedicated")} |
| + if _, e := c.DirectBinding(b); e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, path := range []string{"/", "relative", b.ProviderHome, filepath.Join(b.ProviderHome, "nested")} { |
| + bad := c |
| + bad.ScratchRoot = path |
| + if _, e := bad.DirectBinding(b); e == nil { |
| + t.Fatalf("unsafe runtime root accepted: %s", path) |
| + } |
| + } |
| +} |
| + |
| +func TestEffectivePolicyReleaseManifest(t *testing.T) { |
| + raw, _ := json.Marshal(release.PolicyCertificate{Provider: "codex", ProviderVersion: "0.165.0", LauncherVersion: "2", BwrapVersion: "0.11.0", PolicyHash: "policy"}) |
| + for _, key := range []string{"provider", "provider_version", "launcher_version", "bwrap_version", "policy_hash"} { |
| + if !strings.Contains(string(raw), `"`+key+`"`) { |
| + t.Fatalf("missing manifest field %s", key) |
| + } |
| + } |
| +} |
diff --git a/internal/runner/connections.go b/internal/runner/connections.go| index 7ddd0340..6753dc10 100644 |
| --- a/internal/runner/connections.go |
| +++ b/internal/runner/connections.go |
| @@ -13,19 +13,23 @@ import ( |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "amadan.net/oficina/equipo/internal/release" |
| "amadan.net/oficina/equipo/internal/runner/paseo" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| "amadan.net/oficina/equipo/internal/runner/workspace" |
| "amadan.net/oficina/equipo/internal/runnerproto" |
| ) |
| type AccountBinding struct { |
| - ID string `json:"id"` |
| - LocalID string `json:"local_id"` |
| - Provider string `json:"provider"` |
| - Family string `json:"family"` |
| - Model string `json:"model"` |
| - AccountID string `json:"account_id"` |
| - CredentialHome string `json:"credential_home"` |
| - Kind string `json:"kind"` |
| + PersonID string `json:"person_id,omitempty"` |
| + ProviderHome string `json:"provider_home,omitempty"` |
| + ExpectedIdentity provider.Identity `json:"expected_identity,omitempty"` |
| + ID string `json:"id"` |
| + LocalID string `json:"local_id"` |
| + Provider string `json:"provider"` |
| + Family string `json:"family"` |
| + Model string `json:"model"` |
| + AccountID string `json:"account_id"` |
| + CredentialHome string `json:"credential_home"` |
| + Kind string `json:"kind"` |
| } |
| func loadBindings(path string) ([]AccountBinding, error) { |
| @@ -134,3 +138,71 @@ func discover(ctx context.Context, c Config, client *paseo.Client) ([]runnerprot |
| func serviceInspector(client TerminalClient, j *Journal) (*LinuxProcessInspector, error) { |
| return NewLinuxProcessInspector("/proc", client, j) |
| } |
| + |
| +// DirectAccount preserves the configured person's LocalID and model order. |
| +// It contains no credentials and does not grant dispatch authority. |
| +type DirectAccount struct { |
| + Binding AccountBinding |
| + Identity provider.Identity |
| + Available bool |
| + Failure error |
| +} |
| + |
| +func loadDirectBindings(path string) ([]AccountBinding, error) { |
| + var bs []AccountBinding |
| + if e := privateJSON(path, &bs); e != nil { |
| + return nil, e |
| + } |
| + if len(bs) == 0 || len(bs) > 256 { |
| + return nil, provider.ErrIdentity |
| + } |
| + seen := map[string]bool{} |
| + accounts := map[string]AccountBinding{} |
| + for _, b := range bs { |
| + key := b.LocalID + "/" + b.Model |
| + if b.ID == "" || b.LocalID == "" || b.Model == "" || b.AccountID == "" || b.ExpectedIdentity.AccountID != b.AccountID || b.ExpectedIdentity.HomeID == "" || b.ExpectedIdentity.ProviderVersion == "" || !(b.Provider == "codex" && b.Family == "gpt" || b.Provider == "claude" && b.Family == "claude") || !(b.Kind == "subscription" || b.Kind == "api") || provider.DefaultHomeRules().RefusesPath(b.ProviderHome) || seen[key] || b.CredentialHome != "" && b.CredentialHome != b.ProviderHome { |
| + return nil, provider.ErrIdentity |
| + } |
| + if prior, ok := accounts[b.LocalID]; ok && (prior.ID != b.ID || prior.ProviderHome != b.ProviderHome || prior.AccountID != b.AccountID || prior.PersonID != b.PersonID || prior.ExpectedIdentity != b.ExpectedIdentity) { |
| + return nil, provider.ErrIdentity |
| + } |
| + seen[key] = true |
| + accounts[b.LocalID] = b |
| + } |
| + return bs, nil |
| +} |
| + |
| +// DiscoverDirect never consults Paseo or scans interactive homes. Adapters supply |
| +// a no-prompt account-status probe. The dispatch path must open a fresh lease. |
| +func DiscoverDirect(ctx context.Context, c Config, probe func(context.Context, provider.Binding) (provider.Identity, error)) ([]DirectAccount, error) { |
| + return discoverDirect(ctx, c, func(ctx context.Context, b provider.Binding) (provider.Identity, error) { |
| + l, e := provider.OpenAccount(ctx, b) |
| + if e != nil { |
| + return provider.Identity{}, e |
| + } |
| + defer l.Close() |
| + if e = l.Preflight(ctx, probe); e != nil { |
| + return provider.Identity{}, e |
| + } |
| + return l.Identity(), nil |
| + }) |
| +} |
| +func discoverDirect(ctx context.Context, c Config, check func(context.Context, provider.Binding) (provider.Identity, error)) ([]DirectAccount, error) { |
| + bs, e := loadDirectBindings(c.AccountBindingsPath) |
| + if e != nil { |
| + return nil, e |
| + } |
| + reports := make([]DirectAccount, 0, len(bs)) |
| + for _, b := range bs { |
| + if e = ctx.Err(); e != nil { |
| + return nil, e |
| + } |
| + binding, e := c.DirectBinding(b) |
| + if e != nil { |
| + return nil, e |
| + } |
| + id, e := check(ctx, binding) |
| + reports = append(reports, DirectAccount{Binding: b, Identity: id, Available: e == nil && id == b.ExpectedIdentity, Failure: e}) |
| + } |
| + return reports, nil |
| +} |
diff --git a/internal/runner/connections_test.go b/internal/runner/connections_test.go| index 424a1c77..ea0aa2bc 100644 |
| --- a/internal/runner/connections_test.go |
| +++ b/internal/runner/connections_test.go |
| @@ -2,6 +2,7 @@ package runner |
| import ( |
| "amadan.net/oficina/equipo/internal/runner/paseo" |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| "context" |
| "encoding/json" |
| "os" |
| @@ -96,3 +97,45 @@ func TestTrialDedicatedCapabilityReported(t *testing.T) { |
| t.Fatal("dedicated capability lost", report) |
| } |
| } |
| + |
| +func TestAccountHomeConfiguredDiscovery(t *testing.T) { |
| + c := configFixture(t) |
| + bs := []AccountBinding{ |
| + {ID: "binding", LocalID: "person-local", PersonID: "person", Provider: "codex", Family: "gpt", Model: "second", AccountID: "account", ProviderHome: filepath.Join(t.TempDir(), "dedicated"), ExpectedIdentity: provider.Identity{AccountID: "account", HomeID: "home", ProviderVersion: "0.165.0"}, Kind: "subscription"}, |
| + } |
| + second := bs[0] |
| + second.Model = "first" |
| + bs = append(bs, second) |
| + save := func() { |
| + raw, _ := json.Marshal(bs) |
| + if e := os.WriteFile(c.AccountBindingsPath, raw, 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + save() |
| + calls := 0 |
| + reports, e := discoverDirect(context.Background(), c, func(_ context.Context, b provider.Binding) (provider.Identity, error) { |
| + calls++ |
| + if b.DedicatedHome || b.VerifiedDedicatedHome() { |
| + t.Fatal("configuration granted egress authority") |
| + } |
| + return b.Expected, nil |
| + }) |
| + if e != nil || calls != 2 || len(reports) != 2 { |
| + t.Fatal("configured discovery failed", e, calls) |
| + } |
| + if reports[0].Binding.Model != "second" || reports[1].Binding.Model != "first" || reports[0].Binding.PersonID != "person" || reports[0].Binding.LocalID != "person-local" { |
| + t.Fatal("association or order lost") |
| + } |
| + bs = append(bs, bs[0]) |
| + save() |
| + if _, e = loadDirectBindings(c.AccountBindingsPath); e == nil { |
| + t.Fatal("second matching binding accepted") |
| + } |
| + bs = bs[:1] |
| + bs[0].ExpectedIdentity = provider.Identity{} |
| + save() |
| + if _, e = loadDirectBindings(c.AccountBindingsPath); e == nil { |
| + t.Fatal("missing identity accepted") |
| + } |
| +} |
diff --git a/internal/runner/containment/egress.go b/internal/runner/containment/egress.go| index 82f7c431..96c4758e 100644 |
| --- a/internal/runner/containment/egress.go |
| +++ b/internal/runner/containment/egress.go |
| @@ -17,7 +17,7 @@ func (m *Manager) openEgress(ctx context.Context, l provider.Launch, dir string, |
| if l.Selection.Provider == "" { |
| return "", nil |
| } |
| - if l.Binding.DedicatedHome && l.Binding.Home == "" { |
| + if l.Binding.DedicatedHome && !l.Binding.VerifiedDedicatedHome() { |
| return "", errMount |
| } |
| contract := provider.NetworkContract{Provider: l.Selection.Provider} |
| @@ -26,10 +26,13 @@ func (m *Manager) openEgress(ctx context.Context, l provider.Launch, dir string, |
| contract = c |
| } |
| } |
| - policy, e := egress.ProviderPolicy(contract, l.Binding.DedicatedHome) |
| + policy, e := egress.ProviderPolicy(contract, l.Binding.VerifiedDedicatedHome()) |
| if e != nil { |
| return "", e |
| } |
| + if e = l.Policy.ValidateNetwork(policy.Provider, policy.Hosts); e != nil { |
| + return "", e |
| + } |
| hash, e := policy.Hash() |
| if e != nil { |
| return "", e |
diff --git a/internal/runner/containment/egress_test.go b/internal/runner/containment/egress_test.go| index 15752cb7..9adf098f 100644 |
| --- a/internal/runner/containment/egress_test.go |
| +++ b/internal/runner/containment/egress_test.go |
| @@ -308,3 +308,24 @@ func TestEgressStartupFailureClosesProxy(t *testing.T) { |
| } |
| } |
| } |
| + |
| +func TestEgressRejectsForgedDedicatedHome(t *testing.T) { |
| + m, l := egressFixture(t) |
| + home := filepath.Join(m.cfg.ScratchRoot, "homes", "forged") |
| + if e := os.MkdirAll(home, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + l.Binding = provider.Binding{Home: home, DedicatedHome: true} |
| + if p, e := m.Start(context.Background(), l, []string{"/usr/bin/true"}); e == nil { |
| + m.Stop(context.Background(), p.ID()) |
| + t.Fatal("caller boolean granted dedicated-home authority") |
| + } |
| + plan := &mounts{} |
| + if _, e := m.openEgress(context.Background(), l, t.TempDir(), plan); e == nil { |
| + if plan.proxy != nil { |
| + plan.proxy.Close() |
| + } |
| + plan.close() |
| + t.Fatal("egress accepted forged provenance") |
| + } |
| +} |
diff --git a/internal/runner/containment/linux.go b/internal/runner/containment/linux.go| index 0426b8ae..c5196cd6 100644 |
| --- a/internal/runner/containment/linux.go |
| +++ b/internal/runner/containment/linux.go |
| @@ -4,6 +4,7 @@ package containment |
| import ( |
| "context" |
| "crypto/rand" |
| + "crypto/sha256" |
| "encoding/hex" |
| "encoding/json" |
| "errors" |
| @@ -114,6 +115,13 @@ func (m *Manager) Start(ctx context.Context, l provider.Launch, argv []string) ( |
| if l.AttemptKey == "" || l.Policy.Hash == "" || len(argv) == 0 || !cleanAbsolute(argv[0]) { |
| return nil, errStartup |
| } |
| + if e := l.Policy.ValidateRuntimeBinaries(m.cfg.Binary, m.cfg.RunnerBinary); e != nil { |
| + return nil, e |
| + } |
| + manifestHash, err := provider.AttestLaunch(l, argv) |
| + if err != nil { |
| + return nil, err |
| + } |
| var random [16]byte |
| if _, e := rand.Read(random[:]); e != nil { |
| return nil, e |
| @@ -155,7 +163,12 @@ func (m *Manager) Start(ctx context.Context, l provider.Launch, argv []string) ( |
| mounts.close() |
| return nil, e |
| } |
| - r := Record{ID: id, AttemptKey: l.AttemptKey, BootID: boot, ManifestHash: l.Policy.Hash, EgressHash: egressHash} |
| + manifestHash, e = m.namespaceManifest(l, argv, manifestHash, dir, mounts) |
| + if e != nil { |
| + mounts.close() |
| + return nil, e |
| + } |
| + r := Record{ID: id, AttemptKey: l.AttemptKey, BootID: boot, ManifestHash: manifestHash, PolicyHash: l.Policy.Hash, EgressHash: egressHash} |
| if e = m.persist(r); e != nil { |
| mounts.close() |
| return nil, e |
| @@ -241,13 +254,7 @@ func (m *Manager) lifecycle(ctx context.Context, r Record, argv []string, mounts |
| result <- startResult{err: e} |
| return |
| } |
| - args := []string{"--unshare-user", "--unshare-pid", "--unshare-ipc", "--unshare-uts", "--unshare-cgroup", "--unshare-net", "--die-with-parent", "--new-session", "--as-pid-1", "--cap-drop", "ALL", "--json-status-fd", "3"} |
| - args = append(args, mounts.args...) |
| - args = append(args, "--", "/equipo-namespace", "__namespace") |
| - if mounts.proxy != nil { |
| - args = append(args, "--egress") |
| - } |
| - args = append(args, argv...) |
| + args := namespaceArgs(mounts, argv) |
| cmd := exec.Command(m.cfg.Binary, args...) |
| cmd.Env = []string{} |
| cmd.ExtraFiles = append([]*os.File{statusW, releaseR, readyW}, mounts.files...) |
| @@ -526,3 +533,76 @@ func NamespaceMain(argv []string) int { |
| } |
| return status.ExitStatus() |
| } |
| + |
| +func namespaceArgs(mounts *mounts, argv []string) []string { |
| + args := provider.NamespaceArguments() |
| + args = append(args, mounts.args...) |
| + args = append(args, "--", "/equipo-namespace", "__namespace") |
| + if mounts.proxy != nil { |
| + args = append(args, "--egress") |
| + } |
| + args = append(args, argv...) |
| + return args |
| +} |
| + |
| +// Hash the actual namespace plan after sources have been pinned, including the |
| +// generated scratch and socket paths. Directory contents include credentials |
| +// and workspaces, so only regular runtime files are digested here. |
| +func (m *Manager) namespaceManifest(l provider.Launch, argv []string, launchHash, dir string, p *mounts) (string, error) { |
| + type file struct{ Path, Hash string } |
| + files := []file{} |
| + pinnedDigest := func(f *os.File) (string, error) { |
| + reader, e := os.Open(fmt.Sprintf("/proc/self/fd/%d", f.Fd())) |
| + if e != nil { |
| + return "", e |
| + } |
| + defer reader.Close() |
| + h := sha256.New() |
| + if _, e = io.Copy(h, reader); e != nil { |
| + return "", e |
| + } |
| + return hex.EncodeToString(h.Sum(nil)), nil |
| + } |
| + for _, f := range p.files { |
| + info, e := f.Stat() |
| + if e != nil { |
| + return "", e |
| + } |
| + entry := file{Path: f.Name()} |
| + if info.Mode().IsRegular() { |
| + entry.Hash, e = pinnedDigest(f) |
| + if e != nil { |
| + return "", e |
| + } |
| + if e = l.Policy.ValidateFileDigest(f.Name(), entry.Hash); e != nil { |
| + return "", e |
| + } |
| + } |
| + files = append(files, entry) |
| + } |
| + for _, path := range []string{m.cfg.Binary, m.cfg.RunnerBinary} { |
| + f, e := pin(path) |
| + if e != nil { |
| + return "", e |
| + } |
| + hash, e := pinnedDigest(f) |
| + f.Close() |
| + if e != nil { |
| + return "", e |
| + } |
| + if e = l.Policy.ValidateFileDigest(path, hash); e != nil { |
| + return "", e |
| + } |
| + files = append(files, file{Path: path, Hash: hash}) |
| + } |
| + raw, e := json.Marshal(struct { |
| + LaunchHash, PolicyHash, Scratch string |
| + Argv []string |
| + Files []file |
| + }{launchHash, l.Policy.Hash, dir, namespaceArgs(p, argv), files}) |
| + if e != nil { |
| + return "", e |
| + } |
| + hash := sha256.Sum256(raw) |
| + return hex.EncodeToString(hash[:]), nil |
| +} |
diff --git a/internal/runner/containment/linux_test.go b/internal/runner/containment/linux_test.go| index 4e28ea1e..c397327f 100644 |
| --- a/internal/runner/containment/linux_test.go |
| +++ b/internal/runner/containment/linux_test.go |
| @@ -638,3 +638,46 @@ func TestNamespaceCancellation(t *testing.T) { |
| } |
| exited(t, fd) |
| } |
| + |
| +func TestNamespaceConcreteManifestHash(t *testing.T) { |
| + m, l := fixture(t) |
| + p := launch(t, m, l, "pass") |
| + r := record(t, m, p) |
| + if r.ManifestHash == l.Policy.Hash { |
| + t.Fatal("policy hash substituted for concrete manifest hash") |
| + } |
| +} |
| + |
| +func TestNamespaceManifestInputs(t *testing.T) { |
| + m, l := fixture(t) |
| + plan := &mounts{args: []string{"--bind-fd", "6", "/workspace"}} |
| + first, e := m.namespaceManifest(l, []string{"/usr/bin/true"}, "launch", "/scratch/attempt-one", plan) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, kind := range []string{"argv", "mount", "scratch", "binary"} { |
| + t.Run(kind, func(t *testing.T) { |
| + args := []string{"/usr/bin/true"} |
| + dir := "/scratch/attempt-one" |
| + p := *plan |
| + manager := &Manager{cfg: m.cfg} |
| + switch kind { |
| + case "argv": |
| + args = []string{"/usr/bin/false"} |
| + case "mount": |
| + p.args = []string{"--ro-bind-fd", "6", "/workspace"} |
| + case "scratch": |
| + dir = "/scratch/attempt-two" |
| + case "binary": |
| + manager.cfg.RunnerBinary = "/usr/bin/true" |
| + } |
| + next, e := manager.namespaceManifest(l, args, "launch", dir, &p) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if first == next { |
| + t.Fatal("constructed namespace input not hashed") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/containment/recovery.go b/internal/runner/containment/recovery.go| index 31aea388..80aa69db 100644 |
| --- a/internal/runner/containment/recovery.go |
| +++ b/internal/runner/containment/recovery.go |
| @@ -18,7 +18,7 @@ import ( |
| type Record struct { |
| ID, AttemptKey, BootID, NamespaceID, ManifestHash string |
| - EgressHash string |
| + EgressHash, PolicyHash string |
| HostPID int |
| StartTicks uint64 |
| } |
diff --git a/internal/runner/provider/accounts.go b/internal/runner/provider/accounts.go| new file mode 100644 |
| index 00000000..06e96440 |
| --- /dev/null |
| +++ b/internal/runner/provider/accounts.go |
| @@ -0,0 +1,566 @@ |
| +package provider |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/rand" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| + "errors" |
| + "io" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "sync" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +const IdentityFile = "equipo-identity.json" |
| +const ( |
| + ErrAccountBusy Error = "provider_account_busy" |
| + ErrAccountMaintenance Error = "provider_account_maintenance" |
| + ErrPreflightRequired Error = "provider_preflight_required" |
| + ErrContainment Error = "provider_account_containment" |
| + ErrPolicy Error = "provider_policy_rejected" |
| +) |
| + |
| +// HomeRules describes forbidden credential sources. Tests inject owned fake |
| +// directories; production also compares directory inodes to catch bind aliases. |
| +type HomeRules struct{ InteractiveHomes []string } |
| + |
| +func DefaultHomeRules() HomeRules { |
| + home, _ := os.UserHomeDir() |
| + return HomeRules{InteractiveHomes: []string{filepath.Join(home, ".claude"), filepath.Join(home, ".codex")}} |
| +} |
| +func withinPath(path, root string) bool { return path == root || strings.HasPrefix(path, root+"/") } |
| +func cleanPath(path string) bool { |
| + return filepath.IsAbs(path) && filepath.Clean(path) == path && path != "/" |
| +} |
| +func (r HomeRules) RefusesPath(path string) bool { |
| + if !cleanPath(path) { |
| + return true |
| + } |
| + if strings.Contains(path+"/", "/.paseo/zerosub/homes/") { |
| + return true |
| + } |
| + for _, home := range r.InteractiveHomes { |
| + if withinPath(path, home) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| +func (r HomeRules) refusedInode(info os.FileInfo) bool { |
| + for _, home := range r.InteractiveHomes { |
| + if other, e := os.Stat(home); e == nil && os.SameFile(info, other) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| +func pinDirectory(path string) (*os.File, error) { |
| + if !cleanPath(path) { |
| + return nil, ErrPolicy |
| + } |
| + fd, e := unix.Openat2(unix.AT_FDCWD, path, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_DIRECTORY | unix.O_CLOEXEC, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + return os.NewFile(uintptr(fd), path), nil |
| +} |
| +func privateDirectory(f *os.File) bool { |
| + info, e := f.Stat() |
| + return e == nil && info.IsDir() && info.Mode().Perm() == 0700 |
| +} |
| + |
| +// AccountLease holds a directory flock until Close, including across preflight, |
| +// all turns and token refresh. Claude's identity is trust-on-first-use: Paul |
| +// confirms CLI-observed metadata at enrolment. It is not remote attestation. |
| +type AccountLease struct { |
| + mu sync.Mutex |
| + source Binding |
| + rules HomeRules |
| + dir *os.File |
| + runtime string |
| + runtimeInfo os.FileInfo |
| + generation [32]byte |
| + ready, active, closed bool |
| + checking bool |
| + runtimeGeneration [32]byte |
| +} |
| + |
| +func OpenAccount(ctx context.Context, b Binding) (*AccountLease, error) { |
| + return openAccount(ctx, b, DefaultHomeRules()) |
| +} |
| +func openAccount(ctx context.Context, b Binding, r HomeRules) (_ *AccountLease, err error) { |
| + if e := ctx.Err(); e != nil { |
| + return nil, e |
| + } |
| + if ValidateContract(Version, b.Provider) != nil || b.ID == "" || b.AccountID == "" || b.Expected.AccountID != b.AccountID || b.Expected.HomeID == "" || b.Expected.ProviderVersion == "" || r.RefusesPath(b.Home) { |
| + return nil, ErrIdentity |
| + } |
| + // Resolve before opening any login file. Also inspect mount roots for aliases |
| + // of forbidden trees; inode comparison below handles explicit interactive homes. |
| + real, e := filepath.EvalSymlinks(b.Home) |
| + if e != nil || real != b.Home || r.RefusesPath(real) || refusedMountAlias(b.Home, r) { |
| + return nil, ErrPolicy |
| + } |
| + dir, e := pinDirectory(b.Home) |
| + if e != nil { |
| + return nil, e |
| + } |
| + defer func() { |
| + if err != nil { |
| + dir.Close() |
| + } |
| + }() |
| + if !privateDirectory(dir) { |
| + return nil, ErrPolicy |
| + } |
| + for parent := b.Home; parent != "/"; parent = filepath.Dir(parent) { |
| + info, e := os.Stat(parent) |
| + if e != nil || r.refusedInode(info) { |
| + return nil, ErrPolicy |
| + } |
| + } |
| + if e = unix.Flock(int(dir.Fd()), unix.LOCK_EX|unix.LOCK_NB); e != nil { |
| + return nil, ErrAccountBusy |
| + } |
| + l := &AccountLease{source: b, dir: dir, rules: r} |
| + _, _, e = l.snapshot() |
| + if e != nil { |
| + return nil, e |
| + } |
| + if r.RefusesPath(b.RuntimeRoot) || !cleanPath(b.RuntimeRoot) || withinPath(b.RuntimeRoot, b.Home) || withinPath(b.Home, b.RuntimeRoot) { |
| + return nil, ErrPolicy |
| + } |
| + root, e := makePrivateRoot(b.RuntimeRoot) |
| + if e != nil { |
| + return nil, e |
| + } |
| + defer root.Close() |
| + if !privateDirectory(root) { |
| + return nil, ErrPolicy |
| + } |
| + l.runtime, e = os.MkdirTemp(b.RuntimeRoot, "account-") |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + l.runtimeInfo, e = os.Stat(l.runtime) |
| + if e != nil { |
| + os.RemoveAll(l.runtime) |
| + return nil, ErrPolicy |
| + } |
| + if e = l.stage(); e != nil { |
| + os.RemoveAll(l.runtime) |
| + return nil, e |
| + } |
| + return l, nil |
| +} |
| + |
| +// mountinfo's root field retains the original tree when a directory is bind |
| +// mounted elsewhere. No credential file is consulted to reject these aliases. |
| +func refusedMountAlias(path string, r HomeRules) bool { |
| + data, e := os.ReadFile("/proc/self/mountinfo") |
| + if e != nil { |
| + return true |
| + } |
| + decode := strings.NewReplacer(`\040`, " ", `\011`, "\t", `\012`, "\n", `\134`, `\`) |
| + for _, line := range strings.Split(string(data), "\n") { |
| + fields := strings.Fields(line) |
| + if len(fields) < 6 { |
| + continue |
| + } |
| + root, mount := decode.Replace(fields[3]), decode.Replace(fields[4]) |
| + if withinPath(path, mount) { |
| + rel, e := filepath.Rel(mount, path) |
| + if e != nil || r.RefusesPath(filepath.Join(root, rel)) { |
| + return true |
| + } |
| + } |
| + } |
| + return false |
| +} |
| +func credentialName(provider string) string { |
| + if provider == "claude" { |
| + return ".credentials.json" |
| + } |
| + return "auth.json" |
| +} |
| +func readPrivate(dir *os.File, name string) ([]byte, error) { |
| + fd, e := unix.Openat(int(dir.Fd()), name, unix.O_RDONLY|unix.O_NOFOLLOW|unix.O_CLOEXEC|unix.O_NONBLOCK, 0) |
| + if e != nil { |
| + return nil, ErrAccountMaintenance |
| + } |
| + f := os.NewFile(uintptr(fd), name) |
| + defer f.Close() |
| + var st unix.Stat_t |
| + if unix.Fstat(fd, &st) != nil || st.Nlink != 1 || st.Uid != uint32(os.Geteuid()) { |
| + return nil, ErrPolicy |
| + } |
| + info, e := f.Stat() |
| + if e != nil || !info.Mode().IsRegular() || info.Mode().Perm() != 0600 || info.Size() > 1<<20 { |
| + return nil, ErrPolicy |
| + } |
| + raw, e := io.ReadAll(io.LimitReader(f, (1<<20)+1)) |
| + if e != nil || len(raw) == 0 || len(raw) > 1<<20 { |
| + return nil, ErrAccountMaintenance |
| + } |
| + return raw, nil |
| +} |
| +func (l *AccountLease) sourceUnchanged() bool { |
| + f, e := pinDirectory(l.source.Home) |
| + if e != nil { |
| + return false |
| + } |
| + defer f.Close() |
| + a, e := f.Stat() |
| + if e != nil { |
| + return false |
| + } |
| + b, e := l.dir.Stat() |
| + return e == nil && os.SameFile(a, b) && privateDirectory(f) |
| +} |
| +func (l *AccountLease) snapshot() ([]byte, [32]byte, error) { |
| + var zero [32]byte |
| + if !l.sourceUnchanged() { |
| + return nil, zero, ErrContainment |
| + } |
| + metadata, e := readPrivate(l.dir, IdentityFile) |
| + if e != nil { |
| + return nil, zero, e |
| + } |
| + metadata, e = canonical(metadata) |
| + if e != nil { |
| + return nil, zero, ErrIdentity |
| + } |
| + var id Identity |
| + dec := json.NewDecoder(bytes.NewReader(metadata)) |
| + dec.DisallowUnknownFields() |
| + if dec.Decode(&id) != nil || dec.Decode(new(any)) != io.EOF || id != l.source.Expected { |
| + return nil, zero, ErrIdentity |
| + } |
| + raw, e := readPrivate(l.dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, zero, e |
| + } |
| + // This digest stays in memory. Stat identity detects atomic replacement |
| + // even when the replacement contains identical credential bytes. |
| + var stat unix.Stat_t |
| + if unix.Fstatat(int(l.dir.Fd()), credentialName(l.source.Provider), &stat, unix.AT_SYMLINK_NOFOLLOW) != nil { |
| + return nil, zero, ErrAccountMaintenance |
| + } |
| + state, _ := json.Marshal(struct { |
| + Dev, Ino uint64 |
| + Mtime, Ctime unix.Timespec |
| + }{uint64(stat.Dev), stat.Ino, stat.Mtim, stat.Ctim}) |
| + digest := sha256.Sum256(bytes.Join([][]byte{metadata, raw, state}, nil)) |
| + return raw, digest, nil |
| +} |
| +func (l *AccountLease) runtimeDir() (*os.File, error) { |
| + f, e := pinDirectory(l.runtime) |
| + if e != nil { |
| + return nil, ErrContainment |
| + } |
| + info, e := f.Stat() |
| + if e != nil || !os.SameFile(info, l.runtimeInfo) || !privateDirectory(f) { |
| + f.Close() |
| + return nil, ErrContainment |
| + } |
| + return f, nil |
| +} |
| +func atomicPrivate(dir *os.File, name string, raw []byte) error { |
| + var random [16]byte |
| + if _, e := rand.Read(random[:]); e != nil { |
| + return ErrAccountMaintenance |
| + } |
| + temp := ".equipo-" + hex.EncodeToString(random[:]) |
| + fd, e := unix.Openat(int(dir.Fd()), temp, unix.O_WRONLY|unix.O_CREAT|unix.O_EXCL|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0600) |
| + if e != nil { |
| + return ErrAccountMaintenance |
| + } |
| + defer unix.Unlinkat(int(dir.Fd()), temp, 0) |
| + f := os.NewFile(uintptr(fd), temp) |
| + _, e = f.Write(raw) |
| + if e == nil { |
| + e = f.Sync() |
| + } |
| + closeErr := f.Close() |
| + if e != nil || closeErr != nil { |
| + return ErrAccountMaintenance |
| + } |
| + if unix.Renameat(int(dir.Fd()), temp, int(dir.Fd()), name) != nil || dir.Sync() != nil { |
| + return ErrAccountMaintenance |
| + } |
| + return nil |
| +} |
| +func (l *AccountLease) stage() error { |
| + raw, _, e := l.snapshot() |
| + if e != nil { |
| + return e |
| + } |
| + dir, e := l.runtimeDir() |
| + if e != nil { |
| + return e |
| + } |
| + defer dir.Close() |
| + name := credentialName(l.source.Provider) |
| + var stat unix.Stat_t |
| + if e = unix.Fstatat(int(dir.Fd()), name, &stat, unix.AT_SYMLINK_NOFOLLOW); e == nil && stat.Mode&unix.S_IFMT != unix.S_IFREG { |
| + return ErrContainment |
| + } |
| + if e != nil && e != unix.ENOENT { |
| + return ErrContainment |
| + } |
| + if e = atomicPrivate(dir, name, raw); e != nil { |
| + return e |
| + } |
| + metadata, _ := json.Marshal(l.source.Expected) |
| + if e = atomicPrivate(dir, IdentityFile, metadata); e != nil { |
| + return e |
| + } |
| + l.runtimeGeneration = sha256.Sum256(raw) |
| + return nil |
| +} |
| +func (l *AccountLease) runtimeSnapshot() ([]byte, error) { |
| + dir, e := l.runtimeDir() |
| + if e != nil { |
| + return nil, e |
| + } |
| + defer dir.Close() |
| + return readPrivate(dir, credentialName(l.source.Provider)) |
| +} |
| +func (l *AccountLease) binding() Binding { |
| + b := l.source |
| + b.CredentialHome = b.Home |
| + b.Home = l.runtime |
| + b.DedicatedHome = true |
| + b.provenance = l |
| + return b |
| +} |
| +func (l *AccountLease) Binding() Binding { l.mu.Lock(); defer l.mu.Unlock(); return l.binding() } |
| +func (l *AccountLease) Identity() Identity { return l.source.Expected } |
| +func (b Binding) VerifiedDedicatedHome() bool { |
| + l := b.provenance |
| + if l == nil { |
| + return false |
| + } |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + return !l.closed && b == l.binding() && l.sourceUnchanged() |
| +} |
| +func (l *AccountLease) validate(ctx context.Context) error { |
| + if e := ctx.Err(); e != nil { |
| + return e |
| + } |
| + if l.closed || l.checking { |
| + return ErrAccountMaintenance |
| + } |
| + _, generation, e := l.snapshot() |
| + if e != nil { |
| + l.ready = false |
| + if l.active { |
| + return ErrContainment |
| + } |
| + return e |
| + } |
| + if generation != l.generation { |
| + l.ready = false |
| + if l.active { |
| + return ErrContainment |
| + } |
| + return ErrPreflightRequired |
| + } |
| + runtimeRaw, runtimeErr := l.runtimeSnapshot() |
| + if runtimeErr != nil || sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| + l.ready = false |
| + if l.active { |
| + return ErrContainment |
| + } |
| + return ErrPreflightRequired |
| + } |
| + if !l.ready { |
| + return ErrPreflightRequired |
| + } |
| + return nil |
| +} |
| +func (l *AccountLease) Validate(ctx context.Context) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + return l.validate(ctx) |
| +} |
| + |
| +// Preflight restages only the selected login and checks CLI-observed identity. |
| +// Call it again after ErrPreflightRequired, before binding a new turn or resume. |
| +// A failed check leaves the account waiting for maintenance, never in failover. |
| +func (l *AccountLease) Preflight(ctx context.Context, probe func(context.Context, Binding) (Identity, error)) error { |
| + return l.check(ctx, probe, false) |
| +} |
| + |
| +// CommitRefresh accepts a login atomically replaced by the harness in its |
| +// private runtime home. The adapter must observe the same identity without |
| +// prompting. A successful commit still requires Preflight before another turn. |
| +func (l *AccountLease) CommitRefresh(ctx context.Context, probe func(context.Context, Binding) (Identity, error)) error { |
| + return l.check(ctx, probe, true) |
| +} |
| +func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Binding) (Identity, error), refresh bool) error { |
| + l.mu.Lock() |
| + if e := ctx.Err(); e != nil { |
| + l.mu.Unlock() |
| + return e |
| + } |
| + if l.closed || l.active || l.checking || probe == nil { |
| + l.mu.Unlock() |
| + return ErrAccountMaintenance |
| + } |
| + l.ready = false |
| + _, before, e := l.snapshot() |
| + if e != nil { |
| + l.mu.Unlock() |
| + return e |
| + } |
| + if !refresh { |
| + e = l.stage() |
| + if e != nil { |
| + l.mu.Unlock() |
| + return e |
| + } |
| + } |
| + runtimeBefore, e := l.runtimeSnapshot() |
| + if e != nil { |
| + l.mu.Unlock() |
| + return e |
| + } |
| + l.checking = true |
| + b := l.binding() |
| + l.mu.Unlock() |
| + id, probeErr := probe(ctx, b) |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + l.checking = false |
| + if l.closed { |
| + return ErrAccountMaintenance |
| + } |
| + if e = ctx.Err(); e != nil { |
| + return e |
| + } |
| + if probeErr != nil { |
| + return probeErr |
| + } |
| + if id != l.source.Expected { |
| + return ErrIdentity |
| + } |
| + _, after, e := l.snapshot() |
| + if e != nil { |
| + return e |
| + } |
| + if before != after { |
| + return ErrPreflightRequired |
| + } |
| + runtimeAfter, e := l.runtimeSnapshot() |
| + if e != nil { |
| + return e |
| + } |
| + if !bytes.Equal(runtimeBefore, runtimeAfter) { |
| + return ErrPreflightRequired |
| + } |
| + if refresh { |
| + if e = atomicPrivate(l.dir, credentialName(l.source.Provider), runtimeAfter); e != nil { |
| + return e |
| + } |
| + return nil |
| + } |
| + l.generation = after |
| + l.runtimeGeneration = sha256.Sum256(runtimeAfter) |
| + l.ready = true |
| + return nil |
| +} |
| +func (l *AccountLease) BeginTurn(ctx context.Context) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if l.active { |
| + return ErrAccountBusy |
| + } |
| + if e := l.validate(ctx); e != nil { |
| + return e |
| + } |
| + l.active = true |
| + return nil |
| +} |
| +func (l *AccountLease) EndTurn(ctx context.Context) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + e := l.validate(ctx) |
| + l.active = false |
| + return e |
| +} |
| +func (l *AccountLease) Close() error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if l.closed { |
| + return nil |
| + } |
| + l.closed = true |
| + l.ready = false |
| + // Do not follow a runtime path replaced by someone else during cleanup. |
| + info, e := os.Lstat(l.runtime) |
| + var cleanup error |
| + if e == nil && os.SameFile(info, l.runtimeInfo) { |
| + cleanup = os.RemoveAll(l.runtime) |
| + } else { |
| + cleanup = ErrContainment |
| + } |
| + return errors.Join(cleanup, l.dir.Close()) |
| +} |
| + |
| +func (l *AccountLease) validateLaunch() error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if l.closed { |
| + return ErrAccountMaintenance |
| + } |
| + if l.checking { |
| + _, _, e := l.snapshot() |
| + return e |
| + } |
| + return l.validate(context.Background()) |
| +} |
| + |
| +func makePrivateRoot(path string) (*os.File, error) { |
| + missing := []string{} |
| + parent := path |
| + for { |
| + _, e := os.Lstat(parent) |
| + if e == nil { |
| + break |
| + } |
| + if !os.IsNotExist(e) || parent == "/" { |
| + return nil, ErrPolicy |
| + } |
| + missing = append(missing, filepath.Base(parent)) |
| + parent = filepath.Dir(parent) |
| + } |
| + dir, e := pinDirectory(parent) |
| + if e != nil { |
| + return nil, e |
| + } |
| + for i := len(missing) - 1; i >= 0; i-- { |
| + if e = unix.Mkdirat(int(dir.Fd()), missing[i], 0700); e != nil && e != unix.EEXIST { |
| + dir.Close() |
| + return nil, ErrPolicy |
| + } |
| + fd, e := unix.Openat(int(dir.Fd()), missing[i], unix.O_RDONLY|unix.O_DIRECTORY|unix.O_NOFOLLOW|unix.O_CLOEXEC, 0) |
| + dir.Close() |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + dir = os.NewFile(uintptr(fd), path) |
| + } |
| + if !privateDirectory(dir) { |
| + dir.Close() |
| + return nil, ErrPolicy |
| + } |
| + return dir, nil |
| +} |
diff --git a/internal/runner/provider/accounts_test.go b/internal/runner/provider/accounts_test.go| new file mode 100644 |
| index 00000000..a5fb7d5a |
| --- /dev/null |
| +++ b/internal/runner/provider/accounts_test.go |
| @@ -0,0 +1,433 @@ |
| +package provider |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| +) |
| + |
| +func accountFixture(t *testing.T) (Binding, HomeRules) { |
| + t.Helper() |
| + root := t.TempDir() |
| + home := filepath.Join(root, "dedicated") |
| + if e := os.Mkdir(home, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + identity := Identity{AccountID: "account", HomeID: "enrolled-home", ProviderVersion: "0.165.0"} |
| + b := Binding{ID: "binding", Home: home, AccountID: "account", Provider: "codex", Expected: identity, RuntimeRoot: filepath.Join(root, "homes")} |
| + writeMetadata(t, home, identity) |
| + writeFake(t, filepath.Join(home, "auth.json"), `{"token":"fake-one"}`) |
| + return b, HomeRules{InteractiveHomes: []string{filepath.Join(root, "interactive")}} |
| +} |
| +func writeFake(t *testing.T, path, s string) { |
| + t.Helper() |
| + if e := os.WriteFile(path, []byte(s), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| +} |
| +func writeMetadata(t *testing.T, home string, id Identity) { |
| + t.Helper() |
| + raw, _ := json.Marshal(id) |
| + writeFake(t, filepath.Join(home, IdentityFile), string(raw)) |
| +} |
| +func openFixture(t *testing.T, b Binding, r HomeRules) *AccountLease { |
| + t.Helper() |
| + l, e := openAccount(context.Background(), b, r) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + t.Cleanup(func() { l.Close() }) |
| + return l |
| +} |
| +func preflightFixture(t *testing.T, l *AccountLease) { |
| + t.Helper() |
| + if e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return l.Identity(), nil }); e != nil { |
| + t.Fatal(e) |
| + } |
| +} |
| + |
| +func TestAccountHomeBinding(t *testing.T) { |
| + t.Run("dedicated provenance", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + b.DedicatedHome = true |
| + if b.VerifiedDedicatedHome() { |
| + t.Fatal("input boolean granted authority") |
| + } |
| + l := openFixture(t, b, r) |
| + if !l.Binding().VerifiedDedicatedHome() { |
| + t.Fatal("verified lease lost provenance") |
| + } |
| + wire, _ := json.Marshal(l.Binding()) |
| + var forged Binding |
| + json.Unmarshal(wire, &forged) |
| + if forged.VerifiedDedicatedHome() { |
| + t.Fatal("wire input granted authority") |
| + } |
| + altered := l.Binding() |
| + altered.AccountID = "other" |
| + if altered.VerifiedDedicatedHome() { |
| + t.Fatal("altered binding retained authority") |
| + } |
| + if e := l.Validate(context.Background()); !errors.Is(e, ErrPreflightRequired) { |
| + t.Fatalf("unobserved identity accepted: %v", e) |
| + } |
| + preflightFixture(t, l) |
| + if e := l.Validate(context.Background()); e != nil { |
| + t.Fatal(e) |
| + } |
| + l.Close() |
| + if l.Binding().VerifiedDedicatedHome() { |
| + t.Fatal("closed lease retained authority") |
| + } |
| + }) |
| + t.Run("identity", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + b.Expected.AccountID = "other" |
| + if l, e := openAccount(context.Background(), b, r); e == nil { |
| + l.Close() |
| + t.Fatal("wrong expected identity accepted") |
| + } |
| + }) |
| + t.Run("missing metadata", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + os.Remove(filepath.Join(b.Home, IdentityFile)) |
| + if l, e := openAccount(context.Background(), b, r); e == nil { |
| + l.Close() |
| + t.Fatal("missing metadata accepted") |
| + } |
| + }) |
| + t.Run("shared and aliases", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + r.InteractiveHomes = []string{b.Home} |
| + for _, name := range []string{b.Home, filepath.Join(filepath.Dir(b.Home), "alias")} { |
| + if name != b.Home { |
| + if e := os.Symlink(b.Home, name); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + candidate := b |
| + candidate.Home = name |
| + if l, e := openAccount(context.Background(), candidate, r); e == nil { |
| + l.Close() |
| + t.Fatal("shared home accepted") |
| + } |
| + } |
| + // Inode comparison is exercised independently of path spelling (bind alias semantics). |
| + f, e := os.Open(b.Home) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer f.Close() |
| + info, _ := f.Stat() |
| + if !r.refusedInode(info) { |
| + t.Fatal("shared inode accepted") |
| + } |
| + }) |
| + t.Run("real defaults path only", func(t *testing.T) { |
| + r := DefaultHomeRules() |
| + for _, p := range r.InteractiveHomes { |
| + if !r.RefusesPath(p) { |
| + t.Fatal("default shared home accepted") |
| + } |
| + } |
| + if !r.RefusesPath("/home/paulca/.paseo/zerosub/homes/fake") { |
| + t.Fatal("ZeroSub accepted") |
| + } |
| + }) |
| + t.Run("private modes", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + os.Chmod(filepath.Join(b.Home, "auth.json"), 0644) |
| + if l, e := openAccount(context.Background(), b, r); e == nil { |
| + l.Close() |
| + t.Fatal("public credentials accepted") |
| + } |
| + }) |
| +} |
| +func TestAccountUnavailableDoesNotFailover(t *testing.T) { |
| + for _, failure := range []error{ErrAccountMaintenance, ErrIdentity, Error("quota")} { |
| + t.Run(failure.Error(), func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + calls, prompts := 0, 0 |
| + e := l.Preflight(context.Background(), func(_ context.Context, got Binding) (Identity, error) { |
| + calls++ |
| + if got.AccountID != b.AccountID { |
| + t.Fatal("fallback account") |
| + } |
| + return Identity{}, failure |
| + }) |
| + if e == nil { |
| + t.Fatal("failure accepted") |
| + } |
| + if l.BeginTurn(context.Background()) == nil { |
| + prompts++ |
| + } |
| + if calls != 1 || prompts != 0 { |
| + t.Fatalf("calls=%d prompts=%d", calls, prompts) |
| + } |
| + }) |
| + } |
| +} |
| +func TestAccountHomeMutation(t *testing.T) { |
| + t.Run("replacement", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + os.Rename(b.Home, b.Home+"-old") |
| + os.Symlink(b.Home+"-old", b.Home) |
| + if e := l.Validate(context.Background()); !errors.Is(e, ErrContainment) { |
| + t.Fatalf("replacement accepted: %v", e) |
| + } |
| + }) |
| + t.Run("lock", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + if other, e := openAccount(context.Background(), b, r); !errors.Is(e, ErrAccountBusy) { |
| + if other != nil { |
| + other.Close() |
| + } |
| + t.Fatalf("concurrent lease accepted: %v", e) |
| + } |
| + l.Close() |
| + openFixture(t, b, r) |
| + }) |
| + for _, kind := range []string{"successful refresh", "failed refresh", "identity change", "active change"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + if kind == "active change" { |
| + if e := l.BeginTurn(context.Background()); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + writeFake(t, filepath.Join(b.Home, "replacement"), `{"token":"fake-two"}`) |
| + os.Rename(filepath.Join(b.Home, "replacement"), filepath.Join(b.Home, "auth.json")) |
| + if kind == "identity change" { |
| + id := b.Expected |
| + id.AccountID = "different" |
| + writeMetadata(t, b.Home, id) |
| + } |
| + want := ErrPreflightRequired |
| + if kind == "identity change" { |
| + want = ErrIdentity |
| + } |
| + if kind == "active change" { |
| + want = ErrContainment |
| + } |
| + if e := l.Validate(context.Background()); !errors.Is(e, want) { |
| + t.Fatalf("got %v want %v", e, want) |
| + } |
| + if kind == "successful refresh" { |
| + preflightFixture(t, l) |
| + if e := l.BeginTurn(context.Background()); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := l.EndTurn(context.Background()); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + if kind == "failed refresh" { |
| + e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return Identity{}, ErrAccountMaintenance }) |
| + if !errors.Is(e, ErrAccountMaintenance) { |
| + t.Fatal(e) |
| + } |
| + if l.BeginTurn(context.Background()) == nil { |
| + t.Fatal("failed refresh dispatched") |
| + } |
| + } |
| + }) |
| + } |
| +} |
| +func TestPrivateHomeDoesNotTouchInteractiveConfig(t *testing.T) { |
| + b, r := accountFixture(t) |
| + interactive := r.InteractiveHomes[0] |
| + os.Mkdir(interactive, 0700) |
| + path := filepath.Join(interactive, "config.toml") |
| + writeFake(t, path, "original untrusted config") |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + home := l.Binding().Home |
| + raw, e := os.ReadFile(filepath.Join(home, "auth.json")) |
| + if e != nil || string(raw) != `{"token":"fake-one"}` { |
| + t.Fatal("login not staged", e) |
| + } |
| + for _, p := range []string{home, filepath.Join(home, "auth.json")} { |
| + info, e := os.Stat(p) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + want := os.FileMode(0600) |
| + if info.IsDir() { |
| + want = 0700 |
| + } |
| + if info.Mode().Perm() != want { |
| + t.Fatal("nonprivate runtime") |
| + } |
| + } |
| + got, _ := os.ReadFile(path) |
| + entries, _ := os.ReadDir(interactive) |
| + if string(got) != "original untrusted config" || len(entries) != 1 { |
| + t.Fatal("interactive config changed") |
| + } |
| + l.Close() |
| + if _, e = os.Stat(home); !os.IsNotExist(e) { |
| + t.Fatal("runtime leaked") |
| + } |
| +} |
| + |
| +func TestAccountHomeRuntimeGuards(t *testing.T) { |
| + t.Run("runtime symlink", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + target := filepath.Join(l.Binding().Home, "auth.json") |
| + os.Remove(target) |
| + os.Symlink(filepath.Join(b.Home, "auth.json"), target) |
| + if l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return b.Expected, nil }) == nil { |
| + t.Fatal("runtime symlink accepted") |
| + } |
| + }) |
| + t.Run("same bytes new generation", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + writeFake(t, filepath.Join(b.Home, "new"), `{"token":"fake-one"}`) |
| + os.Rename(filepath.Join(b.Home, "new"), filepath.Join(b.Home, "auth.json")) |
| + if l.Validate(context.Background()) == nil { |
| + t.Fatal("atomic generation not detected") |
| + } |
| + }) |
| + t.Run("runtime active mutation", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + l.BeginTurn(context.Background()) |
| + writeFake(t, filepath.Join(l.Binding().Home, "auth.json"), `{"token":"fake-new"}`) |
| + if !errors.Is(l.EndTurn(context.Background()), ErrContainment) { |
| + t.Fatal("active runtime mutation accepted") |
| + } |
| + }) |
| + t.Run("controlled refresh", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + writeFake(t, filepath.Join(l.Binding().Home, "auth.json"), `{"token":"fake-refreshed"}`) |
| + if e := l.CommitRefresh(context.Background(), func(_ context.Context, got Binding) (Identity, error) { |
| + if !got.VerifiedDedicatedHome() { |
| + t.Fatal("probe lost provenance") |
| + } |
| + return b.Expected, nil |
| + }); e != nil { |
| + t.Fatal(e) |
| + } |
| + if !errors.Is(l.Validate(context.Background()), ErrPreflightRequired) { |
| + t.Fatal("refresh skipped preflight") |
| + } |
| + preflightFixture(t, l) |
| + raw, _ := os.ReadFile(filepath.Join(b.Home, "auth.json")) |
| + if string(raw) != `{"token":"fake-refreshed"}` { |
| + t.Fatal("refresh not committed") |
| + } |
| + }) |
| +} |
| + |
| +func TestAccountHomeRuntimeAliasNoSideEffects(t *testing.T) { |
| + b, r := accountFixture(t) |
| + interactive := r.InteractiveHomes[0] |
| + if e := os.Mkdir(interactive, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + alias := filepath.Join(filepath.Dir(b.Home), "runtime-alias") |
| + if e := os.Symlink(interactive, alias); e != nil { |
| + t.Fatal(e) |
| + } |
| + b.RuntimeRoot = filepath.Join(alias, "new") |
| + if l, e := openAccount(context.Background(), b, r); e == nil { |
| + l.Close() |
| + t.Fatal("runtime alias accepted") |
| + } |
| + entries, e := os.ReadDir(interactive) |
| + if e != nil || len(entries) != 0 { |
| + t.Fatal("interactive directory changed", e) |
| + } |
| +} |
| +func TestAccountHomeFileGuards(t *testing.T) { |
| + for _, kind := range []string{"directory mode", "credential hardlink", "metadata trailing", "metadata duplicate", "metadata missing home"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + switch kind { |
| + case "directory mode": |
| + os.Chmod(b.Home, 0755) |
| + case "credential hardlink": |
| + os.Link(filepath.Join(b.Home, "auth.json"), filepath.Join(filepath.Dir(b.Home), "linked")) |
| + case "metadata trailing": |
| + raw, _ := json.Marshal(b.Expected) |
| + writeFake(t, filepath.Join(b.Home, IdentityFile), string(raw)+`{}`) |
| + case "metadata duplicate": |
| + writeFake(t, filepath.Join(b.Home, IdentityFile), `{"account_id":"account","account_id":"account","home_id":"enrolled-home","provider_version":"0.165.0"}`) |
| + case "metadata missing home": |
| + id := b.Expected |
| + id.HomeID = "" |
| + writeMetadata(t, b.Home, id) |
| + } |
| + if l, e := openAccount(context.Background(), b, r); e == nil { |
| + l.Close() |
| + t.Fatal("unsafe account input accepted") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestAccountHomePreflightGuards(t *testing.T) { |
| + t.Run("observed identity", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + id := b.Expected |
| + id.AccountID = "other" |
| + if e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return id, nil }); !errors.Is(e, ErrIdentity) { |
| + t.Fatal("wrong CLI identity accepted", e) |
| + } |
| + }) |
| + t.Run("generation during probe", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + if e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { |
| + writeFake(t, filepath.Join(b.Home, "auth.json"), `{"token":"changed-during-probe"}`) |
| + return b.Expected, nil |
| + }); !errors.Is(e, ErrPreflightRequired) { |
| + t.Fatal("unstable probe accepted", e) |
| + } |
| + }) |
| + t.Run("refresh identity", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + writeFake(t, filepath.Join(l.Binding().Home, "auth.json"), `{"token":"wrong-account"}`) |
| + id := b.Expected |
| + id.AccountID = "other" |
| + if e := l.CommitRefresh(context.Background(), func(context.Context, Binding) (Identity, error) { return id, nil }); !errors.Is(e, ErrIdentity) { |
| + t.Fatal("wrong refresh accepted", e) |
| + } |
| + raw, _ := os.ReadFile(filepath.Join(b.Home, "auth.json")) |
| + if string(raw) != `{"token":"fake-one"}` { |
| + t.Fatal("failed refresh modified dedicated home") |
| + } |
| + }) |
| + t.Run("claude", func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + b.Provider = "claude" |
| + b.Expected.ProviderVersion = "2.1.312" |
| + writeMetadata(t, b.Home, b.Expected) |
| + writeFake(t, filepath.Join(b.Home, ".credentials.json"), `{"token":"fake-claude"}`) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + if _, e := os.Stat(filepath.Join(l.Binding().Home, "auth.json")); !os.IsNotExist(e) { |
| + t.Fatal("other provider login copied") |
| + } |
| + }) |
| +} |
diff --git a/internal/runner/provider/policy.go b/internal/runner/provider/policy.go| new file mode 100644 |
| index 00000000..7d201a1e |
| --- /dev/null |
| +++ b/internal/runner/provider/policy.go |
| @@ -0,0 +1,584 @@ |
| +package provider |
| + |
| +import ( |
| + "bytes" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| + "io" |
| + "net/netip" |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "sort" |
| + "strings" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +const PolicyVersion = "direct-v1" |
| +const SettingsPath = "/config/equipo-settings.json" |
| +const MCPPath = "/config/equipo-mcp.json" |
| + |
| +type PolicyInputs struct { |
| + RuntimeFiles []Mount |
| + DeniedPaths, EgressHosts []string |
| + ProviderVersion, LauncherVersion, BwrapVersion string |
| + Settings, MCP, ThreadPolicy, TurnPolicy json.RawMessage |
| + Tools []string |
| + // Adapters supply the exact argv and any permitted nonsecret environment. |
| + Argv []string |
| + Env map[string]string |
| + Workspace, Scratch string |
| + InstructionFiles []Mount |
| +} |
| +type fileDigest struct { |
| + Mount Mount |
| + SHA256 string |
| +} |
| +type effectiveManifest struct { |
| + OuterMounts, GeneratedMounts []Mount |
| + NamespaceArgs []string |
| + Version string |
| + BindingID, Provider, AccountID, CredentialHome string |
| + Identity Identity |
| + ProviderVersion, LauncherVersion, BwrapVersion string |
| + Argv []string |
| + Env map[string]string |
| + Files []fileDigest |
| + DeniedPaths, EgressHosts, Tools []string |
| + Settings, MCP, ThreadPolicy, TurnPolicy json.RawMessage |
| + Workspace, Scratch, RuntimeHome string |
| + Instructions []fileDigest |
| + HooksDisabled, PluginsDisabled, TurnOverridesOmitted bool |
| + MaskedDirectories []string |
| + Proxy string |
| +} |
| + |
| +func digest(raw []byte) string { s := sha256.Sum256(raw); return hex.EncodeToString(s[:]) } |
| +func hashJSON(value any) ([]byte, string, error) { |
| + raw, e := json.Marshal(value) |
| + return raw, digest(raw), e |
| +} |
| + |
| +// Canonical JSON rejects duplicate keys so the harness and attestation cannot |
| +// interpret the same configuration differently. Numbers retain their precision. |
| +func canonical(raw json.RawMessage) (json.RawMessage, error) { |
| + if len(raw) == 0 { |
| + raw = json.RawMessage(`{}`) |
| + } |
| + d := json.NewDecoder(bytes.NewReader(raw)) |
| + d.UseNumber() |
| + value, e := jsonValue(d) |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + if _, e = d.Token(); e != io.EOF { |
| + return nil, ErrPolicy |
| + } |
| + if _, ok := value.(map[string]any); !ok { |
| + return nil, ErrPolicy |
| + } |
| + out, e := json.Marshal(value) |
| + return out, e |
| +} |
| +func jsonValue(d *json.Decoder) (any, error) { |
| + token, e := d.Token() |
| + if e != nil { |
| + return nil, e |
| + } |
| + delim, ok := token.(json.Delim) |
| + if !ok { |
| + return token, nil |
| + } |
| + switch delim { |
| + case '{': |
| + m := map[string]any{} |
| + for d.More() { |
| + key, e := d.Token() |
| + if e != nil { |
| + return nil, e |
| + } |
| + k, ok := key.(string) |
| + if !ok { |
| + return nil, ErrPolicy |
| + } |
| + if _, ok = m[k]; ok { |
| + return nil, ErrPolicy |
| + } |
| + v, e := jsonValue(d) |
| + if e != nil { |
| + return nil, e |
| + } |
| + m[k] = v |
| + } |
| + _, e = d.Token() |
| + return m, e |
| + case '[': |
| + a := []any{} |
| + for d.More() { |
| + v, e := jsonValue(d) |
| + if e != nil { |
| + return nil, e |
| + } |
| + a = append(a, v) |
| + } |
| + _, e = d.Token() |
| + return a, e |
| + } |
| + return nil, ErrPolicy |
| +} |
| +func validTurnPolicy(raw json.RawMessage) bool { |
| + var value map[string]any |
| + if json.Unmarshal(raw, &value) != nil { |
| + return false |
| + } |
| + // Only non-authority turn parameters are allowed. Adding an SDK field requires |
| + // a deliberate policy revision; unknown fields cannot become hidden overrides. |
| + for key := range value { |
| + switch key { |
| + case "effort", "summary": |
| + default: |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| +func nonsecretJSON(raw json.RawMessage) bool { |
| + var value any |
| + if json.Unmarshal(raw, &value) != nil { |
| + return false |
| + } |
| + var safe func(any) bool |
| + safe = func(v any) bool { |
| + switch x := v.(type) { |
| + case map[string]any: |
| + for k, v := range x { |
| + lower := strings.ToLower(k) |
| + if strings.Contains(lower, "token") || strings.Contains(lower, "secret") || strings.Contains(lower, "password") || strings.Contains(lower, "api_key") || strings.Contains(lower, "apikey") || lower == "authorization" { |
| + return false |
| + } |
| + if !safe(v) { |
| + return false |
| + } |
| + } |
| + case []any: |
| + for _, v := range x { |
| + if !safe(v) { |
| + return false |
| + } |
| + } |
| + } |
| + return true |
| + } |
| + return safe(value) |
| +} |
| +func hashFiles(mounts []Mount, b Binding) ([]fileDigest, error) { |
| + out := make([]fileDigest, 0, len(mounts)) |
| + seen := map[string]bool{} |
| + for _, m := range mounts { |
| + if credentialSource(m.Source, b) { |
| + return nil, ErrPolicy |
| + } |
| + if !m.ReadOnly || !cleanPath(m.Source) || !cleanPath(m.Target) || seen[m.Target] || withinPath(m.Source, b.CredentialHome) || withinPath(m.Source, b.Home) { |
| + return nil, ErrPolicy |
| + } |
| + if !(strings.HasPrefix(m.Target, "/opt/") || strings.HasPrefix(m.Target, "/config/") || strings.HasPrefix(m.Target, "/etc/claude-code/") || strings.HasPrefix(m.Target, "/etc/codex/")) { |
| + return nil, ErrPolicy |
| + } |
| + fd, e := unix.Openat2(unix.AT_FDCWD, m.Source, &unix.OpenHow{Flags: unix.O_RDONLY | unix.O_CLOEXEC | unix.O_NONBLOCK, Resolve: unix.RESOLVE_NO_SYMLINKS | unix.RESOLVE_NO_MAGICLINKS}) |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + f := os.NewFile(uintptr(fd), m.Source) |
| + var stat unix.Stat_t |
| + if unix.Fstat(fd, &stat) != nil || stat.Nlink != 1 { |
| + f.Close() |
| + return nil, ErrPolicy |
| + } |
| + info, e := f.Stat() |
| + if e != nil || !info.Mode().IsRegular() { |
| + f.Close() |
| + return nil, ErrPolicy |
| + } |
| + h := sha256.New() |
| + _, e = io.Copy(h, f) |
| + f.Close() |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + out = append(out, fileDigest{Mount: m, SHA256: hex.EncodeToString(h.Sum(nil))}) |
| + seen[m.Target] = true |
| + } |
| + return out, nil |
| +} |
| +func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| + if !b.VerifiedDedicatedHome() { |
| + return Policy{}, ErrIdentity |
| + } |
| + if in.ProviderVersion == "" || in.LauncherVersion == "" || in.BwrapVersion == "" || len(in.RuntimeFiles) == 0 || len(in.Argv) == 0 || !cleanPath(in.Argv[0]) || len(in.EgressHosts) == 0 { |
| + return Policy{}, ErrPolicy |
| + } |
| + for _, path := range []string{in.Workspace, in.Scratch} { |
| + f, e := pinDirectory(path) |
| + if e != nil { |
| + return Policy{}, ErrPolicy |
| + } |
| + f.Close() |
| + for _, protected := range append([]string{b.Home, b.CredentialHome, b.RuntimeRoot}, in.DeniedPaths...) { |
| + if withinPath(path, protected) || withinPath(protected, path) { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| + } |
| + if withinPath(in.Workspace, in.Scratch) || withinPath(in.Scratch, in.Workspace) { |
| + return Policy{}, ErrPolicy |
| + } |
| + settings, e := canonical(in.Settings) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + mcp, e := canonical(in.MCP) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + thread, e := canonical(in.ThreadPolicy) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + turn, e := canonical(in.TurnPolicy) |
| + if e != nil || !validTurnPolicy(turn) { |
| + return Policy{}, ErrPolicy |
| + } |
| + for _, raw := range []json.RawMessage{settings, mcp, thread, turn} { |
| + if !nonsecretJSON(raw) { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| + env := map[string]string{"LANG": "C.UTF-8"} |
| + if b.Provider == "codex" { |
| + env["CODEX_HOME"] = "/home/runner" |
| + } else { |
| + env["CLAUDE_CONFIG_DIR"] = "/home/runner" |
| + env["CLAUDE_SECURESTORAGE_CONFIG_DIR"] = "/home/runner" |
| + env["CLAUDE_TMPDIR"] = "/tmp" |
| + env["CLAUDE_CODE_DISABLE_AUTO_UPDATE"] = "1" |
| + } |
| + for k, v := range in.Env { |
| + if (k != "LANG" && k != "LC_ALL" && k != "TERM") || strings.ContainsRune(v, 0) { |
| + return Policy{}, ErrPolicy |
| + } |
| + env[k] = v |
| + } |
| + files, e := hashFiles(in.RuntimeFiles, b) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + instructions, e := hashFiles(in.InstructionFiles, b) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + denied := append([]string(nil), in.DeniedPaths...) |
| + denied = append(denied, b.CredentialHome, "/home/runner") |
| + sort.Strings(denied) |
| + for _, path := range denied { |
| + if !cleanPath(path) { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| + binaryPresent := false |
| + for _, file := range files { |
| + if file.Mount.Target == in.Argv[0] { |
| + binaryPresent = true |
| + } |
| + } |
| + if !binaryPresent { |
| + return Policy{}, ErrPolicy |
| + } |
| + hosts := append([]string(nil), in.EgressHosts...) |
| + sort.Strings(hosts) |
| + for i, h := range hosts { |
| + if _, e := netip.ParseAddr(h); e == nil { |
| + return Policy{}, ErrPolicy |
| + } |
| + if h == "" || strings.ContainsAny(h, "/:*@ \t\n") || h != strings.ToLower(h) || (i > 0 && h == hosts[i-1]) { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| + tools := append([]string(nil), in.Tools...) |
| + for i, v := range tools { |
| + if v == "" { |
| + return Policy{}, ErrPolicy |
| + } |
| + for _, prior := range tools[:i] { |
| + if prior == v { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| + } |
| + fullEnv := map[string]string{"PATH": "/usr/bin:/bin:/opt", "HOME": "/home/runner", "TMPDIR": "/tmp"} |
| + for k, v := range env { |
| + fullEnv[k] = v |
| + } |
| + for _, k := range []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"} { |
| + fullEnv[k] = "http://127.0.0.1:18080" |
| + } |
| + m := effectiveManifest{Version: PolicyVersion, BindingID: b.ID, Provider: b.Provider, AccountID: b.AccountID, CredentialHome: b.CredentialHome, Identity: b.Expected, ProviderVersion: in.ProviderVersion, LauncherVersion: in.LauncherVersion, BwrapVersion: in.BwrapVersion, Argv: append([]string(nil), in.Argv...), Env: fullEnv, Files: files, DeniedPaths: denied, EgressHosts: hosts, Tools: tools, Settings: settings, MCP: mcp, ThreadPolicy: thread, TurnPolicy: turn, Workspace: in.Workspace, Scratch: in.Scratch, RuntimeHome: b.Home, Instructions: instructions, HooksDisabled: true, PluginsDisabled: true, TurnOverridesOmitted: true, MaskedDirectories: []string{"/etc/claude-code", "/etc/codex"}, Proxy: "http://127.0.0.1:18080"} |
| + m.OuterMounts = []Mount{{Source: "/usr", Target: "/usr", ReadOnly: true}, {Source: in.Workspace, Target: "/workspace"}, {Source: b.Home, Target: "/home/runner"}, {Source: in.Scratch, Target: "/tmp"}} |
| + m.GeneratedMounts = generatedMounts(b) |
| + m.NamespaceArgs = NamespaceArguments() |
| + raw, manifestHash, e := hashJSON(m) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + _, instructionHash, _ := hashJSON(instructions) |
| + // Only validated attempt directories become roles. Account paths, protected |
| + // paths, argv, binaries and every other runtime input remain exact. |
| + m = policyTemplate(m) |
| + _, policyHash, e := hashJSON(m) |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + dir, e := b.provenance.runtimeDir() |
| + if e != nil { |
| + return Policy{}, e |
| + } |
| + defer dir.Close() |
| + if atomicPrivate(dir, "equipo-settings.json", settings) != nil || atomicPrivate(dir, "equipo-mcp.json", mcp) != nil { |
| + return Policy{}, ErrPolicy |
| + } |
| + mounts := append(append([]Mount(nil), in.RuntimeFiles...), in.InstructionFiles...) |
| + mounts = append(mounts, generatedMounts(b)...) |
| + return Policy{Hash: policyHash, ManifestHash: manifestHash, InstructionHash: instructionHash, Manifest: raw, Mounts: mounts, Env: env, Settings: settings, MCP: mcp, ThreadPolicy: thread, TurnPolicy: turn}, nil |
| +} |
| + |
| +type ConfigReadback struct { |
| + Settings, MCP, ThreadPolicy, TurnPolicy json.RawMessage |
| + Layers []string |
| + HooksDisabled, PluginsDisabled, RemoteControl bool |
| +} |
| + |
| +func (p Policy) ValidateReadback(r ConfigReadback) error { |
| + var m effectiveManifest |
| + if json.Unmarshal(p.Manifest, &m) != nil { |
| + return ErrPolicy |
| + } |
| + layers := []string{"equipo"} |
| + for _, file := range m.Files { |
| + if strings.HasPrefix(file.Mount.Target, "/etc/claude-code/") || strings.HasPrefix(file.Mount.Target, "/etc/codex/") { |
| + layers = append(layers, "managed:"+file.Mount.Target) |
| + } |
| + } |
| + sort.Strings(layers) |
| + actual := append([]string(nil), r.Layers...) |
| + sort.Strings(actual) |
| + if r.RemoteControl || !r.HooksDisabled || !r.PluginsDisabled || !reflect.DeepEqual(actual, layers) { |
| + return ErrPolicy |
| + } |
| + for _, pair := range [][2]json.RawMessage{{p.Settings, r.Settings}, {p.MCP, r.MCP}, {p.ThreadPolicy, r.ThreadPolicy}, {p.TurnPolicy, r.TurnPolicy}} { |
| + a, e := canonical(pair[0]) |
| + if e != nil { |
| + return e |
| + } |
| + b, e := canonical(pair[1]) |
| + if e != nil || !bytes.Equal(a, b) { |
| + return ErrPolicy |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// AttestLaunch binds a concrete attempt to the already built policy. Containment |
| +// persists this hash separately from the reusable policy certificate hash. |
| +func AttestLaunch(l Launch, argv []string) (string, error) { |
| + p := l.Policy |
| + if p.ManifestHash == "" { |
| + // Legacy check jobs have no direct-provider manifest during the cutover. |
| + if l.Binding.DedicatedHome { |
| + return "", ErrPolicy |
| + } |
| + _, h, e := hashJSON(struct { |
| + Launch Launch |
| + Argv []string |
| + }{l, argv}) |
| + return h, e |
| + } |
| + if !l.Binding.VerifiedDedicatedHome() || l.Binding.provenance.validateLaunch() != nil { |
| + return "", ErrIdentity |
| + } |
| + if digest(p.Manifest) != p.ManifestHash { |
| + return "", ErrPolicy |
| + } |
| + var m effectiveManifest |
| + if json.Unmarshal(p.Manifest, &m) != nil { |
| + return "", ErrPolicy |
| + } |
| + if l.AttemptKey == "" || m.Workspace != l.Workspace || m.RuntimeHome != l.Binding.Home || m.CredentialHome != l.Binding.CredentialHome || m.BindingID != l.Binding.ID || m.Identity != l.Binding.Expected || m.Provider != l.Selection.Provider || m.AccountID != l.Selection.AccountID || !reflect.DeepEqual(m.Argv, argv) { |
| + return "", ErrIdentity |
| + } |
| + for _, pair := range [][2]json.RawMessage{{m.Settings, p.Settings}, {m.MCP, p.MCP}, {m.ThreadPolicy, p.ThreadPolicy}, {m.TurnPolicy, p.TurnPolicy}} { |
| + if !bytes.Equal(pair[0], pair[1]) { |
| + return "", ErrPolicy |
| + } |
| + } |
| + mounts := []Mount{} |
| + for _, f := range append(append([]fileDigest(nil), m.Files...), m.Instructions...) { |
| + mounts = append(mounts, f.Mount) |
| + } |
| + expectedMounts := append(mounts, generatedMounts(l.Binding)...) |
| + if !reflect.DeepEqual(expectedMounts, p.Mounts) { |
| + return "", ErrPolicy |
| + } |
| + expectedEnv := map[string]string{} |
| + for k, v := range m.Env { |
| + switch k { |
| + case "PATH", "HOME", "TMPDIR", "HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy": |
| + default: |
| + expectedEnv[k] = v |
| + } |
| + } |
| + if !reflect.DeepEqual(expectedEnv, p.Env) { |
| + return "", ErrPolicy |
| + } |
| + current, e := hashFiles(mounts, l.Binding) |
| + if e != nil || !reflect.DeepEqual(current, append(append([]fileDigest(nil), m.Files...), m.Instructions...)) { |
| + return "", ErrPolicy |
| + } |
| + dir, e := l.Binding.provenance.runtimeDir() |
| + if e != nil { |
| + return "", e |
| + } |
| + defer dir.Close() |
| + for name, want := range map[string][]byte{"equipo-settings.json": p.Settings, "equipo-mcp.json": p.MCP} { |
| + raw, e := readPrivate(dir, name) |
| + if e != nil || !bytes.Equal(raw, want) { |
| + return "", ErrPolicy |
| + } |
| + } |
| + _, instructionHash, _ := hashJSON(m.Instructions) |
| + if instructionHash != p.InstructionHash { |
| + return "", ErrPolicy |
| + } |
| + m = policyTemplate(m) |
| + _, policyHash, _ := hashJSON(m) |
| + if policyHash != p.Hash { |
| + return "", ErrPolicy |
| + } |
| + _, hash, e := hashJSON(struct { |
| + ManifestHash, AttemptKey, ResumeSessionID string |
| + Selection Selection |
| + }{p.ManifestHash, l.AttemptKey, l.ResumeSessionID, l.Selection}) |
| + return hash, e |
| +} |
| +func (p Policy) ValidateNetwork(name string, hosts []string) error { |
| + if p.ManifestHash == "" { |
| + return nil |
| + } |
| + var m effectiveManifest |
| + if json.Unmarshal(p.Manifest, &m) != nil { |
| + return ErrPolicy |
| + } |
| + actual := append([]string(nil), hosts...) |
| + sort.Strings(actual) |
| + if m.Provider != name || !reflect.DeepEqual(actual, m.EgressHosts) { |
| + return ErrPolicy |
| + } |
| + return nil |
| +} |
| +func generatedMounts(b Binding) []Mount { |
| + return []Mount{{Source: filepath.Join(b.Home, "equipo-settings.json"), Target: SettingsPath, ReadOnly: true}, {Source: filepath.Join(b.Home, "equipo-mcp.json"), Target: MCPPath, ReadOnly: true}} |
| +} |
| + |
| +// ValidateRuntimeBinaries requires the host's actual launcher and bubblewrap |
| +// binaries to be among the files certified by the adapter's policy inputs. |
| +func (p Policy) ValidateRuntimeBinaries(paths ...string) error { |
| + if p.ManifestHash == "" { |
| + return nil |
| + } |
| + var m effectiveManifest |
| + if json.Unmarshal(p.Manifest, &m) != nil { |
| + return ErrPolicy |
| + } |
| + for _, path := range paths { |
| + found := false |
| + for _, f := range m.Files { |
| + if f.Mount.Source == path { |
| + found = true |
| + } |
| + } |
| + if !found { |
| + return ErrPolicy |
| + } |
| + } |
| + return nil |
| +} |
| +func (p Policy) ValidateFileDigest(path, hash string) error { |
| + if p.ManifestHash == "" { |
| + return nil |
| + } |
| + var m effectiveManifest |
| + if json.Unmarshal(p.Manifest, &m) != nil { |
| + return ErrPolicy |
| + } |
| + for _, f := range append(m.Files, m.Instructions...) { |
| + if f.Mount.Source == path && f.SHA256 == hash { |
| + return nil |
| + } |
| + } |
| + if path == filepath.Join(m.RuntimeHome, "equipo-settings.json") && digest(m.Settings) == hash { |
| + return nil |
| + } |
| + if path == filepath.Join(m.RuntimeHome, "equipo-mcp.json") && digest(m.MCP) == hash { |
| + return nil |
| + } |
| + return ErrPolicy |
| +} |
| + |
| +// NamespaceArguments is shared with containment so changes to isolation flags |
| +// also change the reusable policy hash. |
| +func NamespaceArguments() []string { |
| + return []string{"--unshare-user", "--unshare-pid", "--unshare-ipc", "--unshare-uts", "--unshare-cgroup", "--unshare-net", "--die-with-parent", "--new-session", "--as-pid-1", "--cap-drop", "ALL", "--json-status-fd", "3"} |
| +} |
| +func policyTemplate(m effectiveManifest) effectiveManifest { |
| + m.OuterMounts = append([]Mount(nil), m.OuterMounts...) |
| + m.GeneratedMounts = append([]Mount(nil), m.GeneratedMounts...) |
| + for i := range m.OuterMounts { |
| + switch m.OuterMounts[i].Target { |
| + case "/workspace": |
| + m.OuterMounts[i].Source = "$WORKSPACE" |
| + case "/home/runner": |
| + m.OuterMounts[i].Source = "$RUNTIME_HOME" |
| + case "/tmp": |
| + m.OuterMounts[i].Source = "$SCRATCH" |
| + } |
| + } |
| + for i := range m.GeneratedMounts { |
| + m.GeneratedMounts[i].Source = filepath.Join("$RUNTIME_HOME", filepath.Base(m.GeneratedMounts[i].Source)) |
| + } |
| + m.Workspace = "$WORKSPACE" |
| + m.Scratch = "$SCRATCH" |
| + m.RuntimeHome = "$RUNTIME_HOME" |
| + m.Instructions = nil |
| + return m |
| +} |
| + |
| +func credentialSource(path string, b Binding) bool { |
| + switch filepath.Base(path) { |
| + case "auth.json", ".credentials.json", IdentityFile: |
| + return true |
| + } |
| + if b.provenance == nil { |
| + return true |
| + } |
| + rules := b.provenance.rules |
| + if rules.RefusesPath(path) || refusedMountAlias(path, rules) { |
| + return true |
| + } |
| + for parent := filepath.Dir(path); parent != "/"; parent = filepath.Dir(parent) { |
| + info, e := os.Stat(parent) |
| + if e != nil || rules.refusedInode(info) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
diff --git a/internal/runner/provider/policy_test.go b/internal/runner/provider/policy_test.go| new file mode 100644 |
| index 00000000..1622481f |
| --- /dev/null |
| +++ b/internal/runner/provider/policy_test.go |
| @@ -0,0 +1,312 @@ |
| +package provider |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func policyFixture(t *testing.T) (Binding, PolicyInputs) { |
| + t.Helper() |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + binary := filepath.Join(t.TempDir(), "codex") |
| + writeFake(t, binary, "fake binary") |
| + companion := filepath.Join(filepath.Dir(binary), "helper") |
| + writeFake(t, companion, "fake helper") |
| + work, scratch := filepath.Join(t.TempDir(), "work"), filepath.Join(t.TempDir(), "scratch") |
| + os.Mkdir(work, 0700) |
| + os.Mkdir(scratch, 0700) |
| + return l.Binding(), PolicyInputs{RuntimeFiles: []Mount{{Source: binary, Target: "/opt/codex", ReadOnly: true}, {Source: companion, Target: "/opt/helper", ReadOnly: true}}, DeniedPaths: []string{b.Home}, EgressHosts: []string{"chatgpt.com"}, ProviderVersion: "0.165.0", LauncherVersion: "2", BwrapVersion: "0.11.0", Settings: json.RawMessage(`{"sandbox":"read-only"}`), MCP: json.RawMessage(`{"servers":{}}`), ThreadPolicy: json.RawMessage(`{"start":{"permissions":"probe"},"resume":{"permissions":"probe"}}`), TurnPolicy: json.RawMessage(`{}`), Tools: []string{"read", "shell"}, Argv: []string{"/opt/codex", "app-server"}, Workspace: work, Scratch: scratch} |
| +} |
| +func mustPolicy(t *testing.T, b Binding, in PolicyInputs) Policy { |
| + t.Helper() |
| + p, e := BuildPolicy(b, in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + return p |
| +} |
| +func TestEffectivePolicyHash(t *testing.T) { |
| + for _, field := range []string{"binary", "settings", "routing", "tools", "mcp", "managed", "env", "mount", "thread-start", "thread-resume", "turn", "provider-version", "launcher-version", "bwrap-version", "argv", "denied"} { |
| + t.Run(field, func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + before := mustPolicy(t, b, in) |
| + switch field { |
| + case "binary": |
| + writeFake(t, in.RuntimeFiles[0].Source, "different binary") |
| + case "settings": |
| + in.Settings = json.RawMessage(`{"sandbox":"workspace-write"}`) |
| + case "routing": |
| + in.EgressHosts = append(in.EgressHosts, "refresh.example") |
| + case "tools": |
| + in.Tools = append(in.Tools, "image") |
| + case "mcp": |
| + in.MCP = json.RawMessage(`{"servers":{"equipo":{"command":"/opt/mcp"}}}`) |
| + case "managed": |
| + file := filepath.Join(t.TempDir(), "managed.json") |
| + writeFake(t, file, `{}`) |
| + in.RuntimeFiles = append(in.RuntimeFiles, Mount{Source: file, Target: "/etc/codex/managed.json", ReadOnly: true}) |
| + case "env": |
| + in.Env = map[string]string{"LANG": "en_IE.UTF-8"} |
| + case "mount": |
| + in.RuntimeFiles[1].Target = "/opt/other" |
| + case "thread-start": |
| + in.ThreadPolicy = json.RawMessage(`{"start":{"permissions":"other"},"resume":{"permissions":"probe"}}`) |
| + case "thread-resume": |
| + in.ThreadPolicy = json.RawMessage(`{"start":{"permissions":"probe"},"resume":{"permissions":"other"}}`) |
| + case "turn": |
| + in.TurnPolicy = json.RawMessage(`{"effort":"high"}`) |
| + case "provider-version": |
| + in.ProviderVersion = "new" |
| + case "launcher-version": |
| + in.LauncherVersion = "new" |
| + case "bwrap-version": |
| + in.BwrapVersion = "new" |
| + case "argv": |
| + in.Argv = append(in.Argv, "--flag") |
| + case "denied": |
| + in.DeniedPaths = append(in.DeniedPaths, "/protected") |
| + } |
| + after := mustPolicy(t, b, in) |
| + if before.Hash == after.Hash || before.ManifestHash == after.ManifestHash { |
| + t.Fatal("manifest change not hashed") |
| + } |
| + }) |
| + } |
| + t.Run("canonical and concrete", func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + in.Settings = json.RawMessage("{ \"sandbox\" : \"read-only\" }") |
| + q := mustPolicy(t, b, in) |
| + if p.Hash != q.Hash { |
| + t.Fatal("JSON not canonical") |
| + } |
| + in.Workspace = filepath.Join(t.TempDir(), "next") |
| + os.Mkdir(in.Workspace, 0700) |
| + q = mustPolicy(t, b, in) |
| + if p.Hash != q.Hash || p.ManifestHash == q.ManifestHash { |
| + t.Fatal("workspace role or concrete hash wrong") |
| + } |
| + if strings.Contains(string(p.Manifest), "fake-one") { |
| + t.Fatal("credential leaked") |
| + } |
| + }) |
| + t.Run("account exact", func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + other, _ := policyFixture(t) |
| + q := mustPolicy(t, other, in) |
| + if p.Hash == q.Hash { |
| + t.Fatal("different account home reused certificate") |
| + } |
| + }) |
| + t.Run("instructions separate", func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + path := filepath.Join(t.TempDir(), "instructions") |
| + writeFake(t, path, "one") |
| + in.InstructionFiles = []Mount{{Source: path, Target: "/config/instructions", ReadOnly: true}} |
| + p := mustPolicy(t, b, in) |
| + writeFake(t, path, "two") |
| + q := mustPolicy(t, b, in) |
| + if p.Hash != q.Hash || p.InstructionHash == q.InstructionHash || p.ManifestHash == q.ManifestHash { |
| + t.Fatal("instructions not separately hashed") |
| + } |
| + }) |
| +} |
| +func TestUnexpectedConfigLayer(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + good := ConfigReadback{Settings: in.Settings, MCP: in.MCP, ThreadPolicy: in.ThreadPolicy, TurnPolicy: in.TurnPolicy, Layers: []string{"equipo"}, HooksDisabled: true, PluginsDisabled: true} |
| + if e := p.ValidateReadback(good); e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, kind := range []string{"user", "project", "managed", "remote", "ignored", "hooks", "plugins", "turn override"} { |
| + t.Run(kind, func(t *testing.T) { |
| + bad := good |
| + switch kind { |
| + case "remote": |
| + bad.RemoteControl = true |
| + case "ignored": |
| + bad.Settings = json.RawMessage(`{}`) |
| + case "hooks": |
| + bad.HooksDisabled = false |
| + case "plugins": |
| + bad.PluginsDisabled = false |
| + case "turn override": |
| + bad.TurnPolicy = json.RawMessage(`{"sandboxPolicy":{}}`) |
| + default: |
| + bad.Layers = append([]string{"equipo"}, kind) |
| + } |
| + if p.ValidateReadback(bad) == nil { |
| + t.Fatal("unexpected config accepted") |
| + } |
| + }) |
| + } |
| + for _, key := range []string{"ANTHROPIC_API_KEY", "OPENAI_API_KEY", "HTTPS_PROXY", "SSH_AUTH_SOCK", "DBUS_SESSION_BUS_ADDRESS", "PASEO_HOME", "CLAUDE_CODE_OAUTH_TOKEN"} { |
| + t.Run(key, func(t *testing.T) { |
| + t.Setenv(key, "parent-secret") |
| + p := mustPolicy(t, b, in) |
| + if strings.Contains(string(p.Manifest), "parent-secret") { |
| + t.Fatal("inherited environment") |
| + } |
| + bad := in |
| + bad.Env = map[string]string{key: "injected"} |
| + if _, e := BuildPolicy(b, bad); e == nil { |
| + t.Fatal("injected environment accepted") |
| + } |
| + }) |
| + } |
| + for _, key := range []string{"sandboxPolicy", "approvalPolicy", "permissions", "permissionProfile", "cwd", "model"} { |
| + bad := in |
| + bad.TurnPolicy = json.RawMessage(`{"` + key + `":"override"}`) |
| + if _, e := BuildPolicy(b, bad); e == nil { |
| + t.Fatalf("turn override %s accepted", key) |
| + } |
| + } |
| + forged := b |
| + forged.provenance = nil |
| + if _, e := BuildPolicy(forged, in); e == nil { |
| + t.Fatal("unverified binding accepted") |
| + } |
| +} |
| + |
| +func TestEffectivePolicyLaunchAttestation(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + l := Launch{AttemptKey: "attempt", Workspace: in.Workspace, Binding: b, Policy: p, Selection: Selection{Provider: b.Provider, AccountID: b.AccountID, Model: "model", Family: "gpt", ConnectionID: "person-connection"}} |
| + hash, e := AttestLaunch(l, in.Argv) |
| + if e != nil || hash == "" || hash == p.Hash { |
| + t.Fatal("missing concrete attempt hash", e) |
| + } |
| + for _, kind := range []string{"argv", "workspace", "env", "mount", "binary", "account", "manifest", "manifesthash", "policyhash"} { |
| + t.Run(kind, func(t *testing.T) { |
| + bad := l |
| + argv := append([]string(nil), in.Argv...) |
| + switch kind { |
| + case "argv": |
| + argv = append(argv, "--override") |
| + case "workspace": |
| + bad.Workspace = "/different" |
| + case "env": |
| + bad.Policy.Env = map[string]string{"LANG": "bad"} |
| + case "mount": |
| + bad.Policy.Mounts = nil |
| + case "binary": |
| + writeFake(t, in.RuntimeFiles[0].Source, "changed") |
| + defer writeFake(t, in.RuntimeFiles[0].Source, "fake binary") |
| + case "account": |
| + bad.Selection.AccountID = "other" |
| + case "manifest": |
| + bad.Policy.Manifest = json.RawMessage(`{}`) |
| + case "manifesthash": |
| + bad.Policy.ManifestHash = "changed" |
| + case "policyhash": |
| + bad.Policy.Hash = "changed" |
| + } |
| + if _, e := AttestLaunch(bad, argv); e == nil { |
| + t.Fatal("changed launch accepted") |
| + } |
| + }) |
| + } |
| + if e := p.ValidateNetwork(b.Provider, []string{"other.example"}); e == nil { |
| + t.Fatal("egress drift accepted") |
| + } |
| +} |
| + |
| +func TestUnexpectedConfigInputs(t *testing.T) { |
| + for _, kind := range []string{"duplicate JSON", "secret JSON", "missing binary", "writable mount", "unprotected role", "duplicate tool", "symlink binary", "network number"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + switch kind { |
| + case "duplicate JSON": |
| + in.Settings = json.RawMessage(`{"a":1,"a":2}`) |
| + case "secret JSON": |
| + in.MCP = json.RawMessage(`{"apiKey":"secret"}`) |
| + case "missing binary": |
| + in.RuntimeFiles = nil |
| + case "writable mount": |
| + in.RuntimeFiles[0].ReadOnly = false |
| + case "unprotected role": |
| + in.Workspace = b.CredentialHome |
| + case "duplicate tool": |
| + in.Tools = append(in.Tools, in.Tools[0]) |
| + case "symlink binary": |
| + alias := filepath.Join(t.TempDir(), "alias") |
| + os.Symlink(in.RuntimeFiles[0].Source, alias) |
| + in.RuntimeFiles[0].Source = alias |
| + case "network number": |
| + in.EgressHosts = []string{"127.0.0.1"} |
| + } |
| + if _, e := BuildPolicy(b, in); e == nil { |
| + t.Fatal("unsafe policy input accepted") |
| + } |
| + }) |
| + } |
| +} |
| +func TestEffectivePolicyPreflightLaunch(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + _, in := policyFixture(t) |
| + e := l.Preflight(context.Background(), func(ctx context.Context, b Binding) (Identity, error) { |
| + p, e := BuildPolicy(b, in) |
| + if e != nil { |
| + return Identity{}, e |
| + } |
| + _, e = AttestLaunch(Launch{AttemptKey: "auth-check", Binding: b, Policy: p, Workspace: in.Workspace, Selection: Selection{Provider: b.Provider, AccountID: b.AccountID}}, in.Argv) |
| + return b.Expected, e |
| + }) |
| + if e != nil { |
| + t.Fatal("preflight could not launch status check", e) |
| + } |
| +} |
| + |
| +func TestEffectivePolicyHostBinary(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + if p.ValidateRuntimeBinaries(in.RuntimeFiles[0].Source) != nil { |
| + t.Fatal("hashed binary rejected") |
| + } |
| + if p.ValidateRuntimeBinaries("/missing/binary") == nil { |
| + t.Fatal("unhashed host binary accepted") |
| + } |
| +} |
| + |
| +func TestEffectivePolicyManifestBoundary(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + var value map[string]any |
| + json.Unmarshal(p.Manifest, &value) |
| + if value["OuterMounts"] == nil || value["NamespaceArgs"] == nil || value["GeneratedMounts"] == nil { |
| + t.Fatal("outer mount policy missing from manifest") |
| + } |
| + if p.ValidateFileDigest(in.RuntimeFiles[0].Source, "changed") == nil { |
| + t.Fatal("changed pinned file digest accepted") |
| + } |
| +} |
| + |
| +func TestPrivateHomeRejectsCredentialMount(t *testing.T) { |
| + b, in := policyFixture(t) |
| + fake := filepath.Join(t.TempDir(), "other-home") |
| + if e := os.Mkdir(fake, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + secret := filepath.Join(fake, "auth.json") |
| + writeFake(t, secret, `{"token":"other-fake-login"}`) |
| + in.RuntimeFiles = append(in.RuntimeFiles, Mount{Source: secret, Target: "/config/credential", ReadOnly: true}) |
| + if _, e := BuildPolicy(b, in); e == nil { |
| + t.Fatal("credential source entered public manifest") |
| + } |
| + alias := filepath.Join(t.TempDir(), "aliased-runtime") |
| + if e := os.Link(secret, alias); e != nil { |
| + t.Fatal(e) |
| + } |
| + in.RuntimeFiles[len(in.RuntimeFiles)-1].Source = alias |
| + if _, e := BuildPolicy(b, in); e == nil { |
| + t.Fatal("credential inode alias entered public manifest") |
| + } |
| +} |
diff --git a/internal/runner/provider/types.go b/internal/runner/provider/types.go| index f01b8916..dc210fce 100644 |
| --- a/internal/runner/provider/types.go |
| +++ b/internal/runner/provider/types.go |
| @@ -16,7 +16,10 @@ type Selection struct { |
| type Binding struct { |
| ID, Home, AccountID, Provider string |
| - DedicatedHome bool |
| + DedicatedHome bool `json:"-"` |
| + Expected Identity |
| + CredentialHome, RuntimeRoot string |
| + provenance *AccountLease |
| } |
| // NetworkContract is installed by the runner, never supplied by a permission answer. |
| @@ -27,7 +30,9 @@ type NetworkContract struct { |
| } |
| type Identity struct { |
| - AccountID, HomeID, ProviderVersion string |
| + AccountID string `json:"account_id"` |
| + HomeID string `json:"home_id"` |
| + ProviderVersion string `json:"provider_version"` |
| } |
| type Mount struct { |
| @@ -36,11 +41,13 @@ type Mount struct { |
| } |
| type Policy struct { |
| - Hash string |
| - Manifest json.RawMessage |
| - Mounts []Mount |
| - Env map[string]string |
| - Settings, MCP json.RawMessage |
| + Hash string |
| + ManifestHash, InstructionHash string |
| + ThreadPolicy, TurnPolicy json.RawMessage |
| + Manifest json.RawMessage |
| + Mounts []Mount |
| + Env map[string]string |
| + Settings, MCP json.RawMessage |
| } |
| type Launch struct { |
| @@ -85,6 +92,8 @@ type Process interface { |
| } |
| // ProcessHost owns the namespace and the lifetime of its processes. |
| +// Start receives the attempt lifetime context. Cancelling it kills the attempt; |
| +// callers must not use a short preflight or startup-only context. |
| type ProcessHost interface { |
| Start(context.Context, Launch, []string) (Process, error) |
| } |