fix: preserve refreshed logins and attest every direct launch
10 files changed,
+2,264
−62
docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md+1,447 −0internal/runner/connections.go+13 −1internal/runner/connections_test.go+30 −0internal/runner/containment/egress_test.go+63 −16internal/runner/containment/linux.go+7 −2internal/runner/containment/linux_test.go+124 −1internal/runner/provider/accounts.go+140 −18internal/runner/provider/accounts_test.go+286 −2internal/runner/provider/policy.go+52 −22internal/runner/provider/policy_test.go+102 −0
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 a57b4546..9f9f38de 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| @@ -6443,3 +6443,1450 @@ No UI or prose runtime strings were added, and copy.go is unchanged. New interna |
| - 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. |
| + |
| + |
| +## Task 4 fix round 1: refreshed logins and direct launch attestation |
| + |
| +Status: DONE. All seven findings and the neutral-path cleanup are addressed. |
| +Commit subject: `fix: preserve refreshed logins and attest every direct launch` (61 characters). |
| +Branch: `plan-2b`. Work stayed in `/home/paulca/amadan.net/oficina/equipo-plan-2b`. |
| + |
| +### What changed |
| + |
| +A harness login update now returns `ErrRefreshPending`. Preflight refuses to restage while that update is pending, including when the caller has not called Validate first. The runtime login stays intact until CommitRefresh verifies the observed identity and atomically commits it to the dedicated source. A successful commit accepts that runtime generation but still requires a fresh preflight before another turn. Tests cover refresh both between turns and during an active turn, failed maintenance, and a changed observed identity. |
| + |
| +Containment is sticky for the lease. Active source-generation changes, replaced directories, unsafe source/runtime login files, and changed identity stop admission. Restoring the original files does not clear containment. This also applies when Preflight detects source or identity tampering directly. Contained leases lose dedicated-home provenance and cannot begin another turn. Runtime identity metadata is checked as well as source metadata; actual provider identity still comes from the adapter's no-prompt probe during CommitRefresh and Preflight. |
| + |
| +Manager.Start requires a manifest for every nonempty Selection.Provider before it creates attempt state or forks. AttestLaunch independently rejects legacy attestation for a selected provider. Provider-less check jobs retain their existing legacy manifest path. |
| + |
| +Generated settings and MCP files now live in a separate, pinned, lease-owned config directory. Only their read-only file mounts reach the namespace at the fixed config paths. The writable runtime home no longer contains them. The manifest includes the concrete config directory and normalizes its lease-owned role in the reusable policy hash. Close removes this directory. Runtime/managed/instruction sources inside the writable workspace or supplied scratch are rejected to prevent another writable alias. |
| + |
| +BuildPolicy retains a private copy of the manifest on the lease. BeginTurn checks its generated and managed/runtime source contents again. Adapters can call AccountLease.ValidatePolicy before a resume; Policy.ValidateSources also exposes the file check and is used by AttestLaunch. Config directory replacement or loss of private permissions is rejected. The existing pinned-file digest check remains the final check after mount descriptors are retained. |
| + |
| +DefaultHomeRules resolves the effective UID through os/user.LookupId, which works with CGO_ENABLED=0. It fails closed if the lookup fails or has no absolute home. HOME no longer selects the default refusal paths. Inherited CODEX_HOME and CLAUDE_CONFIG_DIR paths and their resolved aliases are also refused. loadDirectBindings uses these same rules and rejects conflicting LocalID/PersonID ownership indexed by ProviderHome, Expected.HomeID and provider/account identity. Existing model ordering is preserved. |
| + |
| +The egress fixtures now create fake leases and complete BuildPolicy manifests with the actual bwrap and runner binaries. TestNamespaceDirectPolicy reaches a running namespace and verifies config cannot be written there. TestNamespaceDirectPolicySwapBeforePin swaps the settings file through an unexported test hook immediately after attestation; Start rejects the pinned digest. Admission tests separately exercise changed binaries, argv, environment and mounts through Manager.Start. The hard-coded developer home in the ZeroSub path-only test is now `/home/example`. |
| + |
| +### Files |
| + |
| +- `internal/runner/provider/accounts.go`, `accounts_test.go`: refresh state, containment latch, trusted home rules, config directory ownership and turn/resume checks. |
| +- `internal/runner/provider/policy.go`, `policy_test.go`: config staging, source validation, writable-alias refusal, direct attestation and regression tests. |
| +- `internal/runner/connections.go`, `connections_test.go`: unique account/home ownership across configured people and LocalIDs. |
| +- `internal/runner/containment/linux.go`, `linux_test.go`, `egress_test.go`: mandatory direct manifests, deterministic attestation-to-pin test hook, running direct namespace and converted egress fixtures. |
| +- This appended controller section and the appended local task report. `mounts.go` was mutated for verification and restored byte-for-byte; it has no final change. |
| + |
| +### Interpretations |
| + |
| +The binding controller ruling takes precedence over the original active-turn runtime mutation expectation: a regular runtime login update with matching enrolled metadata is provisionally refresh-pending even during a turn. CommitRefresh must then observe the same provider identity, and Preflight must succeed before another turn or resume. A changed observed identity latches containment. No token is parsed as an independent identity attestation. |
| + |
| +The original brief explicitly permits a new source credential generation with the same identity between turns after fresh preflight. That behavior remains. A source generation change during an active turn, a source directory/file replacement that violates the pinned/private file rules, or an identity change is contained. Source login files that cannot be safely read are also contained. |
| + |
| +Account identity uniqueness is scoped by provider and AccountID, since provider IDs are separate namespaces. ProviderHome and Equipo HomeID uniqueness apply across all configured bindings. Multiple models for the same LocalID/person/account remain valid. |
| + |
| +The task's explicit instructions override generic writing-pipeline delegation, copy-review and handoff workflows. No copy-review skill/server, model call, helper agent or `.claude/HANDOFF.md` was used. All login files used in tests were owned fake fixtures under on-disk test scratch. No real credential home was created or opened, no provider was contacted, and no machine was enrolled. |
| + |
| +### RED evidence |
| + |
| +Commands ran from `/home/paulca/amadan.net/oficina/equipo-plan-2b` with on-disk TMPDIR `/home/paulca/t/e2b` and default Go caches. Tests were added before each finding's implementation. The direct-namespace coverage finding added a test-only interleaving hook; its initial RED was the missing hook field. The other findings produced behavioral failures before implementation. |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner -run 'TestAccountRefreshPending|TestAccountContainmentLatched|TestAccountHomeDefaultsIgnoreEnvironment|TestAccountHomeConfiguredDiscoveryAliases' -count=1 |
| +``` |
| + |
| +Exit 1: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshPending (0.28s) |
| + --- FAIL: TestAccountRefreshPending/false (0.14s) |
| + accounts_test.go:451: refresh must be pending: provider_preflight_required |
| + --- FAIL: TestAccountRefreshPending/true (0.14s) |
| + accounts_test.go:451: refresh must be pending: provider_account_containment |
| +--- FAIL: TestAccountContainmentLatched (1.06s) |
| + --- FAIL: TestAccountContainmentLatched/source (0.21s) |
| + accounts_test.go:487: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/identity (0.20s) |
| + accounts_test.go:487: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.21s) |
| + accounts_test.go:482: active tampering not contained: <nil> |
| + accounts_test.go:487: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/symlink (0.22s) |
| + accounts_test.go:487: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/nonregular (0.22s) |
| + accounts_test.go:487: containment not latched: <nil> |
| +--- FAIL: TestAccountHomeDefaultsIgnoreEnvironment (0.00s) |
| + accounts_test.go:497: passwd home accepted with changed HOME |
| +FAIL |
| +rastrillo-budget/v1 ran 1.344s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 1.350s |
| +--- FAIL: TestAccountHomeConfiguredDiscoveryAliases (0.00s) |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/home (0.00s) |
| + connections_test.go:154: shared binding authority accepted |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/home-id (0.00s) |
| + connections_test.go:154: shared binding authority accepted |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/account (0.00s) |
| + connections_test.go:154: shared binding authority accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 8ms |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.012s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/containment -run 'TestEffectivePolicyTurnSources|TestPrivateHomeConfigOutsideWritableMounts|TestEffectivePolicyRejectsWritableSource|TestNamespaceProviderRequiresManifest' -count=1 |
| +``` |
| + |
| +Exit 1: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyTurnSources (0.65s) |
| + --- FAIL: TestEffectivePolicyTurnSources/settings (0.21s) |
| + policy_test.go:327: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/mcp (0.22s) |
| + policy_test.go:327: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/managed (0.22s) |
| + policy_test.go:327: changed policy admitted next turn |
| +--- FAIL: TestPrivateHomeConfigOutsideWritableMounts (0.21s) |
| + policy_test.go:334: config source has writable namespace alias |
| +--- FAIL: TestEffectivePolicyRejectsWritableSource (0.42s) |
| + --- FAIL: TestEffectivePolicyRejectsWritableSource/workspace (0.21s) |
| + policy_test.go:342: writable managed alias accepted |
| + --- FAIL: TestEffectivePolicyRejectsWritableSource/scratch (0.21s) |
| + policy_test.go:342: writable managed alias accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1.28s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 1.282s |
| +--- FAIL: TestNamespaceProviderRequiresManifest (0.11s) |
| + linux_test.go:688: provider launch without manifest forked |
| +FAIL |
| +rastrillo-budget/v1 ran 111ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.113s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicy' -count=1 |
| +``` |
| + |
| +Exit 1: |
| + |
| +```text |
| +# amadan.net/oficina/equipo/internal/runner/containment [amadan.net/oficina/equipo/internal/runner/containment.test] |
| +internal/runner/containment/linux_test.go:715:4: m.beforePin undefined (type *Manager has no field or method beforePin) |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment [build failed] |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentPreflightLatched$' -count=1 |
| +``` |
| + |
| +Exit 1: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentPreflightLatched (0.20s) |
| + --- FAIL: TestAccountContainmentPreflightLatched/source (0.06s) |
| + accounts_test.go:537: preflight containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentPreflightLatched/identity (0.10s) |
| + accounts_test.go:537: preflight containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 204ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.206s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentSourceFile$' -count=1 |
| +``` |
| + |
| +Exit 1: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentSourceFile (0.12s) |
| + --- FAIL: TestAccountContainmentSourceFile/symlink (0.06s) |
| + accounts_test.go:652: unsafe source not contained: provider_account_maintenance |
| + accounts_test.go:655: unsafe source containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentSourceFile/directory (0.06s) |
| + accounts_test.go:652: unsafe source not contained: provider_policy_rejected |
| + accounts_test.go:655: unsafe source containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 123ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.125s |
| +FAIL |
| +``` |
| + |
| +An earlier test-file import replacement caused a parser error; it was corrected before the recorded direct-test RED. It is not behavioral evidence. |
| + |
| +### GREEN evidence |
| + |
| +All implementation and supplemental tests passed before mutation checks. The intermediate commands were: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner -run 'TestAccount' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/containment -run 'TestEffectivePolicy|TestPrivateHome|TestNamespaceProviderRequiresManifest' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/containment -run 'TestAccountContainmentPreflightLatched|TestNamespaceDirectPolicy|TestNamespaceProviderRequiresManifest|TestAccountHomeLookupFailClosed|TestAccountRefreshPreflightPreservesLogin|TestEffectivePolicyProviderRequiresManifest' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run 'TestAccountContainmentSourceFile|TestEffectivePolicyConfigDirectory' -count=1 |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run 'TestAccountContainmentLatched|TestAccountRefreshFailure' -count=1 |
| +``` |
| + |
| +Each exited 0. During conversion, the long-scratch egress fixture initially retained its old runtime-home root and failed with namespace_mount_rejected. It now constructs the lease under the final long scratch root; the final covering command includes that test. |
| + |
| +After restoring all mutations, the required covering command passed: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner ./internal/runner/containment ./internal/runner/egress -run 'TestAccount|TestEffectivePolicy|TestUnexpectedConfig|TestPrivateHome|TestNamespace|TestEgress' -count=1 |
| +``` |
| + |
| +Exit 0: |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider 8.656s |
| +ok amadan.net/oficina/equipo/internal/runner 19.597s |
| +ok amadan.net/oficina/equipo/internal/runner/containment 7.646s |
| +ok amadan.net/oficina/equipo/internal/runner/egress 3.280s |
| +``` |
| + |
| +```sh |
| +make runner-namespace-test |
| +``` |
| + |
| +Exit 0: |
| + |
| +```text |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespace' -count=1 |
| +ok amadan.net/oficina/equipo/internal/runner/containment 5.055s |
| +``` |
| + |
| +`gofmt` was applied to the changed Go files and `git diff --check` passed. No full suite, make ci, live gate, sign-in or provider prompt was run. |
| + |
| +### Mutation evidence |
| + |
| +Each mutation below changed one guard, ran the exact named command, produced a compiled test failure, and was restored before the next mutation. All 39 recorded mutations exited 1 with a named test failure. One preliminary version of mutation 20 left `info` unused; it was replaced with a compiling false condition and rerun. The compile failure is not counted as evidence. |
| + |
| +#### R1 mutation 1: refresh-state |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +return ErrRefreshPending |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +return ErrPreflightRequired |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountRefreshPending$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshPending (0.17s) |
| + --- FAIL: TestAccountRefreshPending/false (0.08s) |
| + accounts_test.go:460: refresh must be pending: provider_preflight_required |
| + --- FAIL: TestAccountRefreshPending/true (0.08s) |
| + accounts_test.go:460: refresh must be pending: provider_preflight_required |
| +FAIL |
| +rastrillo-budget/v1 ran 165ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.167s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 2: preflight-preserves-refresh |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !refresh && sha256.Sum256(runtimeCurrent) != l.runtimeGeneration { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !refresh && sha256.Sum256(runtimeCurrent) != l.runtimeGeneration { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountRefreshPreflightPreservesLogin$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshPreflightPreservesLogin (0.08s) |
| + accounts_test.go:591: pending refresh probed |
| + accounts_test.go:596: pending refresh overwritten |
| +FAIL |
| +rastrillo-budget/v1 ran 85ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.087s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 3: midturn-refresh-explained |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| + if l.active { return ErrContainment } |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountRefreshPending/true$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshPending (0.05s) |
| + --- FAIL: TestAccountRefreshPending/true (0.05s) |
| + accounts_test.go:460: refresh must be pending: provider_account_containment |
| +FAIL |
| +rastrillo-budget/v1 ran 49ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.052s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 4: containment-latch |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +defer func() { l.latch(err) }() |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +defer func() { _ = err }() |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.25s) |
| + --- FAIL: TestAccountContainmentLatched/identity (0.12s) |
| + accounts_test.go:541: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.13s) |
| + accounts_test.go:541: containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 247ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.252s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 5: preflight-latch-admission |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if l.contained { |
| + l.mu.Unlock() |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && l.contained { |
| + l.mu.Unlock() |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.24s) |
| + --- FAIL: TestAccountContainmentLatched/identity (0.12s) |
| + accounts_test.go:541: containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.12s) |
| + accounts_test.go:541: containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 239ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.241s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 6: contained-provenance |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +!l.closed && !l.contained && b == l.binding() |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +!l.closed && b == l.binding() |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.13s) |
| + --- FAIL: TestAccountContainmentLatched/identity (0.08s) |
| + accounts_test.go:544: contained lease retained provenance |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.05s) |
| + accounts_test.go:544: contained lease retained provenance |
| +FAIL |
| +rastrillo-budget/v1 ran 130ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.132s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 7: runtime-identity |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +json.Unmarshal(metadata, &id) != nil || id != l.source.Expected |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +json.Unmarshal(metadata, &id) != nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/runtime-identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.11s) |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.11s) |
| + accounts_test.go:529: active tampering not contained: <nil> |
| + accounts_test.go:541: containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 109ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.111s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 8: runtime-unsafe-file |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +raw, e := readPrivate(dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, ErrContainment |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +raw, e := readPrivate(dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/symlink$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.08s) |
| + --- FAIL: TestAccountContainmentLatched/symlink (0.08s) |
| + accounts_test.go:529: active tampering not contained: provider_refresh_pending |
| + accounts_test.go:541: containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 77ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.078s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 9: commit-refresh-generation |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +l.runtimeGeneration = sha256.Sum256(runtimeAfter) |
| + return nil |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = runtimeAfter |
| + return nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountRefreshPending$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshPending (0.19s) |
| + --- FAIL: TestAccountRefreshPending/false (0.10s) |
| + accounts_test.go:475: refresh skipped preflight: provider_refresh_pending |
| + --- FAIL: TestAccountRefreshPending/true (0.09s) |
| + accounts_test.go:475: refresh skipped preflight: provider_refresh_pending |
| +FAIL |
| +rastrillo-budget/v1 ran 192ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.194s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 10: source-file-containment |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +raw, e := readPrivate(l.dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, zero, ErrContainment |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +raw, e := readPrivate(l.dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, zero, e |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentSourceFile$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentSourceFile (0.24s) |
| + --- FAIL: TestAccountContainmentSourceFile/symlink (0.12s) |
| + accounts_test.go:666: unsafe source not contained: provider_account_maintenance |
| + accounts_test.go:673: unsafe source containment not latched: <nil> |
| + --- FAIL: TestAccountContainmentSourceFile/directory (0.12s) |
| + accounts_test.go:666: unsafe source not contained: provider_policy_rejected |
| + accounts_test.go:673: unsafe source containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 238ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.240s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 11: preflight-source-latch |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +_, before, e := l.snapshot() |
| + if e != nil { |
| + l.latch(e) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_, before, e := l.snapshot() |
| + if e != nil { |
| + _ = e |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentPreflightLatched/source$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentPreflightLatched (0.11s) |
| + --- FAIL: TestAccountContainmentPreflightLatched/source (0.11s) |
| + accounts_test.go:640: preflight containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 115ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.116s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 12: start-manifest |
| + |
| +File: `internal/runner/containment/linux.go`. Replace the first matching fragment: |
| + |
| +```go |
| +(l.Selection.Provider != "" && l.Policy.ManifestHash == "") |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +(false && l.Selection.Provider != "" && l.Policy.ManifestHash == "") |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceProviderRequiresManifest$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceProviderRequiresManifest (0.00s) |
| + linux_test.go:702: missing manifest passed admission: provider_policy_rejected |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.003s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 13: attestation-manifest |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if l.Selection.Provider != "" || l.Binding.DedicatedHome { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if l.Binding.DedicatedHome { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyProviderRequiresManifest$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyProviderRequiresManifest (0.00s) |
| + policy_test.go:373: direct provider accepted legacy attestation |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.001s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 14: config-outside-home |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +filepath.Join(b.provenance.config, "equipo-settings.json") |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +filepath.Join(b.Home, "equipo-settings.json") |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestPrivateHomeConfigOutsideWritableMounts$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestPrivateHomeConfigOutsideWritableMounts (0.12s) |
| + policy_test.go:347: config source has writable namespace alias |
| +FAIL |
| +rastrillo-budget/v1 ran 122ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.123s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 15: turn-policy-check |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e := l.validatePolicy(); e != nil { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e := l.validatePolicy(); false && e != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyTurnSources$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyTurnSources (0.35s) |
| + --- FAIL: TestEffectivePolicyTurnSources/settings (0.11s) |
| + policy_test.go:335: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/mcp (0.12s) |
| + policy_test.go:335: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/managed (0.12s) |
| + policy_test.go:335: changed policy admitted next turn |
| +FAIL |
| +rastrillo-budget/v1 ran 350ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.351s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 16: register-turn-policy |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +b.provenance.policy = &Policy{Manifest: bytes.Clone(raw), ManifestHash: manifestHash} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +b.provenance.policy = nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyTurnSources$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyTurnSources (0.25s) |
| + --- FAIL: TestEffectivePolicyTurnSources/settings (0.08s) |
| + policy_test.go:335: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/mcp (0.09s) |
| + policy_test.go:335: changed policy admitted next turn |
| + --- FAIL: TestEffectivePolicyTurnSources/managed (0.07s) |
| + policy_test.go:335: changed policy admitted next turn |
| +FAIL |
| +rastrillo-budget/v1 ran 250ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.252s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 17: managed-digest |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e != nil || !reflect.DeepEqual(current, expected) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e != nil || (false && !reflect.DeepEqual(current, expected)) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyTurnSources/managed$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyTurnSources (0.12s) |
| + --- FAIL: TestEffectivePolicyTurnSources/managed (0.12s) |
| + policy_test.go:335: changed policy admitted next turn |
| +FAIL |
| +rastrillo-budget/v1 ran 117ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.122s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 18: generated-digest |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e != nil || !bytes.Equal(raw, want) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e != nil || (false && !bytes.Equal(raw, want)) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyTurnSources/settings$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyTurnSources (0.12s) |
| + --- FAIL: TestEffectivePolicyTurnSources/settings (0.12s) |
| + policy_test.go:335: changed policy admitted next turn |
| +FAIL |
| +rastrillo-budget/v1 ran 125ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.127s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 19: writable-source |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if withinPath(file.Source, in.Workspace) || withinPath(file.Source, in.Scratch) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && (withinPath(file.Source, in.Workspace) || withinPath(file.Source, in.Scratch)) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyRejectsWritableSource$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyRejectsWritableSource (0.20s) |
| + --- FAIL: TestEffectivePolicyRejectsWritableSource/workspace (0.11s) |
| + policy_test.go:365: writable managed alias accepted |
| + --- FAIL: TestEffectivePolicyRejectsWritableSource/scratch (0.09s) |
| + policy_test.go:365: writable managed alias accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 204ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.213s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 20: config-directory-identity |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +e != nil || !os.SameFile(info, l.configInfo) || !privateDirectory(f) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +e != nil || (false && !os.SameFile(info, l.configInfo)) || !privateDirectory(f) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyConfigDirectory/replacement$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyConfigDirectory (0.11s) |
| + --- FAIL: TestEffectivePolicyConfigDirectory/replacement (0.11s) |
| + policy_test.go:410: changed config admitted resume |
| +FAIL |
| +rastrillo-budget/v1 ran 112ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.113s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 21: config-directory-mode |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +e != nil || !os.SameFile(info, l.configInfo) || !privateDirectory(f) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +e != nil || !os.SameFile(info, l.configInfo) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyConfigDirectory/mode$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyConfigDirectory (0.11s) |
| + --- FAIL: TestEffectivePolicyConfigDirectory/mode (0.11s) |
| + policy_test.go:410: changed config admitted resume |
| +FAIL |
| +rastrillo-budget/v1 ran 113ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.115s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 22: config-cleanup |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +cleanup = errors.Join(cleanup, os.RemoveAll(l.config)) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +cleanup = errors.Join(cleanup, nil) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyConfigDirectory/cleanup$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyConfigDirectory (0.11s) |
| + --- FAIL: TestEffectivePolicyConfigDirectory/cleanup (0.11s) |
| + policy_test.go:403: config directory survived lease close |
| +FAIL |
| +rastrillo-budget/v1 ran 115ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.116s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 23: resume-policy-check |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +return l.validatePolicy() |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +return nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestEffectivePolicyConfigDirectory/resume$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestEffectivePolicyConfigDirectory (0.11s) |
| + --- FAIL: TestEffectivePolicyConfigDirectory/resume (0.11s) |
| + policy_test.go:410: changed config admitted resume |
| +FAIL |
| +rastrillo-budget/v1 ran 105ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.108s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 24: passwd-home |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +u, e := lookup(strconv.Itoa(os.Geteuid())) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +u, e := lookup(strconv.Itoa(os.Geteuid())) |
| + if u != nil { u.HomeDir = getenv("HOME") } |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountHomeDefaultsIgnoreEnvironment$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeDefaultsIgnoreEnvironment (0.00s) |
| + accounts_test.go:559: passwd home accepted with changed HOME |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.001s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 25: lookup-fail-closed |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if r.unavailable || !cleanPath(path) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if !cleanPath(path) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountHomeLookupFailClosed$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeLookupFailClosed (0.00s) |
| + accounts_test.go:576: missing passwd home accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 26: inherited-codex-home |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +[]string{"CODEX_HOME", "CLAUDE_CONFIG_DIR"} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +[]string{"UNUSED_HOME", "CLAUDE_CONFIG_DIR"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountHomeDefaultsIgnoreEnvironment$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeDefaultsIgnoreEnvironment (0.00s) |
| + accounts_test.go:567: inherited CODEX_HOME accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 27: inherited-claude-home |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +[]string{"CODEX_HOME", "CLAUDE_CONFIG_DIR"} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +[]string{"CODEX_HOME", "UNUSED_HOME"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountHomeDefaultsIgnoreEnvironment$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeDefaultsIgnoreEnvironment (0.00s) |
| + accounts_test.go:567: inherited CLAUDE_CONFIG_DIR accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.002s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 28: unique-home |
| + |
| +File: `internal/runner/connections.go`. Replace the first matching fragment: |
| + |
| +```go |
| +homes[b.ProviderHome] = b |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = b |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run '^TestAccountHomeConfiguredDiscoveryAliases/home$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeConfiguredDiscoveryAliases (0.00s) |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/home (0.00s) |
| + connections_test.go:167: shared binding authority accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.003s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 29: unique-home-id |
| + |
| +File: `internal/runner/connections.go`. Replace the first matching fragment: |
| + |
| +```go |
| +homeIDs[b.ExpectedIdentity.HomeID] = b |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = b |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run '^TestAccountHomeConfiguredDiscoveryAliases/home-id$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeConfiguredDiscoveryAliases (0.00s) |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/home-id (0.00s) |
| + connections_test.go:167: shared binding authority accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.003s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 30: unique-account |
| + |
| +File: `internal/runner/connections.go`. Replace the first matching fragment: |
| + |
| +```go |
| +accountIDs[b.Provider+"/"+b.AccountID] = b |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +_ = b |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner -run '^TestAccountHomeConfiguredDiscoveryAliases/account$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountHomeConfiguredDiscoveryAliases (0.00s) |
| + --- FAIL: TestAccountHomeConfiguredDiscoveryAliases/account (0.00s) |
| + connections_test.go:167: shared binding authority accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1ms |
| +FAIL amadan.net/oficina/equipo/internal/runner 0.005s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 31: pinned-settings-digest |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +func (p Policy) ValidateFileDigest(path, hash string) error { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +func (p Policy) ValidateFileDigest(path, hash string) error { |
| + return nil |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicySwapBeforePin$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicySwapBeforePin (0.22s) |
| + linux_test.go:763: swapped settings reached namespace |
| +FAIL |
| +rastrillo-budget/v1 ran 221ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.224s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 32: host-runtime-binaries |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +func (p Policy) ValidateRuntimeBinaries(paths ...string) error { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +func (p Policy) ValidateRuntimeBinaries(paths ...string) error { |
| + return nil |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicyAdmission/(runner|bwrap)$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicyAdmission (0.30s) |
| + --- FAIL: TestNamespaceDirectPolicyAdmission/runner (0.13s) |
| + linux_test.go:802: changed direct launch passed attestation |
| + --- FAIL: TestNamespaceDirectPolicyAdmission/bwrap (0.16s) |
| + linux_test.go:802: changed direct launch passed attestation |
| +FAIL |
| +rastrillo-budget/v1 ran 296ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.298s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 33: launch-argv |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| + || !reflect.DeepEqual(m.Argv, argv) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +// removed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicyAdmission/argv$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicyAdmission (0.21s) |
| + --- FAIL: TestNamespaceDirectPolicyAdmission/argv (0.21s) |
| + linux_test.go:799: changed direct launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 208ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.210s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 34: launch-env |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !reflect.DeepEqual(expectedEnv, p.Env) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !reflect.DeepEqual(expectedEnv, p.Env) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicyAdmission/env$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicyAdmission (0.22s) |
| + --- FAIL: TestNamespaceDirectPolicyAdmission/env (0.22s) |
| + linux_test.go:799: changed direct launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 217ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.220s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 35: launch-mounts |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !reflect.DeepEqual(expectedMounts, p.Mounts) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !reflect.DeepEqual(expectedMounts, p.Mounts) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicyAdmission/mount$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicyAdmission (0.22s) |
| + --- FAIL: TestNamespaceDirectPolicyAdmission/mount (0.22s) |
| + linux_test.go:799: changed direct launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 219ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.221s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 36: active-source-change |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if generation != l.generation && l.active { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && generation != l.generation && l.active { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/source$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.07s) |
| + --- FAIL: TestAccountContainmentLatched/source (0.07s) |
| + accounts_test.go:529: active tampering not contained: provider_preflight_required |
| + accounts_test.go:541: containment not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 73ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.082s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 37: contained-turn-admission |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if l.contained { |
| + return ErrContainment |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && l.contained { |
| + return ErrContainment |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountContainmentLatched/identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountContainmentLatched (0.17s) |
| + --- FAIL: TestAccountContainmentLatched/identity (0.08s) |
| + accounts_test.go:547: contained lease admitted turn: provider_preflight_required |
| + --- FAIL: TestAccountContainmentLatched/runtime-identity (0.09s) |
| + accounts_test.go:547: contained lease admitted turn: provider_preflight_required |
| +FAIL |
| +rastrillo-budget/v1 ran 173ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.179s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 38: refresh-identity-latch |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if id != l.source.Expected { |
| + l.contained = true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if id != l.source.Expected { |
| + l.contained = false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider -run '^TestAccountRefreshFailure/identity$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestAccountRefreshFailure (0.10s) |
| + --- FAIL: TestAccountRefreshFailure/identity (0.10s) |
| + accounts_test.go:713: wrong refresh identity not latched: <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 103ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider 0.113s |
| +FAIL |
| +``` |
| + |
| +#### R1 mutation 39: config-readonly-bind |
| + |
| +File: `internal/runner/containment/mounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +p.bind(mount.Source, target, true, false) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +p.bind(mount.Source, target, false, false) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceDirectPolicy$' -count=1 |
| +``` |
| + |
| +Exit 1, compiled failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceDirectPolicy (0.29s) |
| + linux_test.go:731: direct namespace failed: {1 0 2026-11-03 13:01:56.30799706 +0000 UTC} <nil> Traceback (most recent call last): |
| + File "<string>", line 5, in <module> |
| + raise AssertionError('config writable') |
| + AssertionError: config writable |
| +FAIL |
| +rastrillo-budget/v1 ran 285ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.296s |
| +FAIL |
| +``` |
| + |
| +### User-facing strings and concerns |
| + |
| +No UI strings or copy.go entries changed. The new internal error code is `provider_refresh_pending`; any later UI presentation needs its own individually pending copy.go entry and release copy pass. Existing identity, maintenance, policy and containment errors are reused. This report and test failure messages are the only explanatory text added. |
| + |
| +No unresolved fix-round findings remain. Real refresh behavior, native provider tool restrictions and deployed-policy certification remain later live gates. The fake-login namespace tests do not certify a provider account or add release certificates. Adapters must use CommitRefresh, Preflight and the turn/resume checks in the stated order. |
| + |
| +All mutation sources were restored. All test processes and namespace children exited through their cleanup paths. Owned scratch logs/scripts are removed after copying their evidence into these reports. No push, merge, deployment, README edit, other worktree change or production configuration change was made. |
diff --git a/internal/runner/connections.go b/internal/runner/connections.go| index 6753dc10..f47e7f4e 100644 |
| --- a/internal/runner/connections.go |
| +++ b/internal/runner/connections.go |
| @@ -158,14 +158,26 @@ func loadDirectBindings(path string) ([]AccountBinding, error) { |
| } |
| seen := map[string]bool{} |
| accounts := map[string]AccountBinding{} |
| + homes := map[string]AccountBinding{} |
| + homeIDs := map[string]AccountBinding{} |
| + accountIDs := map[string]AccountBinding{} |
| + rules := provider.DefaultHomeRules() |
| 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 { |
| + 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") || rules.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 |
| } |
| + for _, prior := range []AccountBinding{homes[b.ProviderHome], homeIDs[b.ExpectedIdentity.HomeID], accountIDs[b.Provider+"/"+b.AccountID]} { |
| + if prior.LocalID != "" && (prior.LocalID != b.LocalID || prior.PersonID != b.PersonID) { |
| + return nil, provider.ErrIdentity |
| + } |
| + } |
| + homes[b.ProviderHome] = b |
| + homeIDs[b.ExpectedIdentity.HomeID] = b |
| + accountIDs[b.Provider+"/"+b.AccountID] = b |
| seen[key] = true |
| accounts[b.LocalID] = b |
| } |
diff --git a/internal/runner/connections_test.go b/internal/runner/connections_test.go| index ea0aa2bc..9de97a62 100644 |
| --- a/internal/runner/connections_test.go |
| +++ b/internal/runner/connections_test.go |
| @@ -139,3 +139,33 @@ func TestAccountHomeConfiguredDiscovery(t *testing.T) { |
| t.Fatal("missing identity accepted") |
| } |
| } |
| + |
| +func TestAccountHomeConfiguredDiscoveryAliases(t *testing.T) { |
| + for _, kind := range []string{"home", "home-id", "account"} { |
| + t.Run(kind, func(t *testing.T) { |
| + c := configFixture(t) |
| + first := AccountBinding{ID: "first", LocalID: "first", PersonID: "person", Provider: "codex", Family: "gpt", Model: "model", AccountID: "account", ProviderHome: filepath.Join(t.TempDir(), "dedicated"), ExpectedIdentity: provider.Identity{AccountID: "account", HomeID: "home", ProviderVersion: "0.165.0"}, Kind: "subscription"} |
| + second := first |
| + second.ID = "second" |
| + second.LocalID = "second" |
| + second.PersonID = "other-person" |
| + if kind != "home" { |
| + second.ProviderHome = filepath.Join(t.TempDir(), "other") |
| + } |
| + if kind != "home-id" { |
| + second.ExpectedIdentity.HomeID = "other" |
| + } |
| + if kind != "account" { |
| + second.AccountID = "other" |
| + second.ExpectedIdentity.AccountID = "other" |
| + } |
| + raw, _ := json.Marshal([]AccountBinding{first, second}) |
| + if e := os.WriteFile(c.AccountBindingsPath, raw, 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e := loadDirectBindings(c.AccountBindingsPath); e == nil { |
| + t.Fatal("shared binding authority accepted") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/containment/egress_test.go b/internal/runner/containment/egress_test.go| index 9adf098f..abb07dbc 100644 |
| --- a/internal/runner/containment/egress_test.go |
| +++ b/internal/runner/containment/egress_test.go |
| @@ -3,6 +3,7 @@ package containment |
| import ( |
| "bufio" |
| "context" |
| + "encoding/json" |
| "fmt" |
| "io" |
| "net" |
| @@ -16,7 +17,7 @@ import ( |
| "amadan.net/oficina/equipo/internal/runner/provider" |
| ) |
| -func egressFixture(t *testing.T) (*Manager, provider.Launch) { |
| +func egressFixture(t *testing.T, deep ...bool) (*Manager, provider.Launch) { |
| t.Helper() |
| root, e := os.MkdirTemp(os.Getenv("TMPDIR"), "e3-") |
| if e != nil { |
| @@ -24,8 +25,11 @@ func egressFixture(t *testing.T) (*Manager, provider.Launch) { |
| } |
| t.Cleanup(func() { os.RemoveAll(root) }) |
| state := filepath.Join(root, "s") |
| + if len(deep) > 0 && deep[0] { |
| + state = filepath.Join(state, strings.Repeat("deep", 20), "state") |
| + } |
| workspace := filepath.Join(root, "w") |
| - if e = os.Mkdir(state, 0700); e != nil { |
| + if e = os.MkdirAll(state, 0700); e != nil { |
| t.Fatal(e) |
| } |
| if e = os.Mkdir(workspace, 0700); e != nil { |
| @@ -39,7 +43,32 @@ func egressFixture(t *testing.T) (*Manager, provider.Launch) { |
| if e != nil { |
| t.Fatal(e) |
| } |
| - return m, provider.Launch{AttemptKey: "egress", Workspace: workspace, Selection: provider.Selection{Provider: "claude"}, Policy: provider.Policy{Hash: "fixture-policy"}} |
| + home := filepath.Join(root, "fake-login") |
| + if e = os.Mkdir(home, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + id := provider.Identity{AccountID: "fake-account", HomeID: "fake-home", ProviderVersion: "2.1.312"} |
| + metadata, _ := json.Marshal(id) |
| + for name, raw := range map[string][]byte{provider.IdentityFile: metadata, ".credentials.json": []byte(`{"token":"fake-only"}`)} { |
| + if e = os.WriteFile(filepath.Join(home, name), raw, 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + lease, e := provider.OpenAccount(context.Background(), provider.Binding{ID: "fake-binding", Provider: "claude", AccountID: id.AccountID, Expected: id, Home: home, RuntimeRoot: filepath.Join(state, "homes")}) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + t.Cleanup(func() { |
| + if e := lease.Close(); e != nil { |
| + t.Error(e) |
| + } |
| + }) |
| + if e = lease.Preflight(context.Background(), func(context.Context, provider.Binding) (provider.Identity, error) { return id, nil }); e != nil { |
| + t.Fatal(e) |
| + } |
| + l := provider.Launch{AttemptKey: "egress", Workspace: workspace, Binding: lease.Binding(), Selection: provider.Selection{Provider: "claude", AccountID: id.AccountID}} |
| + l, _ = directPolicyFixture(t, m, l, []string{"/usr/bin/true"}) |
| + return m, l |
| } |
| func TestEgressRejectsHostServices(t *testing.T) { |
| @@ -93,19 +122,11 @@ except OSError: |
| } |
| func TestEgressLongScratchRoot(t *testing.T) { |
| - m, l := egressFixture(t) |
| + m, l := egressFixture(t, true) |
| cfg := m.cfg |
| - cfg.ScratchRoot = filepath.Join(cfg.ScratchRoot, strings.Repeat("deep", 20), "state") |
| if len(cfg.ScratchRoot) < 70 { |
| t.Fatal("fixture scratch root is too short") |
| } |
| - if e := os.MkdirAll(cfg.ScratchRoot, 0700); e != nil { |
| - t.Fatal(e) |
| - } |
| - m, e := New(cfg) |
| - if e != nil { |
| - t.Fatal(e) |
| - } |
| p := launch(t, m, l, `import socket, sys |
| s=socket.create_connection(('127.0.0.1',18080),2) |
| s.sendall(b'CONNECT localhost:443 HTTP/1.1\r\nHost: localhost:443\r\n\r\n') |
| @@ -145,7 +166,7 @@ func TestEgressDiesWithAttempt(t *testing.T) { |
| m, l := egressFixture(t) |
| ctx, cancel := context.WithCancel(context.Background()) |
| defer cancel() |
| - p, e := m.Start(ctx, l, []string{"/usr/bin/python3", "-u", "-c", `import socket,sys,time |
| + l, argv := directPolicyFixture(t, m, l, []string{"/usr/bin/python3", "-u", "-c", `import socket,sys,time |
| s=socket.create_connection(('127.0.0.1',18080),1) |
| s.sendall(b'CONNECT localhost:443 HTTP/1.1\r\n\r\n') |
| assert b'403' in s.recv(1024) |
| @@ -153,6 +174,7 @@ s.close() |
| print('ready',flush=True) |
| sys.stdin.read(1) |
| `}) |
| + p, e := m.Start(ctx, l, argv) |
| if e != nil { |
| t.Fatal(e) |
| } |
| @@ -266,7 +288,7 @@ func TestEgressInstalledContract(t *testing.T) { |
| func TestEgressRefreshRequiresStagedHome(t *testing.T) { |
| m, l := egressFixture(t) |
| - l.Binding.DedicatedHome = true |
| + l.Binding = provider.Binding{Home: l.Binding.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("unstaged home qualified for refresh") |
| @@ -276,6 +298,7 @@ func TestEgressRefreshRequiresStagedHome(t *testing.T) { |
| func TestEgressStartupFailureClosesProxy(t *testing.T) { |
| m, l := egressFixture(t) |
| m.cfg.RunnerBinary = "/usr/bin/true" |
| + l, argv := directPolicyFixture(t, m, l, []string{"/usr/bin/true"}) |
| sockets := func() int { |
| entries, e := os.ReadDir("/proc/self/fd") |
| if e != nil { |
| @@ -291,7 +314,7 @@ func TestEgressStartupFailureClosesProxy(t *testing.T) { |
| return count |
| } |
| before := sockets() |
| - if p, e := m.Start(context.Background(), l, []string{"/usr/bin/true"}); e == nil { |
| + if p, e := m.Start(context.Background(), l, argv); e == nil { |
| m.Stop(context.Background(), p.ID()) |
| t.Fatal("invalid helper started") |
| } |
| @@ -303,7 +326,7 @@ func TestEgressStartupFailureClosesProxy(t *testing.T) { |
| t.Fatal(e) |
| } |
| for _, entry := range entries { |
| - if entry.IsDir() { |
| + if entry.IsDir() && entry.Name() != "homes" { |
| t.Fatalf("startup scratch survived: %s", entry.Name()) |
| } |
| } |
| @@ -329,3 +352,27 @@ func TestEgressRejectsForgedDedicatedHome(t *testing.T) { |
| t.Fatal("egress accepted forged provenance") |
| } |
| } |
| + |
| +func directPolicyFixture(t *testing.T, m *Manager, l provider.Launch, argv []string) (provider.Launch, []string) { |
| + t.Helper() |
| + binary, e := filepath.EvalSymlinks(argv[0]) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + argv = append([]string(nil), argv...) |
| + argv[0] = "/opt/harness" |
| + scratch := t.TempDir() |
| + network, e := egress.ProviderPolicy(provider.NetworkContract{Provider: l.Selection.Provider}, true) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + l.Policy, e = provider.BuildPolicy(l.Binding, provider.PolicyInputs{ |
| + RuntimeFiles: []provider.Mount{{Source: binary, Target: argv[0], ReadOnly: true}, {Source: m.cfg.Binary, Target: "/opt/bwrap", ReadOnly: true}, {Source: m.cfg.RunnerBinary, Target: "/opt/runner", ReadOnly: true}}, |
| + ProviderVersion: "2.1.312", LauncherVersion: "test", BwrapVersion: "0.11.0", EgressHosts: network.Hosts, |
| + Settings: json.RawMessage(`{"sandbox":true}`), MCP: json.RawMessage(`{}`), Workspace: l.Workspace, Scratch: scratch, Argv: argv, |
| + }) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + return l, argv |
| +} |
diff --git a/internal/runner/containment/linux.go b/internal/runner/containment/linux.go| index c5196cd6..6e166fff 100644 |
| --- a/internal/runner/containment/linux.go |
| +++ b/internal/runner/containment/linux.go |
| @@ -28,7 +28,9 @@ type Config struct { |
| ProviderNetworks []provider.NetworkContract |
| } |
| type Manager struct { |
| - cfg Config |
| + cfg Config |
| + // beforePin is a test seam for replacement after attestation. |
| + beforePin func() |
| mu sync.Mutex |
| processes map[string]*process |
| } |
| @@ -112,7 +114,7 @@ func (m *Manager) Start(ctx context.Context, l provider.Launch, argv []string) ( |
| if e := ctx.Err(); e != nil { |
| return nil, e |
| } |
| - if l.AttemptKey == "" || l.Policy.Hash == "" || len(argv) == 0 || !cleanAbsolute(argv[0]) { |
| + if (l.Selection.Provider != "" && l.Policy.ManifestHash == "") || 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 { |
| @@ -122,6 +124,9 @@ func (m *Manager) Start(ctx context.Context, l provider.Launch, argv []string) ( |
| if err != nil { |
| return nil, err |
| } |
| + if m.beforePin != nil { |
| + m.beforePin() |
| + } |
| var random [16]byte |
| if _, e := rand.Read(random[:]); e != nil { |
| return nil, e |
diff --git a/internal/runner/containment/linux_test.go b/internal/runner/containment/linux_test.go| index c397327f..736c229f 100644 |
| --- a/internal/runner/containment/linux_test.go |
| +++ b/internal/runner/containment/linux_test.go |
| @@ -45,7 +45,11 @@ func launch(t *testing.T, m *Manager, l provider.Launch, script string) provider |
| t.Helper() |
| ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) |
| t.Cleanup(cancel) |
| - p, err := m.Start(ctx, l, []string{"/usr/bin/python3", "-u", "-c", script}) |
| + argv := []string{"/usr/bin/python3", "-u", "-c", script} |
| + if l.Selection.Provider != "" { |
| + l, argv = directPolicyFixture(t, m, l, argv) |
| + } |
| + p, err := m.Start(ctx, l, argv) |
| if err != nil { |
| t.Fatalf("namespace capability/start failed (userns, pidfd required): %v", err) |
| } |
| @@ -681,3 +685,122 @@ func TestNamespaceManifestInputs(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +func TestNamespaceProviderRequiresManifest(t *testing.T) { |
| + m, l := fixture(t) |
| + l.Selection.Provider = "claude" |
| + p, e := m.Start(context.Background(), l, []string{"/usr/bin/true"}) |
| + if e == nil { |
| + p.(*process).kill() |
| + p.Wait(context.Background()) |
| + p.Stdin().Close() |
| + p.Stdout().Close() |
| + p.Stderr().Close() |
| + t.Fatal("provider launch without manifest forked") |
| + } |
| + if e != errStartup { |
| + t.Fatalf("missing manifest passed admission: %v", e) |
| + } |
| + entries, e := os.ReadDir(m.cfg.ScratchRoot) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if len(entries) != 0 { |
| + t.Fatal("unattested provider launch created attempt state") |
| + } |
| +} |
| + |
| +func TestNamespaceDirectPolicy(t *testing.T) { |
| + m, l := egressFixture(t) |
| + p := launch(t, m, l, `import os |
| +assert not os.path.exists('/home/runner/equipo-settings.json') |
| +try: |
| + open('/config/equipo-settings.json','w').write('{}') |
| + raise AssertionError('config writable') |
| +except OSError: |
| + pass |
| +print('direct-running',flush=True) |
| +`) |
| + raw, e := io.ReadAll(p.Stdout()) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + exit, e := p.Wait(context.Background()) |
| + if e != nil || exit.Code != 0 || string(raw) != "direct-running\n" { |
| + errout, _ := io.ReadAll(p.Stderr()) |
| + t.Fatalf("direct namespace failed: %s %v %v %s", raw, exit, e, errout) |
| + } |
| + r := record(t, m, p) |
| + if r.ManifestHash == r.PolicyHash { |
| + t.Fatal("direct manifest not concrete") |
| + } |
| +} |
| +func TestNamespaceDirectPolicySwapBeforePin(t *testing.T) { |
| + m, l := egressFixture(t) |
| + l, argv := directPolicyFixture(t, m, l, []string{"/usr/bin/true"}) |
| + called := false |
| + m.beforePin = func() { |
| + called = true |
| + for _, mount := range l.Policy.Mounts { |
| + if mount.Target == provider.SettingsPath { |
| + replacement := mount.Source + "-replacement" |
| + if e := os.WriteFile(replacement, []byte(`{"changed":true}`), 0600); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.Rename(replacement, mount.Source); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + } |
| + } |
| + p, e := m.Start(context.Background(), l, argv) |
| + if e == nil { |
| + p.(*process).kill() |
| + p.Wait(context.Background()) |
| + p.Stdin().Close() |
| + p.Stdout().Close() |
| + p.Stderr().Close() |
| + t.Fatal("swapped settings reached namespace") |
| + } |
| + if !called { |
| + t.Fatal("did not reach attestation-to-pin boundary") |
| + } |
| + if e != provider.ErrPolicy { |
| + t.Fatalf("unexpected refusal: %v", e) |
| + } |
| +} |
| + |
| +func TestNamespaceDirectPolicyAdmission(t *testing.T) { |
| + for _, kind := range []string{"runner", "bwrap", "argv", "env", "mount"} { |
| + t.Run(kind, func(t *testing.T) { |
| + m, l := egressFixture(t) |
| + l, argv := directPolicyFixture(t, m, l, []string{"/usr/bin/true"}) |
| + switch kind { |
| + case "runner": |
| + m.cfg.RunnerBinary = "/usr/bin/false" |
| + case "bwrap": |
| + m.cfg.Binary = "/usr/bin/false" |
| + case "argv": |
| + argv = append(argv, "unexpected") |
| + case "env": |
| + l.Policy.Env["LANG"] = "changed" |
| + case "mount": |
| + l.Policy.Mounts[0].Target = "/opt/other" |
| + } |
| + reached := false |
| + m.beforePin = func() { reached = true } |
| + p, e := m.Start(context.Background(), l, argv) |
| + if e == nil { |
| + p.(*process).kill() |
| + p.Wait(context.Background()) |
| + p.Stdin().Close() |
| + p.Stdout().Close() |
| + p.Stderr().Close() |
| + t.Fatal("changed direct launch accepted") |
| + } |
| + if reached { |
| + t.Fatal("changed direct launch passed attestation") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/provider/accounts.go b/internal/runner/provider/accounts.go| index 06e96440..728dbb2e 100644 |
| --- a/internal/runner/provider/accounts.go |
| +++ b/internal/runner/provider/accounts.go |
| @@ -10,7 +10,9 @@ import ( |
| "errors" |
| "io" |
| "os" |
| + "os/user" |
| "path/filepath" |
| + "strconv" |
| "strings" |
| "sync" |
| @@ -22,24 +24,47 @@ const ( |
| ErrAccountBusy Error = "provider_account_busy" |
| ErrAccountMaintenance Error = "provider_account_maintenance" |
| ErrPreflightRequired Error = "provider_preflight_required" |
| + ErrRefreshPending Error = "provider_refresh_pending" |
| 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 } |
| +type HomeRules struct { |
| + InteractiveHomes []string |
| + unavailable bool |
| +} |
| func DefaultHomeRules() HomeRules { |
| - home, _ := os.UserHomeDir() |
| - return HomeRules{InteractiveHomes: []string{filepath.Join(home, ".claude"), filepath.Join(home, ".codex")}} |
| + return homeRules(user.LookupId, os.Getenv) |
| +} |
| +func homeRules(lookup func(string) (*user.User, error), getenv func(string) string) HomeRules { |
| + u, e := lookup(strconv.Itoa(os.Geteuid())) |
| + if e != nil || u == nil || !cleanPath(u.HomeDir) { |
| + return HomeRules{unavailable: true} |
| + } |
| + homes := []string{filepath.Join(u.HomeDir, ".claude"), filepath.Join(u.HomeDir, ".codex")} |
| + for _, key := range []string{"CODEX_HOME", "CLAUDE_CONFIG_DIR"} { |
| + if path := getenv(key); path != "" { |
| + path, e = filepath.Abs(path) |
| + if e != nil { |
| + return HomeRules{unavailable: true} |
| + } |
| + homes = append(homes, path) |
| + if real, e := filepath.EvalSymlinks(path); e == nil { |
| + homes = append(homes, real) |
| + } |
| + } |
| + } |
| + return HomeRules{InteractiveHomes: homes} |
| } |
| 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) { |
| + if r.unavailable || !cleanPath(path) { |
| return true |
| } |
| if strings.Contains(path+"/", "/.paseo/zerosub/homes/") { |
| @@ -84,10 +109,14 @@ type AccountLease struct { |
| rules HomeRules |
| dir *os.File |
| runtime string |
| + config string |
| + configInfo os.FileInfo |
| + policy *Policy |
| runtimeInfo os.FileInfo |
| generation [32]byte |
| ready, active, closed bool |
| checking bool |
| + contained bool |
| runtimeGeneration [32]byte |
| } |
| @@ -157,6 +186,17 @@ func openAccount(ctx context.Context, b Binding, r HomeRules) (_ *AccountLease, |
| os.RemoveAll(l.runtime) |
| return nil, e |
| } |
| + l.config, e = os.MkdirTemp(b.RuntimeRoot, "config-") |
| + if e != nil { |
| + os.RemoveAll(l.runtime) |
| + return nil, ErrPolicy |
| + } |
| + l.configInfo, e = os.Stat(l.config) |
| + if e != nil { |
| + os.RemoveAll(l.config) |
| + os.RemoveAll(l.runtime) |
| + return nil, ErrPolicy |
| + } |
| return l, nil |
| } |
| @@ -230,7 +270,7 @@ func (l *AccountLease) snapshot() ([]byte, [32]byte, error) { |
| } |
| metadata, e := readPrivate(l.dir, IdentityFile) |
| if e != nil { |
| - return nil, zero, e |
| + return nil, zero, ErrContainment |
| } |
| metadata, e = canonical(metadata) |
| if e != nil { |
| @@ -244,7 +284,7 @@ func (l *AccountLease) snapshot() ([]byte, [32]byte, error) { |
| } |
| raw, e := readPrivate(l.dir, credentialName(l.source.Provider)) |
| if e != nil { |
| - return nil, zero, e |
| + return nil, zero, ErrContainment |
| } |
| // This digest stays in memory. Stat identity detects atomic replacement |
| // even when the replacement contains identical credential bytes. |
| @@ -271,6 +311,18 @@ func (l *AccountLease) runtimeDir() (*os.File, error) { |
| } |
| return f, nil |
| } |
| +func (l *AccountLease) configDir() (*os.File, error) { |
| + f, e := pinDirectory(l.config) |
| + if e != nil { |
| + return nil, ErrPolicy |
| + } |
| + info, e := f.Stat() |
| + if e != nil || !os.SameFile(info, l.configInfo) || !privateDirectory(f) { |
| + f.Close() |
| + return nil, ErrPolicy |
| + } |
| + return f, nil |
| +} |
| func atomicPrivate(dir *os.File, name string, raw []byte) error { |
| var random [16]byte |
| if _, e := rand.Read(random[:]); e != nil { |
| @@ -330,7 +382,20 @@ func (l *AccountLease) runtimeSnapshot() ([]byte, error) { |
| return nil, e |
| } |
| defer dir.Close() |
| - return readPrivate(dir, credentialName(l.source.Provider)) |
| + metadata, e := readPrivate(dir, IdentityFile) |
| + if e != nil { |
| + return nil, ErrContainment |
| + } |
| + metadata, e = canonical(metadata) |
| + var id Identity |
| + if e != nil || json.Unmarshal(metadata, &id) != nil || id != l.source.Expected { |
| + return nil, ErrContainment |
| + } |
| + raw, e := readPrivate(dir, credentialName(l.source.Provider)) |
| + if e != nil { |
| + return nil, ErrContainment |
| + } |
| + return raw, nil |
| } |
| func (l *AccountLease) binding() Binding { |
| b := l.source |
| @@ -349,9 +414,18 @@ func (b Binding) VerifiedDedicatedHome() bool { |
| } |
| l.mu.Lock() |
| defer l.mu.Unlock() |
| - return !l.closed && b == l.binding() && l.sourceUnchanged() |
| + return !l.closed && !l.contained && b == l.binding() && l.sourceUnchanged() |
| +} |
| +func (l *AccountLease) latch(err error) { |
| + if errors.Is(err, ErrContainment) || errors.Is(err, ErrIdentity) { |
| + l.contained = true |
| + } |
| } |
| -func (l *AccountLease) validate(ctx context.Context) error { |
| +func (l *AccountLease) validate(ctx context.Context) (err error) { |
| + defer func() { l.latch(err) }() |
| + if l.contained { |
| + return ErrContainment |
| + } |
| if e := ctx.Err(); e != nil { |
| return e |
| } |
| @@ -366,19 +440,21 @@ func (l *AccountLease) validate(ctx context.Context) error { |
| } |
| return e |
| } |
| - if generation != l.generation { |
| + if generation != l.generation && l.active { |
| l.ready = false |
| - if l.active { |
| - return ErrContainment |
| - } |
| - return ErrPreflightRequired |
| + return ErrContainment |
| } |
| runtimeRaw, runtimeErr := l.runtimeSnapshot() |
| - if runtimeErr != nil || sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| + if runtimeErr != nil { |
| + l.ready = false |
| + return ErrContainment |
| + } |
| + if sha256.Sum256(runtimeRaw) != l.runtimeGeneration { |
| + l.ready = false |
| + return ErrRefreshPending |
| + } |
| + if generation != l.generation { |
| l.ready = false |
| - if l.active { |
| - return ErrContainment |
| - } |
| return ErrPreflightRequired |
| } |
| if !l.ready { |
| @@ -411,6 +487,10 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| l.mu.Unlock() |
| return e |
| } |
| + if l.contained { |
| + l.mu.Unlock() |
| + return ErrContainment |
| + } |
| if l.closed || l.active || l.checking || probe == nil { |
| l.mu.Unlock() |
| return ErrAccountMaintenance |
| @@ -418,18 +498,31 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| l.ready = false |
| _, before, e := l.snapshot() |
| if e != nil { |
| + l.latch(e) |
| l.mu.Unlock() |
| return e |
| } |
| + runtimeCurrent, runtimeErr := l.runtimeSnapshot() |
| + if runtimeErr != nil { |
| + l.contained = true |
| + l.mu.Unlock() |
| + return ErrContainment |
| + } |
| + if !refresh && sha256.Sum256(runtimeCurrent) != l.runtimeGeneration { |
| + l.mu.Unlock() |
| + return ErrRefreshPending |
| + } |
| if !refresh { |
| e = l.stage() |
| if e != nil { |
| + l.latch(e) |
| l.mu.Unlock() |
| return e |
| } |
| } |
| runtimeBefore, e := l.runtimeSnapshot() |
| if e != nil { |
| + l.latch(e) |
| l.mu.Unlock() |
| return e |
| } |
| @@ -450,10 +543,12 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| return probeErr |
| } |
| if id != l.source.Expected { |
| + l.contained = true |
| return ErrIdentity |
| } |
| _, after, e := l.snapshot() |
| if e != nil { |
| + l.latch(e) |
| return e |
| } |
| if before != after { |
| @@ -461,6 +556,7 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| } |
| runtimeAfter, e := l.runtimeSnapshot() |
| if e != nil { |
| + l.latch(e) |
| return e |
| } |
| if !bytes.Equal(runtimeBefore, runtimeAfter) { |
| @@ -470,6 +566,7 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| if e = atomicPrivate(l.dir, credentialName(l.source.Provider), runtimeAfter); e != nil { |
| return e |
| } |
| + l.runtimeGeneration = sha256.Sum256(runtimeAfter) |
| return nil |
| } |
| l.generation = after |
| @@ -486,9 +583,28 @@ func (l *AccountLease) BeginTurn(ctx context.Context) error { |
| if e := l.validate(ctx); e != nil { |
| return e |
| } |
| + if e := l.validatePolicy(); e != nil { |
| + return e |
| + } |
| l.active = true |
| return nil |
| } |
| + |
| +// ValidatePolicy rechecks policy sources before a turn or session resume. |
| +func (l *AccountLease) ValidatePolicy(ctx context.Context) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if e := l.validate(ctx); e != nil { |
| + return e |
| + } |
| + return l.validatePolicy() |
| +} |
| +func (l *AccountLease) validatePolicy() error { |
| + if l.policy == nil { |
| + return nil |
| + } |
| + return l.policy.ValidateSources(l.binding()) |
| +} |
| func (l *AccountLease) EndTurn(ctx context.Context) error { |
| l.mu.Lock() |
| defer l.mu.Unlock() |
| @@ -512,6 +628,12 @@ func (l *AccountLease) Close() error { |
| } else { |
| cleanup = ErrContainment |
| } |
| + info, e = os.Lstat(l.config) |
| + if e == nil && os.SameFile(info, l.configInfo) { |
| + cleanup = errors.Join(cleanup, os.RemoveAll(l.config)) |
| + } else { |
| + cleanup = errors.Join(cleanup, ErrContainment) |
| + } |
| return errors.Join(cleanup, l.dir.Close()) |
| } |
diff --git a/internal/runner/provider/accounts_test.go b/internal/runner/provider/accounts_test.go| index a5fb7d5a..26ec61b6 100644 |
| --- a/internal/runner/provider/accounts_test.go |
| +++ b/internal/runner/provider/accounts_test.go |
| @@ -4,8 +4,11 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "fmt" |
| "os" |
| + "os/user" |
| "path/filepath" |
| + "strconv" |
| "testing" |
| ) |
| @@ -133,7 +136,7 @@ func TestAccountHomeBinding(t *testing.T) { |
| t.Fatal("default shared home accepted") |
| } |
| } |
| - if !r.RefusesPath("/home/paulca/.paseo/zerosub/homes/fake") { |
| + if !r.RefusesPath("/home/example/.paseo/zerosub/homes/fake") { |
| t.Fatal("ZeroSub accepted") |
| } |
| }) |
| @@ -308,7 +311,7 @@ func TestAccountHomeRuntimeGuards(t *testing.T) { |
| 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) { |
| + if !errors.Is(l.EndTurn(context.Background()), Error("provider_refresh_pending")) { |
| t.Fatal("active runtime mutation accepted") |
| } |
| }) |
| @@ -431,3 +434,284 @@ func TestAccountHomePreflightGuards(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +func TestAccountRefreshPending(t *testing.T) { |
| + for _, active := range []bool{false, true} { |
| + t.Run(fmt.Sprint(active), func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + ctx := context.Background() |
| + if active { |
| + if e := l.BeginTurn(ctx); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + path := filepath.Join(l.Binding().Home, "auth.json") |
| + refreshed := `{"token":"rotated"}` |
| + writeFake(t, path, refreshed) |
| + var e error |
| + if active { |
| + e = l.EndTurn(ctx) |
| + } else { |
| + e = l.Validate(ctx) |
| + } |
| + if !errors.Is(e, Error("provider_refresh_pending")) { |
| + t.Fatalf("refresh must be pending: %v", e) |
| + } |
| + calls := 0 |
| + probe := func(context.Context, Binding) (Identity, error) { calls++; return b.Expected, nil } |
| + if e = l.Preflight(ctx, probe); !errors.Is(e, Error("provider_refresh_pending")) { |
| + t.Errorf("preflight must preserve pending refresh: %v", e) |
| + } |
| + raw, _ := os.ReadFile(path) |
| + if string(raw) != refreshed || calls != 0 { |
| + t.Fatal("preflight overwrote rotated login or probed stale login") |
| + } |
| + if e = l.CommitRefresh(ctx, probe); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e = l.BeginTurn(ctx); !errors.Is(e, ErrPreflightRequired) { |
| + t.Fatalf("refresh skipped preflight: %v", e) |
| + } |
| + preflightFixture(t, l) |
| + if e = l.BeginTurn(ctx); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e = l.EndTurn(ctx); e != nil { |
| + t.Fatal(e) |
| + } |
| + raw, _ = os.ReadFile(filepath.Join(b.Home, "auth.json")) |
| + if string(raw) != refreshed { |
| + t.Fatal("rotated login lost") |
| + } |
| + }) |
| + } |
| +} |
| +func TestAccountContainmentLatched(t *testing.T) { |
| + for _, kind := range []string{"source", "identity", "runtime-identity", "symlink", "nonregular"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + ctx := context.Background() |
| + if e := l.BeginTurn(ctx); e != nil { |
| + t.Fatal(e) |
| + } |
| + runtime := l.Binding().Home |
| + switch kind { |
| + case "source": |
| + writeFake(t, filepath.Join(b.Home, "auth.json"), `{"token":"external"}`) |
| + case "identity", "runtime-identity": |
| + home := b.Home |
| + if kind == "runtime-identity" { |
| + home = runtime |
| + } |
| + id := b.Expected |
| + id.AccountID = "changed" |
| + writeMetadata(t, home, id) |
| + case "symlink", "nonregular": |
| + path := filepath.Join(runtime, "auth.json") |
| + if e := os.Remove(path); e != nil { |
| + t.Fatal(e) |
| + } |
| + if kind == "symlink" { |
| + if e := os.Symlink(filepath.Join(b.Home, "auth.json"), path); e != nil { |
| + t.Fatal(e) |
| + } |
| + } else { |
| + if e := os.Mkdir(path, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + } |
| + if e := l.EndTurn(ctx); !errors.Is(e, ErrContainment) { |
| + t.Errorf("active tampering not contained: %v", e) |
| + } |
| + // Restore the inputs: a contained lease still cannot recover authority. |
| + writeMetadata(t, b.Home, b.Expected) |
| + writeMetadata(t, runtime, b.Expected) |
| + if kind == "symlink" || kind == "nonregular" { |
| + if e := os.Remove(filepath.Join(runtime, "auth.json")); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + writeFake(t, filepath.Join(runtime, "auth.json"), `{"token":"fake-one"}`) |
| + if e := l.Preflight(ctx, func(context.Context, Binding) (Identity, error) { return b.Expected, nil }); !errors.Is(e, ErrContainment) { |
| + t.Fatalf("containment not latched: %v", e) |
| + } |
| + if l.Binding().VerifiedDedicatedHome() { |
| + t.Fatal("contained lease retained provenance") |
| + } |
| + if e := l.BeginTurn(ctx); !errors.Is(e, ErrContainment) { |
| + t.Fatalf("contained lease admitted turn: %v", e) |
| + } |
| + |
| + }) |
| + } |
| +} |
| +func TestAccountHomeDefaultsIgnoreEnvironment(t *testing.T) { |
| + u, e := user.LookupId(strconv.Itoa(os.Geteuid())) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, home := range []string{"", t.TempDir()} { |
| + t.Setenv("HOME", home) |
| + r := DefaultHomeRules() |
| + for _, name := range []string{".claude", ".codex"} { |
| + if !r.RefusesPath(filepath.Join(u.HomeDir, name)) { |
| + t.Fatal("passwd home accepted with changed HOME") |
| + } |
| + } |
| + } |
| + for _, key := range []string{"CODEX_HOME", "CLAUDE_CONFIG_DIR"} { |
| + path := filepath.Join(t.TempDir(), "interactive") |
| + t.Setenv(key, path) |
| + if !DefaultHomeRules().RefusesPath(path) { |
| + t.Fatalf("inherited %s accepted", key) |
| + } |
| + } |
| +} |
| + |
| +func TestAccountHomeLookupFailClosed(t *testing.T) { |
| + for _, u := range []*user.User{nil, {}, {HomeDir: "relative"}, {HomeDir: "/"}} { |
| + rules := homeRules(func(string) (*user.User, error) { return u, nil }, func(string) string { return "" }) |
| + if !rules.RefusesPath("/owned/fake-home") { |
| + t.Fatal("missing passwd home accepted") |
| + } |
| + } |
| + rules := homeRules(func(string) (*user.User, error) { return nil, errors.New("lookup failed") }, func(string) string { return "" }) |
| + if !rules.RefusesPath("/owned/fake-home") { |
| + t.Fatal("failed passwd lookup accepted") |
| + } |
| +} |
| +func TestAccountRefreshPreflightPreservesLogin(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + path := filepath.Join(l.Binding().Home, "auth.json") |
| + writeFake(t, path, `{"token":"rotated"}`) |
| + e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { |
| + t.Error("pending refresh probed") |
| + return b.Expected, nil |
| + }) |
| + raw, _ := os.ReadFile(path) |
| + if string(raw) != `{"token":"rotated"}` { |
| + t.Fatal("pending refresh overwritten") |
| + } |
| + if !errors.Is(e, Error("provider_refresh_pending")) { |
| + t.Fatalf("not refresh pending: %v", e) |
| + } |
| +} |
| + |
| +func TestAccountContainmentPreflightLatched(t *testing.T) { |
| + for _, kind := range []string{"source", "identity", "runtime"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + home := b.Home |
| + if kind == "runtime" { |
| + home = l.Binding().Home |
| + } |
| + if kind == "identity" { |
| + id := b.Expected |
| + id.AccountID = "changed" |
| + writeMetadata(t, home, id) |
| + } else { |
| + if e := os.Rename(home, home+"-old"); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.Symlink(home+"-old", home); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + probe := func(context.Context, Binding) (Identity, error) { return b.Expected, nil } |
| + if e := l.Preflight(context.Background(), probe); e == nil { |
| + t.Fatal("tampered preflight accepted") |
| + } |
| + if kind == "identity" { |
| + writeMetadata(t, home, b.Expected) |
| + } else { |
| + if e := os.Remove(home); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.Rename(home+"-old", home); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + if e := l.Preflight(context.Background(), probe); !errors.Is(e, ErrContainment) { |
| + t.Fatalf("preflight containment not latched: %v", e) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestAccountContainmentSourceFile(t *testing.T) { |
| + for _, kind := range []string{"symlink", "directory"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + path := filepath.Join(b.Home, "auth.json") |
| + if e := os.Remove(path); e != nil { |
| + t.Fatal(e) |
| + } |
| + if kind == "symlink" { |
| + if e := os.Symlink(filepath.Join(l.Binding().Home, "auth.json"), path); e != nil { |
| + t.Fatal(e) |
| + } |
| + } else { |
| + if e := os.Mkdir(path, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + if e := l.Validate(context.Background()); !errors.Is(e, ErrContainment) { |
| + t.Errorf("unsafe source not contained: %v", e) |
| + } |
| + if e := os.Remove(path); e != nil { |
| + t.Fatal(e) |
| + } |
| + writeFake(t, path, `{"token":"fake-one"}`) |
| + if e := l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return b.Expected, nil }); !errors.Is(e, ErrContainment) { |
| + t.Fatalf("unsafe source containment not latched: %v", e) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestAccountRefreshFailure(t *testing.T) { |
| + for _, kind := range []string{"maintenance", "identity"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, r := accountFixture(t) |
| + l := openFixture(t, b, r) |
| + preflightFixture(t, l) |
| + path := filepath.Join(l.Binding().Home, "auth.json") |
| + writeFake(t, path, `{"token":"rotated"}`) |
| + e := l.CommitRefresh(context.Background(), func(context.Context, Binding) (Identity, error) { |
| + if kind == "maintenance" { |
| + return Identity{}, ErrAccountMaintenance |
| + } |
| + id := b.Expected |
| + id.AccountID = "different" |
| + return id, nil |
| + }) |
| + want := ErrAccountMaintenance |
| + if kind == "identity" { |
| + want = ErrIdentity |
| + } |
| + if !errors.Is(e, want) { |
| + t.Fatalf("refresh failure lost: %v", e) |
| + } |
| + raw, _ := os.ReadFile(filepath.Join(b.Home, "auth.json")) |
| + if string(raw) != `{"token":"fake-one"}` { |
| + t.Fatal("failed refresh committed") |
| + } |
| + writeFake(t, path, `{"token":"fake-one"}`) |
| + e = l.Preflight(context.Background(), func(context.Context, Binding) (Identity, error) { return b.Expected, nil }) |
| + if kind == "identity" && !errors.Is(e, ErrContainment) { |
| + t.Fatalf("wrong refresh identity not latched: %v", e) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/provider/policy.go b/internal/runner/provider/policy.go| index 7d201a1e..92dc44fb 100644 |
| --- a/internal/runner/provider/policy.go |
| +++ b/internal/runner/provider/policy.go |
| @@ -48,7 +48,7 @@ type effectiveManifest struct { |
| Files []fileDigest |
| DeniedPaths, EgressHosts, Tools []string |
| Settings, MCP, ThreadPolicy, TurnPolicy json.RawMessage |
| - Workspace, Scratch, RuntimeHome string |
| + Workspace, Scratch, RuntimeHome, ConfigHome string |
| Instructions []fileDigest |
| HooksDisabled, PluginsDisabled, TurnOverridesOmitted bool |
| MaskedDirectories []string |
| @@ -270,6 +270,11 @@ func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| } |
| env[k] = v |
| } |
| + for _, file := range append(append([]Mount(nil), in.RuntimeFiles...), in.InstructionFiles...) { |
| + if withinPath(file.Source, in.Workspace) || withinPath(file.Source, in.Scratch) { |
| + return Policy{}, ErrPolicy |
| + } |
| + } |
| files, e := hashFiles(in.RuntimeFiles, b) |
| if e != nil { |
| return Policy{}, e |
| @@ -323,7 +328,7 @@ func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| 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 := 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, ConfigHome: b.provenance.config, 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() |
| @@ -339,7 +344,7 @@ func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| if e != nil { |
| return Policy{}, e |
| } |
| - dir, e := b.provenance.runtimeDir() |
| + dir, e := b.provenance.configDir() |
| if e != nil { |
| return Policy{}, e |
| } |
| @@ -349,7 +354,43 @@ func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| } |
| 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 |
| + p := Policy{Hash: policyHash, ManifestHash: manifestHash, InstructionHash: instructionHash, Manifest: raw, Mounts: mounts, Env: env, Settings: settings, MCP: mcp, ThreadPolicy: thread, TurnPolicy: turn} |
| + b.provenance.mu.Lock() |
| + b.provenance.policy = &Policy{Manifest: bytes.Clone(raw), ManifestHash: manifestHash} |
| + b.provenance.mu.Unlock() |
| + return p, nil |
| +} |
| + |
| +// ValidateSources verifies the current generated, managed and runtime files. |
| +func (p Policy) ValidateSources(b Binding) error { |
| + var m effectiveManifest |
| + if p.ManifestHash == "" || digest(p.Manifest) != p.ManifestHash || json.Unmarshal(p.Manifest, &m) != nil { |
| + return ErrPolicy |
| + } |
| + expected := append(append([]fileDigest(nil), m.Files...), m.Instructions...) |
| + mounts := make([]Mount, 0, len(expected)) |
| + for _, f := range expected { |
| + mounts = append(mounts, f.Mount) |
| + } |
| + current, e := hashFiles(mounts, b) |
| + if e != nil || !reflect.DeepEqual(current, expected) { |
| + return ErrPolicy |
| + } |
| + if b.provenance == nil || m.ConfigHome != b.provenance.config { |
| + return ErrPolicy |
| + } |
| + dir, e := b.provenance.configDir() |
| + if e != nil { |
| + return e |
| + } |
| + defer dir.Close() |
| + for name, want := range map[string][]byte{"equipo-settings.json": m.Settings, "equipo-mcp.json": m.MCP} { |
| + raw, e := readPrivate(dir, name) |
| + if e != nil || !bytes.Equal(raw, want) { |
| + return ErrPolicy |
| + } |
| + } |
| + return nil |
| } |
| type ConfigReadback struct { |
| @@ -394,7 +435,7 @@ 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 { |
| + if l.Selection.Provider != "" || l.Binding.DedicatedHome { |
| return "", ErrPolicy |
| } |
| _, h, e := hashJSON(struct { |
| @@ -440,21 +481,9 @@ func AttestLaunch(l Launch, argv []string) (string, error) { |
| 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 { |
| + if e := p.ValidateSources(l.Binding); 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 |
| @@ -486,7 +515,7 @@ func (p Policy) ValidateNetwork(name string, hosts []string) error { |
| 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}} |
| + return []Mount{{Source: filepath.Join(b.provenance.config, "equipo-settings.json"), Target: SettingsPath, ReadOnly: true}, {Source: filepath.Join(b.provenance.config, "equipo-mcp.json"), Target: MCPPath, ReadOnly: true}} |
| } |
| // ValidateRuntimeBinaries requires the host's actual launcher and bubblewrap |
| @@ -525,10 +554,10 @@ func (p Policy) ValidateFileDigest(path, hash string) error { |
| return nil |
| } |
| } |
| - if path == filepath.Join(m.RuntimeHome, "equipo-settings.json") && digest(m.Settings) == hash { |
| + if path == filepath.Join(m.ConfigHome, "equipo-settings.json") && digest(m.Settings) == hash { |
| return nil |
| } |
| - if path == filepath.Join(m.RuntimeHome, "equipo-mcp.json") && digest(m.MCP) == hash { |
| + if path == filepath.Join(m.ConfigHome, "equipo-mcp.json") && digest(m.MCP) == hash { |
| return nil |
| } |
| return ErrPolicy |
| @@ -553,11 +582,12 @@ func policyTemplate(m effectiveManifest) effectiveManifest { |
| } |
| } |
| for i := range m.GeneratedMounts { |
| - m.GeneratedMounts[i].Source = filepath.Join("$RUNTIME_HOME", filepath.Base(m.GeneratedMounts[i].Source)) |
| + m.GeneratedMounts[i].Source = filepath.Join("$CONFIG_HOME", filepath.Base(m.GeneratedMounts[i].Source)) |
| } |
| m.Workspace = "$WORKSPACE" |
| m.Scratch = "$SCRATCH" |
| m.RuntimeHome = "$RUNTIME_HOME" |
| + m.ConfigHome = "$CONFIG_HOME" |
| m.Instructions = nil |
| return m |
| } |
diff --git a/internal/runner/provider/policy_test.go b/internal/runner/provider/policy_test.go| index 1622481f..af0df6ac 100644 |
| --- a/internal/runner/provider/policy_test.go |
| +++ b/internal/runner/provider/policy_test.go |
| @@ -310,3 +310,105 @@ func TestPrivateHomeRejectsCredentialMount(t *testing.T) { |
| t.Fatal("credential inode alias entered public manifest") |
| } |
| } |
| + |
| +func TestEffectivePolicyTurnSources(t *testing.T) { |
| + for _, kind := range []string{"settings", "mcp", "managed"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + managed := filepath.Join(t.TempDir(), "managed.json") |
| + writeFake(t, managed, `{}`) |
| + in.RuntimeFiles = append(in.RuntimeFiles, Mount{Source: managed, Target: "/etc/codex/managed.json", ReadOnly: true}) |
| + p := mustPolicy(t, b, in) |
| + ctx := context.Background() |
| + if e := b.provenance.BeginTurn(ctx); e != nil { |
| + t.Fatal(e) |
| + } |
| + path := managed |
| + for _, m := range p.Mounts { |
| + if (kind == "settings" && m.Target == SettingsPath) || (kind == "mcp" && m.Target == MCPPath) { |
| + path = m.Source |
| + } |
| + } |
| + writeFake(t, path, `{"changed":true}`) |
| + _ = b.provenance.EndTurn(ctx) |
| + if e := b.provenance.BeginTurn(ctx); e == nil { |
| + t.Fatal("changed policy admitted next turn") |
| + } |
| + }) |
| + } |
| +} |
| +func TestPrivateHomeConfigOutsideWritableMounts(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + for _, m := range p.Mounts { |
| + if m.Target == SettingsPath || m.Target == MCPPath { |
| + for _, w := range []string{b.Home, in.Workspace, in.Scratch} { |
| + if withinPath(m.Source, w) { |
| + t.Fatal("config source has writable namespace alias") |
| + } |
| + } |
| + } |
| + } |
| +} |
| +func TestEffectivePolicyRejectsWritableSource(t *testing.T) { |
| + for _, kind := range []string{"workspace", "scratch"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + root := in.Workspace |
| + if kind == "scratch" { |
| + root = in.Scratch |
| + } |
| + path := filepath.Join(root, "managed.json") |
| + writeFake(t, path, `{}`) |
| + in.RuntimeFiles = append(in.RuntimeFiles, Mount{Source: path, Target: "/etc/codex/managed.json", ReadOnly: true}) |
| + if _, e := BuildPolicy(b, in); e == nil { |
| + t.Fatal("writable managed alias accepted") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestEffectivePolicyProviderRequiresManifest(t *testing.T) { |
| + if _, e := AttestLaunch(Launch{Selection: Selection{Provider: "codex"}, Policy: Policy{Hash: "legacy"}}, []string{"/opt/codex"}); e == nil { |
| + t.Fatal("direct provider accepted legacy attestation") |
| + } |
| +} |
| + |
| +func TestEffectivePolicyConfigDirectory(t *testing.T) { |
| + for _, kind := range []string{"replacement", "mode", "cleanup", "resume"} { |
| + t.Run(kind, func(t *testing.T) { |
| + b, in := policyFixture(t) |
| + p := mustPolicy(t, b, in) |
| + l := b.provenance |
| + switch kind { |
| + case "replacement": |
| + if e := os.Rename(l.config, l.config+"-old"); e != nil { |
| + t.Fatal(e) |
| + } |
| + if e := os.Mkdir(l.config, 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + writeFake(t, filepath.Join(l.config, "equipo-settings.json"), string(p.Settings)) |
| + writeFake(t, filepath.Join(l.config, "equipo-mcp.json"), string(p.MCP)) |
| + defer func() { os.RemoveAll(l.config); os.Rename(l.config+"-old", l.config) }() |
| + case "mode": |
| + if e := os.Chmod(l.config, 0755); e != nil { |
| + t.Fatal(e) |
| + } |
| + case "cleanup": |
| + if e := l.Close(); e != nil { |
| + t.Fatal(e) |
| + } |
| + if _, e := os.Stat(l.config); !os.IsNotExist(e) { |
| + t.Fatal("config directory survived lease close") |
| + } |
| + return |
| + case "resume": |
| + writeFake(t, filepath.Join(l.config, "equipo-settings.json"), `{"changed":true}`) |
| + } |
| + if e := l.ValidatePolicy(context.Background()); e == nil { |
| + t.Fatal("changed config admitted resume") |
| + } |
| + }) |
| + } |
| +} |