fix: enforce dedicated runner users and terminal trial failures
Require dedicated-user process ownership for trial admission and report it. Keep account mismatches terminal and Codex acknowledgement independent. Bound local version reads, preserve charged waits, and allow owner revocation. Update the draft live gate and record regression and mutation checks. Validation: targeted tests and 21 guard mutations passed. Full make ci completed in one background run after the final change, exit status 0. Copy remains pending review. No live agents, enrolment, merge or deployment.
29 files changed,
+875
−54
docs/live-gate.md+45 −7docs/superpowers/plans/CONTROLLER-REPORT-supervised-trial.md+108 −0internal/equipo/copy.go+1 −1internal/equipo/runners.go+4 −2internal/equipo/supervised_trial.go+16 −6internal/equipo/team/scheduler.go+1 −1internal/equipo/team/trial_round2_test.go+14 −0internal/equipo/templates/runners.html+3 −3internal/equipotest/connections_test.go+1 −1internal/equipotest/trial_test.go+44 −3internal/runner/attempt_error.go+1 −0internal/runner/connections.go+1 −1internal/runner/connections_test.go+8 −0internal/runner/dedicated_user.go+213 −0internal/runner/dedicated_user_test.go+127 −0internal/runner/forge/publisher.go+1 −1internal/runner/forge/publisher_test.go+17 −0internal/runner/paseo/client.go+26 −3internal/runner/paseo/client_test.go+2 −2internal/runner/paseo/trial.go+5 −1internal/runner/paseo/trial_round2_test.go+72 −0internal/runner/paseo/types.go+14 −10internal/runner/runtime.go+1 −1internal/runner/trial.go+38 −5internal/runner/trial_reconnect.go+3 −3internal/runner/trial_test.go+82 −0internal/runner/workspace/workspace.go+1 −1internal/runner/workspace/workspace_test.go+24 −0internal/runnerproto/types.go+2 −2
CI cancelled — superseded by a newer push — run details
Intent
diff --git a/docs/live-gate.md b/docs/live-gate.md| index fca11242..6b53a2c0 100644 |
| --- a/docs/live-gate.md |
| +++ b/docs/live-gate.md |
| @@ -4,7 +4,9 @@ DRAFT: copy review required |
| Paul can enable supervised trial per enrolled runner in Machines. The consent |
| records the owner, time and observed Paseo and provider versions. It lapses on |
| -version changes, owner removal or demotion, or when an owner turns it off. |
| +version changes, a failed local version read, owner removal or demotion, or when |
| +an owner turns it off. Any current owner can turn trial off even if the runner |
| +revision changed or the runner person left the team. |
| Codex still needs its separate unconfined acknowledgement in Connections. |
| Without current consent, the four missing Paseo capabilities still block work. |
| @@ -12,8 +14,12 @@ Trial dispatch requests the chosen connection's credential home. An observed |
| account mismatch stops the step. Otherwise the account remains unverified; |
| Equipo never tries another account. Provider versions come from the local CLI |
| and are recorded as observed locally. Effective isolation remains unknown, so |
| -all trial work is unconfined. After a reconnect gap, the task waits for a person |
| -with its reservation charged. Steps, evidence and branch descriptions retain |
| +all trial work, including Claude, is unconfined. Anything world-readable on |
| +docs-t1, including files in `/tmp`, is exposed to trial agents. After a reconnect |
| +gap or another error during an admitted trial turn, the task waits for a person |
| +with its reservation charged. Cancel is the only exit from this wait; there is |
| +no resume or outcome-resolution action. Cancellation keeps the uncertain |
| +action and its charge. Steps, evidence and branch descriptions retain |
| both labels and the list of unverified checks after consent ends. |
| Containment, the trusted check executor, independent-family review, budgets, |
| @@ -38,11 +44,11 @@ From your own shell on docs-t1, create a user with a locked password and enable |
| its user services at boot. Do not give it SSH keys or add it to the sudo group. |
| ```sh |
| -sudo useradd --create-home --shell /bin/bash equipo-runner |
| +sudo useradd --create-home --shell /usr/sbin/nologin equipo-runner |
| sudo passwd --lock equipo-runner |
| sudo chmod 0700 /home/equipo-runner |
| sudo loginctl enable-linger equipo-runner |
| -sudo -iu equipo-runner |
| +sudo -u equipo-runner -H /bin/bash |
| ``` |
| The remaining commands in this section run in that new shell. Install the pinned |
| @@ -64,7 +70,7 @@ npm install --global @getpaseo/cli@0.14.0 @anthropic-ai/claude-code@2.1.312 @ope |
| node --version |
| claude --version |
| codex --version |
| -claude auth login --claudeai |
| +CLAUDE_CONFIG_DIR=/home/equipo-runner/.claude claude auth login --claudeai |
| codex login --device-auth |
| cd "$HOME" |
| rm "$HOME/.cache/equipo-install/node-v24.19.0-linux-x64.tar.xz" "$HOME/.cache/equipo-install/SHASUMS256.txt" |
| @@ -129,6 +135,7 @@ Type=simple |
| Environment=PATH=/home/equipo-runner/.local/bin:/usr/local/bin:/usr/bin:/bin |
| Environment=PASEO_HOME=/home/equipo-runner/.paseo |
| Environment=PASEO_LISTEN=127.0.0.1:6773 |
| +Environment=PASEO_RELAY_ENABLED=false |
| Environment=TMPDIR=/home/equipo-runner/.cache/tmp |
| Environment=DISABLE_AUTOUPDATER=1 |
| ExecStart=/home/equipo-runner/.local/bin/paseo daemon run --home /home/equipo-runner/.paseo |
| @@ -140,9 +147,13 @@ WantedBy=default.target |
| UNIT |
| systemctl --user daemon-reload |
| systemctl --user enable --now equipo-paseo.service |
| +ss -ltnp 'sport = :6773' |
| paseo daemon status --home "$HOME/.paseo" --json |
| ``` |
| +Check that `ss` lists only `127.0.0.1:6773` for this daemon. Stop the service |
| +if it listens on another address. Relay access is disabled in the unit. |
| + |
| Record the daemon's server ID and observed version from that status. This daemon |
| must be version 0.14.0. Do not point the runner at Paul's existing daemon. |
| @@ -177,6 +188,14 @@ systemctl --user daemon-reload |
| systemctl --user enable --now equipo-runner.service |
| ``` |
| +Exit the setup shell after starting the runner service. Trial preflight refuses |
| +login shells, unlocked passwords, a Paseo home outside the runner user's home, |
| +and unrelated processes owned by that UID. The runner checks the lock with |
| +`passwd -S` and reports `dedicated_user` in each connection's routing capabilities. |
| +Only the runner tree, its Paseo daemon tree, user systemd and tracked attempts |
| +are allowed. Other user services also block trial admission; stop them before |
| +starting work. Reopen a temporary shell only for maintenance, then close it. |
| + |
| Open the displayed approval page and check the origin and machine fingerprint. |
| In Machines, enable supervised trial after fresh connection reports arrive. |
| Then acknowledge the exact Codex connection in Connections and enable the chosen |
| @@ -319,6 +338,22 @@ A missing receipt or uncertain containment must remain unknown and charged, |
| never stopped or succeeded. Preserve the gate evidence, remove only owned |
| scratch and sentinels, and leave only the service you installed running. |
| +## End the trial |
| + |
| +Turn trial off in Machines and cancel any waiting tasks. Wait for containment |
| +before stopping the services. Save the nonsecret gate evidence you need; deleting |
| +the user removes its credentials, journal and workspaces. |
| + |
| +From your normal user shell, stop both services and remove only this trial user: |
| + |
| +```sh |
| +RUNNER_UID=$(id -u equipo-runner) |
| +sudo -u equipo-runner env XDG_RUNTIME_DIR=/run/user/$RUNNER_UID DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$RUNNER_UID/bus systemctl --user disable --now equipo-runner.service equipo-paseo.service |
| +sudo loginctl disable-linger equipo-runner |
| +sudo loginctl terminate-user equipo-runner |
| +sudo userdel -r equipo-runner |
| +``` |
| + |
| ## Reset a blocked journal |
| Stop the user service before running `equipo-runner reset` with the same runner |
| @@ -333,7 +368,10 @@ fresh authority and timeline recovery. |
| ## Runner environment |
| -All these settings are required for run, enrol, preflight and reset. Examples use the dedicated equipo-runner user. Replace the instance values and |
| +These settings configure run, enrol, preflight and reset. `EQUIPO_CLAUDE_PATH` |
| +is needed only for a local Claude version read after a strict preflight failure |
| +or when trial consent is present. A failed read ends that consent. Examples use the dedicated equipo-runner user. Replace the instance |
| +values and |
| observed identities with your own. Diagnostics print a reason code and variable name, never its |
| value. `runner.config.path` means the path must be absolute and canonical; |
| `runner.config.overlap` means it overlaps the private state directory. |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-supervised-trial.md b/docs/superpowers/plans/CONTROLLER-REPORT-supervised-trial.md| index d64dbfcb..4d8428ef 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-supervised-trial.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-supervised-trial.md |
| @@ -129,3 +129,111 @@ No machine was enrolled, no real Paseo agent or service was started, and no sudo |
| merge or deployment command was executed. Only test fixtures and local inspection |
| were used. The final handback records the commit, push and CI result. Task scratch |
| and test processes are removed before handback. |
| + |
| +## Round 2 review fixes, 2026-11-03 |
| + |
| +Applied `trial2-brief.md` from `ad32cda`. No other agents, copy-review server, |
| +enrolment, deployment or real Paseo agents were used. |
| + |
| +Trial preflight now requires a dedicated UID. It reads the account database, |
| +refuses login shells, checks the locked password status without reading password |
| +hashes, and checks that the canonical Paseo home belongs to that user inside its |
| +home. Every live process with that UID must belong to the runner, its installed |
| +Paseo CLI daemon tree, user systemd, or an open tracked attempt. Arbitrary user |
| +services, unrelated Node scripts, closed attempts and old boot records cannot |
| +supply ownership. The connection report carries `routing.dedicated_user`; the |
| +server requires it for trial routing. Missing observations deny admission. |
| + |
| +An observed account mismatch has the terminal reason `account_mismatch`, both |
| +at preflight and after agent creation. The scheduler refuses another attempt |
| +regardless of the task's retry allowance. Both runner trial authorization and |
| +workspace admission require Codex's separate acknowledgement, including the |
| +current authorization returned by the instance. |
| + |
| +Local version reads retain at most 256 bytes and discard stderr. They run only |
| +when strict preflight failed or the current assignment carries trial consent. |
| +A failed read clears the version observation, which ends saved consent. The |
| +publisher requires both `supervised trial` and `unconfined` in a trial branch |
| +description. Other errors during an interrupted, admitted trial turn now keep |
| +the same charged human wait as reconnect errors; account mismatches remain |
| +terminal. Cancel is the documented exit from the wait. No outcome-resolution |
| +action was added. |
| + |
| +A current owner can turn trial off with a stale runner revision or after the |
| +runner person leaves the roster. Revoked runners with saved trial consent remain |
| +visible to owners until trial is off. Enable and ordinary revoke controls are |
| +hidden for those revoked runners. Authority still comes from the current owner |
| +inside the write transaction, and disablement is audited. |
| + |
| +The live-gate draft uses a non-login shell, names Claude's login directory, |
| +disables the Paseo relay, checks the listener with `ss -ltnp`, and explains that |
| +all trial work, including Claude, can read world-readable files on docs-t1. |
| +It includes service shutdown, lingering removal and user deletion. Temporary |
| +setup shells and unrelated user services must stop before trial admission. |
| + |
| +### Tests and guard checks |
| + |
| +The first regression run failed on strict preflight running the provider CLI, |
| +account mismatch losing its terminal reason, a second scheduler attempt after |
| +mismatch, non-reconnect errors failing the job, missing trial publication labels, |
| +and trial disablement with a stale revision or removed person. After correcting |
| +two fixture prerequisites, the workspace acknowledgement and publication tests |
| +also failed on their intended guards. The new dedicated-user tests initially |
| +failed to compile because the checks did not exist. The owner-page test failed |
| +because the disable action disappeared when its runner was revoked. A separate |
| +process test accepted an unrelated Node script before CLI identity was checked. |
| + |
| +The restored targeted command passed: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/paseo ./internal/runner ./internal/runner/workspace ./internal/runner/forge ./internal/equipo/team ./internal/equipotest -run 'TestSupervisedTrial|TestTrial|TestRunnerService|TestPreflight|TestConnections' -count=1 |
| +``` |
| + |
| +The full Paseo adapter Go package passed. All 31 bridge tests passed with |
| +`node --test runner/paseo/bridge.test.mjs`. `sh -n scripts/live-gate.sh`, |
| +`git diff --check`, and `make vet fmt-check staticcheck budget` passed. |
| + |
| +Each mutation below was applied alone, caused a test failure, and was restored. |
| +The command for each row was |
| +`CGO_ENABLED=0 go test <package> -run '^<test>$' -count=1`. |
| + |
| +| Guard removed | Package | Failing test | |
| +| --- | --- | --- | |
| +| Non-login shell | `./internal/runner` | `TestTrialDedicatedIdentity/shell` | |
| +| Locked password | `./internal/runner` | `TestTrialDedicatedIdentity/password` | |
| +| Paseo home inside own home | `./internal/runner` | `TestTrialDedicatedIdentity/outside` | |
| +| Reject unrelated UID processes | `./internal/runner` | `TestTrialDedicatedProcessInventory/shared` | |
| +| Verify installed Paseo CLI | `./internal/runner` | `TestTrialDedicatedProcessInventory/unrelated-node` | |
| +| Dedicated UID trial capability | `./internal/runner/paseo` | `TestTrialSharedUIDRefused` | |
| +| Server requires dedicated UID | `./internal/equipotest` | `TestSupervisedTrialConsent/dedicated` | |
| +| Terminal account mismatch | `./internal/equipo/team` | `TestTrialAccountMismatchNoSecondAttempt` | |
| +| Typed mismatch after creation | `./internal/runner/paseo` | `TestTrialAccountMismatchTyped` | |
| +| Workspace Codex acknowledgement | `./internal/runner/workspace` | `TestTrialCodexRequiresSeparateAcknowledgement` | |
| +| Local Codex acknowledgement | `./internal/runner` | `TestTrialRuntimeCodexAcknowledgement` | |
| +| Current Codex acknowledgement | `./internal/runner` | `TestTrialRuntimeCodexAcknowledgement` | |
| +| Version output limit | `./internal/runner` | `TestTrialVersionOutputBounded` | |
| +| Strict preflight skips local read | `./internal/runner/paseo` | `TestTrialStrictPreflightSkipsLocalVersion` | |
| +| Trial consent forces local read | `./internal/runner/paseo` | `TestTrialConsentForcesLocalVersion` | |
| +| Failed read clears version | `./internal/runner/paseo` | `TestTrialVersionFailureClearsObservation` | |
| +| Trial publication label | `./internal/runner/forge` | `TestTrialPublisherRequiresBothLabels` | |
| +| Other interrupted errors wait | `./internal/runner` | `TestTrialOtherTurnErrorWaits` | |
| +| Disable ignores stale revision | `./internal/equipotest` | `TestTrialDisableIgnoresStaleRunnerAndRemovedMember/revision` | |
| +| Disable permits revoked runner | `./internal/equipotest` | `TestTrialDisableIgnoresStaleRunnerAndRemovedMember/removed` | |
| +| Revoked runner keeps disable action | `./internal/equipotest` | `TestTrialRevokedRunnerKeepsDisableAction` | |
| + |
| +The failed-version mutation first exposed a weak fixture: its version was already |
| +empty. The corrected fixture starts with a reported version and trial consent; |
| +removing the clearing guard then failed the test. The guard was restored. |
| + |
| +The final full gate is `make ci`, started in the background after these source, |
| +test and report changes, with network access and default Go caches. Its log is |
| +polled until the process exits; the five-line handback records the exit status. |
| +This report is written before that run so the final gate covers it too. |
| + |
| +### Copy awaiting review |
| + |
| +The changed app string is `trial.reconnect`: `trial outcome uncertain`. It stays |
| +individually marked pending in `internal/equipo/copy.go`. The diagnostic reason |
| +`dedicated_user_required` is new; `account_mismatch` is now also a terminal |
| +attempt reason. Review these with `docs/live-gate.md` and this draft report. |
| +README prose is unchanged. No copy-review server was started. |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 181d9219..73360e69 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -212,7 +212,7 @@ var runnerDraftCopy = map[string]string{ |
| // COPY REVIEW REQUIRED: trial.meaning |
| "trial.meaning": "Every step on this runner is unconfined. Account binding, automatic account changes, effective isolation and completion after reconnect remain unverified. Provider versions are observed locally. Consent lapses on version changes or when its owner loses their role.", |
| // COPY REVIEW REQUIRED: trial.reconnect |
| - "trial.reconnect": "outcome uncertain after reconnect", |
| + "trial.reconnect": "trial outcome uncertain", |
| // COPY REVIEW REQUIRED: trial.observed_locally |
| "trial.observed_locally": "Provider version observed locally", |
| // COPY REVIEW REQUIRED: trial.check.account_unverified |
diff --git a/internal/equipo/runners.go b/internal/equipo/runners.go| index 96d46a0a..108b03cd 100644 |
| --- a/internal/equipo/runners.go |
| +++ b/internal/equipo/runners.go |
| @@ -185,9 +185,11 @@ func (s *Store) runnersFor(ctx context.Context, actor Actor) ([]Runner, error) { |
| if err != nil { |
| return err |
| } |
| - query := tx.Where("instance_id = ? AND revoked_at IS NULL", instance) |
| + query := tx.Where("instance_id = ?", instance) |
| if member.Role != RoleOwner { |
| - query = query.Where("person = ?", member.Address) |
| + query = query.Where("revoked_at IS NULL AND person = ?", member.Address) |
| + } else { |
| + query = query.Where("revoked_at IS NULL OR id IN (SELECT runner_id FROM supervised_trials WHERE revoked_at IS NULL)") |
| } |
| var records []runnerRecord |
| if err := query.Order("id").Find(&records).Error; err != nil { |
diff --git a/internal/equipo/supervised_trial.go b/internal/equipo/supervised_trial.go| index 8027fe21..32a737ae 100644 |
| --- a/internal/equipo/supervised_trial.go |
| +++ b/internal/equipo/supervised_trial.go |
| @@ -26,7 +26,7 @@ func (supervisedTrialRecord) TableName() string { return "supervised_trials" } |
| func trialRouting(r ConnectionReport) bool { |
| v := r.Routing |
| - return r.TrialReady && r.ProviderVersionSource == "observed_locally" && r.ProviderVersion != "" && r.PaseoVersion != "" && v.BindingID != "" && v.AccountID != "" && hexHash(v.CredentialHomeHash) && v.ProcessOwnership && (v.ObservedAccountID == "" || v.ObservedAccountID == v.AccountID) |
| + return r.TrialReady && r.ProviderVersionSource == "observed_locally" && r.ProviderVersion != "" && r.PaseoVersion != "" && v.BindingID != "" && v.AccountID != "" && hexHash(v.CredentialHomeHash) && v.ProcessOwnership && v.DedicatedUser && (v.ObservedAccountID == "" || v.ObservedAccountID == v.AccountID) |
| } |
| func trialVersions(rows []connectionRecord) (string, error) { |
| versions := []string{} |
| @@ -93,15 +93,25 @@ func (s *Store) SetSupervisedTrial(ctx context.Context, actor Actor, runner stri |
| if err != nil { |
| return err |
| } |
| - machine, err := runnerAt(tx, instance, runner) |
| + var machine runnerRecord |
| + if enabled { |
| + machine, err = runnerAt(tx, instance, runner) |
| + } else { |
| + err = tx.Where("id=? AND instance_id=?", runner, instance).First(&machine).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + return ErrForbidden |
| + } |
| + } |
| if err != nil { |
| - return err |
| + return storeError(err) |
| } |
| - if machine.Revision != revision { |
| + if enabled && machine.Revision != revision { |
| return ErrConflict |
| } |
| - if _, err := currentRunnerMember(tx, machine.Person); err != nil { |
| - return err |
| + if enabled { |
| + if _, err := currentRunnerMember(tx, machine.Person); err != nil { |
| + return err |
| + } |
| } |
| var rows []connectionRecord |
| if err := tx.Where("runner_id=?", runner).Find(&rows).Error; err != nil { |
diff --git a/internal/equipo/team/scheduler.go b/internal/equipo/team/scheduler.go| index 9391d3d6..cc67a877 100644 |
| --- a/internal/equipo/team/scheduler.go |
| +++ b/internal/equipo/team/scheduler.go |
| @@ -309,7 +309,7 @@ func (s *Store) Complete(ctx context.Context, scope Scope, h Handle, r AttemptRe |
| aState, sState := AttemptSucceeded, StepSucceeded |
| if r.Outcome == OutcomeFailure { |
| aState, sState = AttemptFailed, StepPending |
| - if hd.job.Evidence.RequireBugFreeze || hd.step.Attempts >= hd.job.Policy.MaxAttemptsPerStep { |
| + if r.Detail == "account_mismatch" || hd.job.Evidence.RequireBugFreeze || hd.step.Attempts >= hd.job.Policy.MaxAttemptsPerStep { |
| sState = StepFailed |
| } |
| // Intents never dispatched hold budget for nothing; in-flight |
diff --git a/internal/equipo/team/trial_round2_test.go b/internal/equipo/team/trial_round2_test.go| new file mode 100644 |
| index 00000000..b2a4a8e2 |
| --- /dev/null |
| +++ b/internal/equipo/team/trial_round2_test.go |
| @@ -0,0 +1,14 @@ |
| +package team |
| + |
| +import "testing" |
| + |
| +func TestTrialAccountMismatchNoSecondAttempt(t *testing.T) { |
| + e := newEnv(t) |
| + _, scope := e.createJob(softwareSpec(SoftwareSteps(false))) |
| + h := e.claim(scope, "reproduce", "runner", "workspace") |
| + must(t, e.store.Complete(e.ctx, scope, h, AttemptResult{Outcome: OutcomeFailure, Detail: "account_mismatch"})) |
| + must(t, e.store.Contain(e.ctx, scope, h.Attempt, "contained")) |
| + if _, err := e.store.Claim(e.ctx, scope, "reproduce", "runner", "another-workspace"); err == nil { |
| + t.Fatal("account mismatch admitted second attempt") |
| + } |
| +} |
diff --git a/internal/equipo/templates/runners.html b/internal/equipo/templates/runners.html| index cf94419d..60da0743 100644 |
| --- a/internal/equipo/templates/runners.html |
| +++ b/internal/equipo/templates/runners.html |
| @@ -30,11 +30,11 @@ |
| <dt>{{copy "runner.fingerprint"}}</dt><dd>{{.MachineKeyHash}}</dd> |
| </dl> |
| {{if .TrialOwner}}<p>{{copy "trial.label"}}: {{.TrialOwner}} / {{.TrialAt}}</p><pre>{{.TrialVersions}}</pre>{{else}}<p>{{copy "trial.off"}}</p>{{end}} |
| -{{if $.Owner}}<p>{{copy "trial.meaning"}}</p><form method="post" action="/runners/{{.ID}}/supervised-trial" equipo-form><input type="hidden" name="revision" value="{{.Revision}}"><button rst-btn name="enabled" value="true">{{copy "trial.enable"}}</button><button rst-btn name="enabled" value="false">{{copy "trial.disable"}}</button></form>{{end}} |
| -<form method="post" action="/runners/{{.ID}}/revoke" equipo-form> |
| +{{if $.Owner}}<p>{{copy "trial.meaning"}}</p><form method="post" action="/runners/{{.ID}}/supervised-trial" equipo-form><input type="hidden" name="revision" value="{{.Revision}}">{{if not .RevokedAt}}<button rst-btn name="enabled" value="true">{{copy "trial.enable"}}</button>{{end}}<button rst-btn name="enabled" value="false">{{copy "trial.disable"}}</button></form>{{end}} |
| +{{if not .RevokedAt}}<form method="post" action="/runners/{{.ID}}/revoke" equipo-form> |
| <input type="hidden" name="revision" value="{{.Revision}}"> |
| <button rst-btn type="submit">{{copy "runner.revoke"}}</button> |
| -</form> |
| +</form>{{end}} |
| </section> |
| {{else}}<p>{{copy "runner.empty"}}</p>{{end}} |
| {{end}} |
diff --git a/internal/equipotest/connections_test.go b/internal/equipotest/connections_test.go| index cee688c6..a7d28795 100644 |
| --- a/internal/equipotest/connections_test.go |
| +++ b/internal/equipotest/connections_test.go |
| @@ -24,7 +24,7 @@ func connectionReport(local, provider, family, model string) equipo.ConnectionRe |
| if provider == "codex" { |
| version = "0.165.0" |
| } |
| - return equipo.ConnectionReport{LocalID: local, Provider: provider, ProviderVersion: version, PaseoVersion: "0.14.0", Family: family, Model: model, AccountLabel: "shared@example.com", Kind: "subscription", Available: true, ReadIsolation: true, IsolationConfigHash: strings.Repeat("a", 64), Routing: equipo.ConnectionRouting{BindingID: local, AccountID: "opaque-" + local, ObservedAccountID: "opaque-" + local, CredentialHomeHash: strings.Repeat("b", 64), AccountPinned: true, NoFailover: true, TimelineRecovery: true, ProcessOwnership: true}} |
| + return equipo.ConnectionReport{LocalID: local, Provider: provider, ProviderVersion: version, PaseoVersion: "0.14.0", Family: family, Model: model, AccountLabel: "shared@example.com", Kind: "subscription", Available: true, ReadIsolation: true, IsolationConfigHash: strings.Repeat("a", 64), Routing: equipo.ConnectionRouting{BindingID: local, AccountID: "opaque-" + local, ObservedAccountID: "opaque-" + local, CredentialHomeHash: strings.Repeat("b", 64), AccountPinned: true, NoFailover: true, TimelineRecovery: true, ProcessOwnership: true, DedicatedUser: true}} |
| } |
| func connectionTuple(r equipo.ConnectionReport) team.IsolationTuple { |
| return team.IsolationTuple{Provider: r.Provider, ProviderVersion: r.ProviderVersion, PaseoVersion: r.PaseoVersion, IsolationConfigHash: r.IsolationConfigHash} |
diff --git a/internal/equipotest/trial_test.go b/internal/equipotest/trial_test.go| index fe8c6f20..4848aa80 100644 |
| --- a/internal/equipotest/trial_test.go |
| +++ b/internal/equipotest/trial_test.go |
| @@ -29,7 +29,7 @@ func trialFixture(t *testing.T) connectionFixture { |
| return f |
| } |
| func TestSupervisedTrialConsent(t *testing.T) { |
| - for _, change := range []string{"off", "on", "revoke", "provider", "server", "demote", "remove", "mismatch", "containment"} { |
| + for _, change := range []string{"off", "on", "revoke", "provider", "server", "demote", "remove", "mismatch", "containment", "dedicated", "version-read"} { |
| t.Run(change, func(t *testing.T) { |
| f := trialFixture(t) |
| setMember(t, f.s, "trial@example.com", equipo.RoleOwner, true) |
| @@ -54,10 +54,14 @@ func TestSupervisedTrialConsent(t *testing.T) { |
| setMember(t, f.s, actor.Address, equipo.RoleOwner, false) |
| case "mismatch": |
| f.reports[0].Routing.ObservedAccountID = "different" |
| + case "dedicated": |
| + f.reports[0].Routing.DedicatedUser = false |
| + case "version-read": |
| + f.reports[0].ProviderVersion = "" |
| case "containment": |
| f.reports[0].Routing.ProcessOwnership = false |
| } |
| - if change == "provider" || change == "server" || change == "mismatch" || change == "containment" { |
| + if change == "provider" || change == "server" || change == "mismatch" || change == "containment" || change == "dedicated" || change == "version-read" { |
| if err := f.s.ReportConnections(connectionContext, f.principal, f.reports); err != nil { |
| t.Fatal(err) |
| } |
| @@ -70,7 +74,7 @@ func TestSupervisedTrialConsent(t *testing.T) { |
| } else { |
| f.denied(t, "product", "") |
| } |
| - if change == "provider" || change == "server" { |
| + if change == "provider" || change == "server" || change == "version-read" { |
| f.reports[0] = trialFixtureReport(f.reports[0]) |
| if err := f.s.ReportConnections(connectionContext, f.principal, f.reports); err != nil { |
| t.Fatal(err) |
| @@ -155,3 +159,40 @@ func TestTrialOwnerAndFreshReports(t *testing.T) { |
| } |
| f.denied(t, "product", "") |
| } |
| + |
| +func TestTrialDisableIgnoresStaleRunnerAndRemovedMember(t *testing.T) { |
| + for _, change := range []string{"revision", "removed"} { |
| + t.Run(change, func(t *testing.T) { |
| + f := trialFixture(t) |
| + setMember(t, f.s, "trial@example.com", equipo.RoleOwner, true) |
| + actor := equipo.Actor{Address: "trial@example.com"} |
| + executionMust(t, f.s.SetSupervisedTrial(connectionContext, actor, f.principal.RunnerID, 1, true)) |
| + if change == "removed" { |
| + owners := projectOwners() |
| + for i := range owners { |
| + owners[i].Address = actor.Address |
| + } |
| + saveProject(t, f.s, f.project, owners, "reassign-trial") |
| + setMember(t, f.s, ownerActor.Address, equipo.RoleOwner, false) |
| + } |
| + executionMust(t, f.s.SetSupervisedTrial(connectionContext, actor, f.principal.RunnerID, 99, false)) |
| + }) |
| + } |
| +} |
| + |
| +func TestTrialRevokedRunnerKeepsDisableAction(t *testing.T) { |
| + f := trialFixture(t) |
| + executionMust(t, f.s.SetSupervisedTrial(connectionContext, ownerActor, f.principal.RunnerID, 1, true)) |
| + executionMust(t, f.s.RevokeRunner(connectionContext, ownerActor, f.principal.RunnerID, 1)) |
| + server, c := taskPageServer(t, f, false) |
| + body := taskGet(t, c, server.URL, "/runners/enrol", 200) |
| + action := "/runners/" + f.principal.RunnerID + "/supervised-trial" |
| + if !strings.Contains(body, action) { |
| + t.Fatal("owner cannot turn revoked runner trial off") |
| + } |
| + executionMust(t, f.s.SetSupervisedTrial(connectionContext, ownerActor, f.principal.RunnerID, 1, false)) |
| + body = taskGet(t, c, server.URL, "/runners/enrol", 200) |
| + if strings.Contains(body, action) { |
| + t.Fatal("disabled revoked runner retained") |
| + } |
| +} |
diff --git a/internal/runner/attempt_error.go b/internal/runner/attempt_error.go| index 30633cc8..52ee9eb6 100644 |
| --- a/internal/runner/attempt_error.go |
| +++ b/internal/runner/attempt_error.go |
| @@ -42,6 +42,7 @@ func attemptFailureReason(err error) string { |
| err error |
| reason string |
| }{ |
| + {paseo.ErrAccountMismatch, "account_mismatch"}, |
| {ErrPromptTooLarge, "runner.prompt_too_large"}, {team.ErrEvidence, "runner.evidence"}, |
| {team.ErrBudget, "runner.budget"}, {team.ErrQuota, "runner.quota"}, {team.ErrReplayUnsafe, "runner.replay"}, |
| } { |
diff --git a/internal/runner/connections.go b/internal/runner/connections.go| index dda969bd..7ddd0340 100644 |
| --- a/internal/runner/connections.go |
| +++ b/internal/runner/connections.go |
| @@ -113,7 +113,7 @@ func connectionReport(b AccountBinding, p paseo.ReadPolicy, c paseo.Capabilities |
| if !ready && reason == "" { |
| reason = "capability_unverified" |
| } |
| - return runnerproto.ConnectionReport{TrialReady: c.TrialReady && (err == nil || err == paseo.ErrCapability || err == paseo.ErrIsolation || err == paseo.ErrPolicy), ProviderVersionSource: c.ProviderVersionSource, LocalID: b.LocalID, Provider: b.Provider, Family: b.Family, Model: b.Model, Kind: b.Kind, ProviderVersion: c.ProviderVersion, PaseoVersion: c.PaseoVersion, IsolationConfigHash: p.ConfigHash, Available: ready, ReadIsolation: confined, UnavailableReason: reason, Routing: runnerproto.ConnectionRouting{BindingID: b.ID, AccountID: b.AccountID, ObservedAccountID: c.ObservedAccount, CredentialHomeHash: hex.EncodeToString(hash[:]), AccountPinned: c.AccountPinning && routingObserved, NoFailover: c.NoFailover, TimelineRecovery: c.RecoverableTimeline, ProcessOwnership: c.ProcessOwnership}} |
| + return runnerproto.ConnectionReport{TrialReady: c.TrialReady && (err == nil || err == paseo.ErrCapability || err == paseo.ErrIsolation || err == paseo.ErrPolicy), ProviderVersionSource: c.ProviderVersionSource, LocalID: b.LocalID, Provider: b.Provider, Family: b.Family, Model: b.Model, Kind: b.Kind, ProviderVersion: c.ProviderVersion, PaseoVersion: c.PaseoVersion, IsolationConfigHash: p.ConfigHash, Available: ready, ReadIsolation: confined, UnavailableReason: reason, Routing: runnerproto.ConnectionRouting{BindingID: b.ID, AccountID: b.AccountID, ObservedAccountID: c.ObservedAccount, CredentialHomeHash: hex.EncodeToString(hash[:]), AccountPinned: c.AccountPinning && routingObserved, NoFailover: c.NoFailover, TimelineRecovery: c.RecoverableTimeline, ProcessOwnership: c.ProcessOwnership, DedicatedUser: c.DedicatedUser}} |
| } |
| func discover(ctx context.Context, c Config, client *paseo.Client) ([]runnerproto.ConnectionReport, error) { |
| bs, err := loadBindings(c.AccountBindingsPath) |
diff --git a/internal/runner/connections_test.go b/internal/runner/connections_test.go| index 7491c1f0..424a1c77 100644 |
| --- a/internal/runner/connections_test.go |
| +++ b/internal/runner/connections_test.go |
| @@ -88,3 +88,11 @@ func TestRunnerServiceUsesLinuxInspector(t *testing.T) { |
| t.Fatal("signalled unattributed child") |
| } |
| } |
| + |
| +func TestTrialDedicatedCapabilityReported(t *testing.T) { |
| + caps := paseo.Capabilities{TrialReady: true, DedicatedUser: true, ProcessOwnership: true} |
| + report := connectionReport(AccountBinding{}, paseo.ReadPolicy{}, caps, paseo.ErrCapability) |
| + if !report.Routing.DedicatedUser || !report.Routing.ProcessOwnership || !report.TrialReady { |
| + t.Fatal("dedicated capability lost", report) |
| + } |
| +} |
diff --git a/internal/runner/dedicated_user.go b/internal/runner/dedicated_user.go| new file mode 100644 |
| index 00000000..8a3a59f8 |
| --- /dev/null |
| +++ b/internal/runner/dedicated_user.go |
| @@ -0,0 +1,213 @@ |
| +package runner |
| + |
| +import ( |
| + "context" |
| + "io" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "slices" |
| + "strconv" |
| + "strings" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/paseo" |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +func boundedCommand(ctx context.Context, limit int, path string, args ...string) ([]byte, error) { |
| + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) |
| + defer cancel() |
| + cmd := exec.CommandContext(ctx, path, args...) |
| + cmd.WaitDelay = time.Second |
| + cmd.Env = []string{"PATH=/usr/bin:/bin", "LANG=C", "LC_ALL=C"} |
| + out := limitedOutput{limit: limit} |
| + cmd.Stdout, cmd.Stderr = &out, io.Discard |
| + if err := cmd.Run(); err != nil || out.overflow { |
| + return nil, paseo.ErrCapability |
| + } |
| + return out.Bytes(), nil |
| +} |
| + |
| +func dedicatedIdentity(passwd []byte, uid int, daemon string, status func(string) ([]byte, error)) error { |
| + found := false |
| + for _, line := range strings.Split(strings.TrimSpace(string(passwd)), "\n") { |
| + fields := strings.Split(line, ":") |
| + if len(fields) != 7 { |
| + return paseo.ErrCapability |
| + } |
| + if fields[2] != strconv.Itoa(uid) { |
| + continue |
| + } |
| + found = true |
| + if !slices.Contains([]string{"/usr/sbin/nologin", "/sbin/nologin", "/bin/false", "/usr/bin/false"}, fields[6]) { |
| + return paseo.ErrCapability |
| + } |
| + home, err := filepath.EvalSymlinks(fields[5]) |
| + resolved, daemonErr := filepath.EvalSymlinks(daemon) |
| + if err != nil || daemonErr != nil || !filepath.IsAbs(home) || home == "/" || resolved != daemon || !strings.HasPrefix(resolved, home+"/") { |
| + return paseo.ErrCapability |
| + } |
| + var st unix.Stat_t |
| + if unix.Stat(home, &st) != nil || st.Uid != uint32(uid) { |
| + return paseo.ErrCapability |
| + } |
| + if unix.Stat(resolved, &st) != nil || st.Uid != uint32(uid) { |
| + return paseo.ErrCapability |
| + } |
| + // passwd -S can report the caller's own lock state without reading hashes. |
| + raw, err := status(fields[0]) |
| + state := strings.Fields(string(raw)) |
| + if err != nil || len(state) < 2 || state[0] != fields[0] || state[1] != "L" { |
| + return paseo.ErrCapability |
| + } |
| + } |
| + if !found { |
| + return paseo.ErrCapability |
| + } |
| + return nil |
| +} |
| + |
| +func (r *Runtime) dedicatedUser(ctx context.Context) (bool, error) { |
| + if r.inspector == nil { |
| + return false, paseo.ErrCapability |
| + } |
| + passwd, err := boundedCommand(ctx, 1<<20, "/usr/bin/getent", "passwd") |
| + if err != nil { |
| + return false, err |
| + } |
| + if err = dedicatedIdentity(passwd, os.Getuid(), r.cfg.PaseoHome, func(name string) ([]byte, error) { |
| + return boundedCommand(ctx, 1024, "/usr/bin/passwd", "-S", name) |
| + }); err != nil { |
| + return false, err |
| + } |
| + host := &LinuxProcessInspector{root: "/proc", boot: r.inspector.boot} |
| + id, err := host.identity(os.Getpid()) |
| + if err != nil { |
| + return false, err |
| + } |
| + node, err := filepath.EvalSymlinks(r.cfg.NodePath) |
| + if err != nil { |
| + return false, err |
| + } |
| + return r.inspector.dedicatedProcesses(ctx, r.cfg.PaseoHome, node, id) |
| +} |
| + |
| +// Unlike ordinary inventory, trial admission also accounts for pre-existing |
| +// processes. User systemd is allowed itself, not all services it might start. |
| +func (p *LinuxProcessInspector) dedicatedProcesses(ctx context.Context, home, node string, runner ProcessIdentity) (bool, error) { |
| + p.mu.Lock() |
| + defer p.mu.Unlock() |
| + dirs, err := os.ReadDir(p.root) |
| + if err != nil { |
| + return false, err |
| + } |
| + all := map[int]procEntry{} |
| + allowed, trees := map[int]bool{}, map[int]bool{} |
| + systemd := map[int]bool{} |
| + pam := map[int]bool{} |
| + for _, dir := range dirs { |
| + if ctx.Err() != nil { |
| + return false, ctx.Err() |
| + } |
| + pid, err := strconv.Atoi(dir.Name()) |
| + if err != nil || pid <= 0 { |
| + continue |
| + } |
| + path := filepath.Join(p.root, dir.Name()) |
| + var st unix.Stat_t |
| + if err := unix.Stat(path, &st); err != nil { |
| + if os.IsNotExist(err) { |
| + continue |
| + } |
| + return false, err |
| + } |
| + if st.Uid != uint32(os.Getuid()) { |
| + continue |
| + } |
| + e, err := p.entry(pid) |
| + if err != nil { |
| + if _, statErr := os.Stat(path); os.IsNotExist(statErr) { |
| + continue |
| + } |
| + return false, paseo.ErrUncertain |
| + } |
| + if e.dead { |
| + continue |
| + } |
| + all[pid] = e |
| + if e.id == runner { |
| + allowed[pid], trees[pid] = true, true |
| + continue |
| + } |
| + raw, argsErr := os.ReadFile(filepath.Join(path, "cmdline")) |
| + env, envErr := os.ReadFile(filepath.Join(path, "environ")) |
| + exe, exeErr := os.Readlink(filepath.Join(path, "exe")) |
| + after, err := p.entry(pid) |
| + if err != nil || after.id != e.id { |
| + return false, paseo.ErrUncertain |
| + } |
| + args := strings.Split(strings.TrimRight(string(raw), "\x00"), "\x00") |
| + vars := strings.Split(string(env), "\x00") |
| + if exeErr == nil && argsErr == nil { |
| + isSystemd := exe == "/usr/lib/systemd/systemd" || exe == "/lib/systemd/systemd" |
| + if isSystemd && len(args) == 2 && args[1] == "--user" { |
| + allowed[pid], systemd[pid] = true, true |
| + } |
| + if isSystemd && len(args) == 1 && args[0] == "(sd-pam)" { |
| + pam[pid] = true |
| + } |
| + if exe == node && envErr == nil && slices.Contains(vars, "PASEO_HOME="+home) && dedicatedDaemon(args, node, home) { |
| + allowed[pid], trees[pid] = true, true |
| + } |
| + } |
| + for _, record := range p.records { |
| + if record.Closed || record.TrackBoot != p.boot || record.TrackTicks == 0 || e.id.StartTicks < record.TrackTicks { |
| + continue |
| + } |
| + if slices.Contains(record.Known, e.id) || (envErr == nil && record.Owner.Marker != "" && slices.Contains(vars, "EQUIPO_ATTEMPT_MARKER="+record.Owner.Marker)) { |
| + allowed[pid], trees[pid] = true, true |
| + } |
| + } |
| + } |
| + for pid := range pam { |
| + if systemd[all[pid].parent] { |
| + allowed[pid] = true |
| + } |
| + } |
| + for changed := true; changed; { |
| + changed = false |
| + for pid, e := range all { |
| + parent, ok := all[e.parent] |
| + if !allowed[pid] && ok && trees[e.parent] && parent.id.StartTicks <= e.id.StartTicks { |
| + allowed[pid], trees[pid], changed = true, true, true |
| + } |
| + } |
| + } |
| + if !allowed[runner.PID] { |
| + return false, paseo.ErrCapability |
| + } |
| + for pid, e := range all { |
| + if !allowed[pid] { |
| + return false, paseo.ErrCapability |
| + } |
| + after, err := p.entry(pid) |
| + if err != nil || after.id != e.id { |
| + return false, paseo.ErrUncertain |
| + } |
| + } |
| + return true, nil |
| +} |
| + |
| +func dedicatedDaemon(args []string, node, home string) bool { |
| + // The pinned CLI's shebang supplies this Node flag. |
| + if len(args) == 7 && args[1] == "--disable-warning=DEP0040" { |
| + args = append([]string{args[0]}, args[2:]...) |
| + } |
| + if len(args) != 6 || !slices.Equal(args[2:], []string{"daemon", "run", "--home", home}) { |
| + return false |
| + } |
| + expected, err := filepath.EvalSymlinks(filepath.Join(filepath.Dir(node), "paseo")) |
| + script, scriptErr := filepath.EvalSymlinks(args[1]) |
| + return err == nil && scriptErr == nil && expected == script |
| +} |
diff --git a/internal/runner/dedicated_user_test.go b/internal/runner/dedicated_user_test.go| new file mode 100644 |
| index 00000000..91551177 |
| --- /dev/null |
| +++ b/internal/runner/dedicated_user_test.go |
| @@ -0,0 +1,127 @@ |
| +package runner |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "os" |
| + "path/filepath" |
| + "strconv" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestTrialDedicatedIdentity(t *testing.T) { |
| + home := t.TempDir() |
| + daemon := filepath.Join(home, ".paseo") |
| + if err := os.Mkdir(daemon, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, mode := range []string{"dedicated", "shell", "password", "empty", "outside", "alias", "symlink"} { |
| + t.Run(mode, func(t *testing.T) { |
| + shell, password, path := "/usr/sbin/nologin", "L", daemon |
| + if mode == "shell" { |
| + shell = "/bin/bash" |
| + } |
| + if mode == "password" { |
| + password = "P" |
| + } |
| + if mode == "empty" { |
| + password = "NP" |
| + } |
| + if mode == "outside" { |
| + path = t.TempDir() |
| + } |
| + if mode == "symlink" { |
| + path = filepath.Join(home, "alias") |
| + if err := os.Symlink(t.TempDir(), path); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + passwd := fmt.Sprintf("runner:x:%d:1::%s:%s\n", os.Getuid(), home, shell) |
| + if mode == "alias" { |
| + passwd += fmt.Sprintf("human:x:%d:1::%s:/bin/bash\n", os.Getuid(), home) |
| + } |
| + err := dedicatedIdentity([]byte(passwd), os.Getuid(), path, func(string) ([]byte, error) { return []byte("runner " + password + " date 0 1 7 -1"), nil }) |
| + if (err == nil) != (mode == "dedicated") { |
| + t.Fatalf("%s: %v", mode, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestTrialDedicatedProcessInventory(t *testing.T) { |
| + for _, mode := range []string{"runner", "shared", "daemon", "foreign-daemon", "unrelated-node", "systemd", "systemd-child", "tracked", "closed", "old-boot", "unreadable"} { |
| + t.Run(mode, func(t *testing.T) { |
| + root := t.TempDir() |
| + install := t.TempDir() |
| + node := filepath.Join(install, "node") |
| + cli := filepath.Join(install, "paseo") |
| + for _, path := range []string{node, cli} { |
| + if err := os.WriteFile(path, []byte("fixture"), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + p := &LinuxProcessInspector{root: root, boot: "boot", records: map[string]*processRecord{}} |
| + write := func(pid, parent int, exe string, args, env []string) { |
| + dir := filepath.Join(root, strconv.Itoa(pid)) |
| + if err := os.Mkdir(dir, 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + fields := []string{strconv.Itoa(pid), "(fixture)", "S", strconv.Itoa(parent)} |
| + for len(fields) < 21 { |
| + fields = append(fields, "0") |
| + } |
| + fields = append(fields, "100") |
| + for name, data := range map[string]string{"stat": strings.Join(fields, " "), "cmdline": strings.Join(args, "\x00") + "\x00", "environ": strings.Join(env, "\x00") + "\x00"} { |
| + if err := os.WriteFile(filepath.Join(dir, name), []byte(data), 0600); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := os.Symlink(exe, filepath.Join(dir, "exe")); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + runnerPID := 10 |
| + write(runnerPID, 1, "/runner", []string{"/runner"}, nil) |
| + id, err := p.identity(runnerPID) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + switch mode { |
| + case "shared": |
| + write(20, 1, "/bin/bash", []string{"bash"}, nil) |
| + case "daemon", "foreign-daemon", "unrelated-node": |
| + home := "/home/runner/.paseo" |
| + if mode == "foreign-daemon" { |
| + home = "/home/other/.paseo" |
| + } |
| + if mode == "unrelated-node" { |
| + cli = "/unrelated-script" |
| + } |
| + write(20, 1, node, []string{"node", cli, "daemon", "run", "--home", home}, []string{"PASEO_HOME=" + home}) |
| + write(21, 20, "/provider", nil, nil) |
| + case "systemd", "systemd-child": |
| + write(20, 1, "/usr/lib/systemd/systemd", []string{"/usr/lib/systemd/systemd", "--user"}, nil) |
| + if mode == "systemd-child" { |
| + write(21, 20, "/bin/bash", []string{"bash"}, nil) |
| + } |
| + case "tracked", "closed", "old-boot": |
| + write(20, 1, "/provider", nil, []string{"EQUIPO_ATTEMPT_MARKER=attempt"}) |
| + p.records["attempt"] = &processRecord{Owner: ProcessOwner{Marker: "attempt"}, TrackTicks: 50, TrackBoot: "boot", Closed: mode == "closed"} |
| + if mode == "old-boot" { |
| + p.records["attempt"].TrackBoot = "old" |
| + } |
| + case "unreadable": |
| + write(20, 1, "/provider", nil, nil) |
| + if err := os.Remove(filepath.Join(root, "20", "stat")); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + ok, err := p.dedicatedProcesses(context.Background(), "/home/runner/.paseo", node, id) |
| + want := mode == "runner" || mode == "daemon" || mode == "systemd" || mode == "tracked" |
| + if (ok && err == nil) != want { |
| + t.Fatalf("%s: %v %v", mode, ok, err) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/runner/forge/publisher.go b/internal/runner/forge/publisher.go| index b574981c..fdb0c3ce 100644 |
| --- a/internal/runner/forge/publisher.go |
| +++ b/internal/runner/forge/publisher.go |
| @@ -125,7 +125,7 @@ func (p *Publisher) validate(a Authorization, d team.Dispatch) error { |
| return team.ErrEvidence |
| } |
| iso := v.Isolation |
| - if !iso.Valid() || ((iso.RunnerTainted || iso.Status == "unconfined") && !strings.Contains(v.Description, "unconfined")) { |
| + if !iso.Valid() || (iso.Trial != nil && !strings.Contains(v.Description, "supervised trial")) || ((iso.RunnerTainted || iso.Status == "unconfined") && !strings.Contains(v.Description, "unconfined")) { |
| return team.ErrEvidence |
| } |
| return nil |
diff --git a/internal/runner/forge/publisher_test.go b/internal/runner/forge/publisher_test.go| index f79356ee..8deb7729 100644 |
| --- a/internal/runner/forge/publisher_test.go |
| +++ b/internal/runner/forge/publisher_test.go |
| @@ -543,3 +543,20 @@ func marshalPublication(t *testing.T, p team.Publication) []byte { |
| must(t, err) |
| return b |
| } |
| + |
| +func TestTrialPublisherRequiresBothLabels(t *testing.T) { |
| + f := newFixture(t) |
| + f.auth.Publication.Isolation.Status = "unconfined" |
| + f.auth.Publication.Isolation.Trial = &team.TrialSnapshot{Label: "supervised trial", AcknowledgementIDs: []string{"trial"}, UnverifiedChecks: team.TrialChecks(), ProviderVersionSource: "observed_locally"} |
| + for _, label := range []string{"unconfined", "supervised trial", "supervised trial unconfined"} { |
| + f.auth.Publication.Description = label |
| + f.auth.Publication.DescriptionHash = Digest([]byte(label)) |
| + raw, _ := json.Marshal(f.auth.Publication) |
| + raw, hash, _ := Canonical(raw) |
| + f.auth.Ticket.Dispatch.Payload, f.auth.Ticket.Dispatch.Hash = raw, hash |
| + err := f.p.validate(f.auth, f.auth.Ticket.Dispatch) |
| + if (err == nil) != (label == "supervised trial unconfined") { |
| + t.Fatalf("%s: %v", label, err) |
| + } |
| + } |
| +} |
diff --git a/internal/runner/paseo/client.go b/internal/runner/paseo/client.go| index 69a4a205..ac25db2a 100644 |
| --- a/internal/runner/paseo/client.go |
| +++ b/internal/runner/paseo/client.go |
| @@ -384,6 +384,11 @@ func (c *Client) Preflight(ctx context.Context, s Selection, p ReadPolicy) (Capa |
| }{s, p}, &caps); err != nil { |
| return caps, err |
| } |
| + caps.DedicatedUser = false |
| + if caps.ObservedAccount != "" && caps.ObservedAccount != s.AccountID { |
| + caps.UnavailableReason = "account_mismatch" |
| + return caps, ErrAccountMismatch |
| + } |
| if caps.ServerID != c.cfg.ServerID { |
| return caps, ErrIdentity |
| } |
| @@ -395,16 +400,30 @@ func (c *Client) Preflight(ctx context.Context, s Selection, p ReadPolicy) (Capa |
| inspected = false |
| } |
| } |
| + result, strictErr := c.strictPreflight(ctx, s, p, caps, inspected) |
| + consent := c.cfg.TrialConsent != nil && c.cfg.TrialConsent() |
| + if strictErr == nil && !consent { |
| + return result, nil |
| + } |
| var trial Capabilities |
| if c.cfg.ObserveProviderVersion != nil { |
| version, e := c.cfg.ObserveProviderVersion(ctx, s) |
| if e != nil { |
| + caps.ProviderVersion = "" |
| + caps.ProviderVersionSource = "" |
| return caps, e |
| } |
| if caps.ProviderVersion != "" && caps.ProviderVersion != version { |
| + caps.ProviderVersion = version |
| + caps.ProviderVersionSource = "observed_locally" |
| return caps, ErrIdentity |
| } |
| local := caps |
| + local.DedicatedUser = false |
| + if c.cfg.InspectDedicatedUser != nil { |
| + ok, err := c.cfg.InspectDedicatedUser(ctx) |
| + local.DedicatedUser = ok && err == nil |
| + } |
| local.ProviderVersion = version |
| local.ProviderVersionSource = "observed_locally" |
| trial, e = evaluateTrial(s, p, local, inspected) |
| @@ -418,13 +437,14 @@ func (c *Client) Preflight(ctx context.Context, s Selection, p ReadPolicy) (Capa |
| trial.UnavailableReason = "" |
| return trial, nil |
| } |
| + } else { |
| + return trial, e |
| } |
| } |
| - result, err := c.strictPreflight(ctx, s, p, caps, inspected) |
| - if err != nil && trial.TrialReady { |
| + if trial.TrialReady { |
| return trial, ErrCapability |
| } |
| - return result, err |
| + return result, strictErr |
| } |
| func (c *Client) strictPreflight(ctx context.Context, s Selection, p ReadPolicy, caps Capabilities, inspected bool) (Capabilities, error) { |
| if c.cfg.VerifyRouting != nil { |
| @@ -514,6 +534,9 @@ func (c *Client) CreateAgent(ctx context.Context, r AgentRequest) (Agent, error) |
| } |
| return a, err |
| } |
| + if a.AccountID != "" && a.AccountID != r.Selection.AccountID { |
| + return a, ErrAccountMismatch |
| + } |
| if (r.ResourceID != "" && a.AgentID != r.ResourceID) || a.ServerID != c.cfg.ServerID || a.WorkspaceID != r.Workspace.WorkspaceID || a.AgentID == "" || a.ProviderSessionID == "" || (a.AccountID != r.Selection.AccountID && !(caps.TrialReady && a.AccountID == "")) || a.Provider != r.Selection.Provider || a.Model != r.Selection.Model || a.Family != r.Selection.Family { |
| return a, ErrUncertain |
| } |
diff --git a/internal/runner/paseo/client_test.go b/internal/runner/paseo/client_test.go| index ef625e11..9ba1a8ab 100644 |
| --- a/internal/runner/paseo/client_test.go |
| +++ b/internal/runner/paseo/client_test.go |
| @@ -21,7 +21,7 @@ func fixturePolicy() ReadPolicy { |
| return ReadPolicy{DeniedPaths: []string{"/protected"}, ConfigHash: "hash"} |
| } |
| func fixtureCaps() Capabilities { |
| - return Capabilities{Version: "0.14.0", PaseoVersion: "0.14.0", ProviderVersion: "2.1.312", ServerID: "server", AccountPinning: true, ObservedAccount: "account", NoFailover: true, RecoverableTimeline: true, ProcessOwnership: true, MCPAtCreate: true, ReadIsolation: true, IsolationConfigHash: "hash"} |
| + return Capabilities{Version: "0.14.0", PaseoVersion: "0.14.0", ProviderVersion: "2.1.312", ServerID: "server", AccountPinning: true, ObservedAccount: "account", NoFailover: true, RecoverableTimeline: true, ProcessOwnership: true, DedicatedUser: true, MCPAtCreate: true, ReadIsolation: true, IsolationConfigHash: "hash"} |
| } |
| func fixtureWorkspace() Workspace { |
| return Workspace{ServerID: "server", ProjectID: "project", WorkspaceID: "workspace", Path: "/work/fixture"} |
| @@ -31,7 +31,7 @@ func fixtureAgent() Agent { |
| } |
| func testClient(t *testing.T, mode string, change func(*Config)) *Client { |
| t.Helper() |
| - cfg := Config{ServerID: "server", VerifiedTuples: []VerifiedTuple{{Provider: "claude", ProviderVersion: "2.1.312", PaseoVersion: "0.14.0", ConfigHash: "hash"}}, RecordIntent: func(context.Context, Intent) error { return nil }, RecordCreationRefusal: func(context.Context, Intent) error { return nil }, InspectProcesses: func(context.Context, Selection) (bool, error) { return true, nil }} |
| + cfg := Config{InspectDedicatedUser: func(context.Context) (bool, error) { return true, nil }, ServerID: "server", VerifiedTuples: []VerifiedTuple{{Provider: "claude", ProviderVersion: "2.1.312", PaseoVersion: "0.14.0", ConfigHash: "hash"}}, RecordIntent: func(context.Context, Intent) error { return nil }, RecordCreationRefusal: func(context.Context, Intent) error { return nil }, InspectProcesses: func(context.Context, Selection) (bool, error) { return true, nil }} |
| if change != nil { |
| change(&cfg) |
| } |
diff --git a/internal/runner/paseo/trial.go b/internal/runner/paseo/trial.go| index 41adf896..fa7e8f42 100644 |
| --- a/internal/runner/paseo/trial.go |
| +++ b/internal/runner/paseo/trial.go |
| @@ -15,11 +15,15 @@ func evaluateTrial(s Selection, p ReadPolicy, c Capabilities, inspected bool) (C |
| return deny("unsupported_provider_version", ErrCapability) |
| } |
| if c.ObservedAccount != "" && c.ObservedAccount != s.AccountID { |
| - return deny("account_mismatch", ErrIdentity) |
| + return deny("account_mismatch", ErrAccountMismatch) |
| } |
| if c.ObservedFamily != "" && c.ObservedFamily != s.Family { |
| return deny("family_changed", ErrIdentity) |
| } |
| + if !c.DedicatedUser { |
| + c.ProcessOwnership = false |
| + return deny("dedicated_user_required", ErrCapability) |
| + } |
| if !inspected { |
| return deny("process_coverage_unverified", ErrCapability) |
| } |
diff --git a/internal/runner/paseo/trial_round2_test.go b/internal/runner/paseo/trial_round2_test.go| new file mode 100644 |
| index 00000000..5caeff45 |
| --- /dev/null |
| +++ b/internal/runner/paseo/trial_round2_test.go |
| @@ -0,0 +1,72 @@ |
| +package paseo |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "testing" |
| +) |
| + |
| +func TestTrialStrictPreflightSkipsLocalVersion(t *testing.T) { |
| + c := testClient(t, "normal", func(cfg *Config) { |
| + cfg.ObserveProviderVersion = func(context.Context, Selection) (string, error) { |
| + t.Error("strict preflight ran provider CLI") |
| + return "", ErrCapability |
| + } |
| + }) |
| + if _, err := c.Preflight(context.Background(), fixtureSelection(), fixturePolicy()); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func TestTrialAccountMismatchTyped(t *testing.T) { |
| + c := testClient(t, "trial-mismatch", func(cfg *Config) { |
| + cfg.ObserveProviderVersion = func(context.Context, Selection) (string, error) { return "2.1.312", nil } |
| + cfg.AuthorizeTrial = func(context.Context, Selection, Capabilities) error { return nil } |
| + }) |
| + _, err := c.CreateAgent(context.Background(), AgentRequest{Workspace: fixtureWorkspace(), Selection: fixtureSelection(), IdempotencyKey: "trial", ModeID: "default", ReadPolicy: fixturePolicy()}) |
| + if err == nil || err.Error() != "account_mismatch" { |
| + t.Fatalf("mismatch loses terminal reason: %v", err) |
| + } |
| + if errors.Is(err, ErrUncertain) { |
| + t.Fatal("mismatch is retryable uncertainty") |
| + } |
| +} |
| + |
| +func TestTrialSharedUIDRefused(t *testing.T) { |
| + c := testClient(t, "trial", func(cfg *Config) { |
| + cfg.ObserveProviderVersion = func(context.Context, Selection) (string, error) { return "2.1.312", nil } |
| + cfg.InspectDedicatedUser = func(context.Context) (bool, error) { return false, nil } |
| + cfg.AuthorizeTrial = func(context.Context, Selection, Capabilities) error { |
| + t.Fatal("shared UID reached consent") |
| + return nil |
| + } |
| + }) |
| + caps, err := c.Preflight(context.Background(), fixtureSelection(), fixturePolicy()) |
| + if err == nil || caps.TrialReady || caps.DedicatedUser || caps.ProcessOwnership || caps.UnavailableReason != "dedicated_user_required" { |
| + t.Fatalf("shared UID accepted: %+v %v", caps, err) |
| + } |
| +} |
| + |
| +func TestTrialVersionFailureClearsObservation(t *testing.T) { |
| + c := testClient(t, "normal", func(cfg *Config) { |
| + cfg.TrialConsent = func() bool { return true } |
| + cfg.ObserveProviderVersion = func(context.Context, Selection) (string, error) { return "", ErrCapability } |
| + }) |
| + caps, err := c.Preflight(context.Background(), fixtureSelection(), fixturePolicy()) |
| + if err == nil || caps.ProviderVersion != "" || caps.ProviderVersionSource != "" || caps.TrialReady { |
| + t.Fatalf("failed read retained version: %+v %v", caps, err) |
| + } |
| +} |
| + |
| +func TestTrialConsentForcesLocalVersion(t *testing.T) { |
| + calls := 0 |
| + c := testClient(t, "normal", func(cfg *Config) { |
| + cfg.TrialConsent = func() bool { return true } |
| + cfg.ObserveProviderVersion = func(context.Context, Selection) (string, error) { calls++; return "2.1.312", nil } |
| + cfg.AuthorizeTrial = func(context.Context, Selection, Capabilities) error { return nil } |
| + }) |
| + caps, err := c.Preflight(context.Background(), fixtureSelection(), fixturePolicy()) |
| + if err != nil || calls != 1 || !caps.TrialReady || caps.ReadIsolation { |
| + t.Fatalf("consent bypassed trial checks: %+v %v calls=%d", caps, err, calls) |
| + } |
| +} |
diff --git a/internal/runner/paseo/types.go b/internal/runner/paseo/types.go| index aa86c66f..17dcad99 100644 |
| --- a/internal/runner/paseo/types.go |
| +++ b/internal/runner/paseo/types.go |
| @@ -16,16 +16,17 @@ type Error string |
| func (e Error) Error() string { return string(e) } |
| const ( |
| - ErrContract Error = "paseo_contract" |
| - ErrClosed Error = "paseo_closed" |
| - ErrUncertain Error = "paseo_uncertain" |
| - ErrNotReady Error = "subscription_not_ready" |
| - ErrCapability Error = "unsupported_capability" |
| - ErrIsolation Error = "read_isolation_required" |
| - ErrCreationAbsent Error = "creation_absent" |
| - ErrCreateRefused Error = "create_refused" |
| - ErrPolicy Error = "policy_mismatch" |
| - ErrIdentity Error = "identity_mismatch" |
| + ErrContract Error = "paseo_contract" |
| + ErrClosed Error = "paseo_closed" |
| + ErrUncertain Error = "paseo_uncertain" |
| + ErrNotReady Error = "subscription_not_ready" |
| + ErrCapability Error = "unsupported_capability" |
| + ErrIsolation Error = "read_isolation_required" |
| + ErrCreationAbsent Error = "creation_absent" |
| + ErrCreateRefused Error = "create_refused" |
| + ErrPolicy Error = "policy_mismatch" |
| + ErrAccountMismatch Error = "account_mismatch" |
| + ErrIdentity Error = "identity_mismatch" |
| ) |
| type Selection struct { |
| @@ -46,6 +47,7 @@ type VerifiedTuple struct { |
| ConfigHash string |
| } |
| type Capabilities struct { |
| + DedicatedUser bool `json:"dedicated_user"` |
| TrialReady bool `json:"trial_ready,omitempty"` |
| ProviderVersionSource string `json:"provider_version_source,omitempty"` |
| ObservedFamily string `json:"observed_family,omitempty"` |
| @@ -141,6 +143,8 @@ type Intent struct { |
| type Config struct { |
| CredentialHome func(Selection) (string, error) |
| ObserveProviderVersion func(context.Context, Selection) (string, error) |
| + TrialConsent func() bool |
| + InspectDedicatedUser func(context.Context) (bool, error) |
| AuthorizeTrial func(context.Context, Selection, Capabilities) error |
| VerifyRouting func(context.Context, Selection, Capabilities) error |
| NodePath string |
diff --git a/internal/runner/runtime.go b/internal/runner/runtime.go| index d5c9dcbc..0e537765 100644 |
| --- a/internal/runner/runtime.go |
| +++ b/internal/runner/runtime.go |
| @@ -84,7 +84,7 @@ func openRuntime(ctx context.Context, c Config) (r *Runtime, err error) { |
| tuples = append(tuples, paseo.VerifiedTuple{Provider: v.Provider, ProviderVersion: v.ProviderVersion, PaseoVersion: v.PaseoVersion, ConfigHash: v.IsolationConfigHash}) |
| } |
| variable = "EQUIPO_BRIDGE_PATH" |
| - r.client, err = paseo.Start(ctx, paseo.Config{CredentialHome: func(s paseo.Selection) (string, error) { b, _, err := r.binding(s); return b.CredentialHome, err }, ObserveProviderVersion: r.providerVersion, AuthorizeTrial: r.authorizeTrial, VerifyRouting: r.verifyRouting, VerifiedTuples: tuples, NodePath: c.NodePath, BridgePath: c.BridgePath, DaemonHome: c.PaseoHome, Endpoint: c.PaseoEndpoint, ServerID: c.PaseoServerID, RecordIntent: r.journal.RecordIntent, RecordCreationRefusal: r.journal.RecordCreationRefusal, InspectProcesses: r.coverage, AuthorizeUnconfined: r.authorizeUnconfined}) |
| + r.client, err = paseo.Start(ctx, paseo.Config{CredentialHome: func(s paseo.Selection) (string, error) { b, _, err := r.binding(s); return b.CredentialHome, err }, ObserveProviderVersion: r.providerVersion, TrialConsent: r.trialConsent, InspectDedicatedUser: r.dedicatedUser, AuthorizeTrial: r.authorizeTrial, VerifyRouting: r.verifyRouting, VerifiedTuples: tuples, NodePath: c.NodePath, BridgePath: c.BridgePath, DaemonHome: c.PaseoHome, Endpoint: c.PaseoEndpoint, ServerID: c.PaseoServerID, RecordIntent: r.journal.RecordIntent, RecordCreationRefusal: r.journal.RecordCreationRefusal, InspectProcesses: r.coverage, AuthorizeUnconfined: r.authorizeUnconfined}) |
| if err != nil { |
| return r, err |
| } |
diff --git a/internal/runner/trial.go b/internal/runner/trial.go| index ae1fe6a8..2adc8f5b 100644 |
| --- a/internal/runner/trial.go |
| +++ b/internal/runner/trial.go |
| @@ -1,7 +1,9 @@ |
| package runner |
| import ( |
| + "bytes" |
| "context" |
| + "io" |
| "os" |
| "os/exec" |
| "path/filepath" |
| @@ -26,6 +28,7 @@ func (r *Runtime) providerVersion(ctx context.Context, s paseo.Selection) (strin |
| defer cancel() |
| // Inherit the runner user's login environment, never an agent's workspace. |
| cmd := exec.CommandContext(ctx, path, "--version") |
| + cmd.WaitDelay = time.Second |
| cmd.Dir = filepath.Dir(path) |
| r.mu.Lock() |
| claim := r.current |
| @@ -37,11 +40,14 @@ func (r *Runtime) providerVersion(ctx context.Context, s paseo.Selection) (strin |
| } |
| cmd.Env = append(os.Environ(), "EQUIPO_ATTEMPT_MARKER="+marker) |
| } |
| - out, err := cmd.Output() |
| - if err != nil || len(out) > 256 { |
| + out := limitedOutput{limit: 256} |
| + cmd.Stdout = &out |
| + cmd.Stderr = io.Discard |
| + err := cmd.Run() |
| + if err != nil || out.overflow { |
| return "", paseo.ErrCapability |
| } |
| - fields := strings.Fields(string(out)) |
| + fields := strings.Fields(out.String()) |
| if len(fields) == 0 { |
| return "", paseo.ErrCapability |
| } |
| @@ -64,7 +70,7 @@ func (r *Runtime) authorizeTrial(ctx context.Context, s paseo.Selection, caps pa |
| return paseo.ErrCapability |
| } |
| iso := claim.Assignment.Selection.Isolation |
| - if iso.Trial == nil || !iso.Valid() { |
| + if iso.Trial == nil || !iso.Valid() || (s.Provider == "codex" && len(iso.AcknowledgementIDs) == 0) { |
| return paseo.ErrCapability |
| } |
| matched := false |
| @@ -80,8 +86,35 @@ func (r *Runtime) authorizeTrial(ctx context.Context, s paseo.Selection, caps pa |
| if err := r.api.Call(ctx, "validate", runnerproto.RunnerRequest{Version: 1, AssignmentID: claim.Assignment.ID, Scope: claim.Scope, Handle: claim.Handle, RequestID: "trial-preflight"}, ¤t); err != nil { |
| return err |
| } |
| - if current.Isolation.Trial == nil { |
| + if current.Isolation.Trial == nil || !current.Isolation.Valid() || (s.Provider == "codex" && len(current.Isolation.AcknowledgementIDs) == 0) { |
| return paseo.ErrCapability |
| } |
| return nil |
| } |
| + |
| +// Keep draining output without retaining more than the limit. |
| +type limitedOutput struct { |
| + buf bytes.Buffer |
| + limit int |
| + overflow bool |
| +} |
| + |
| +func (b *limitedOutput) Len() int { return b.buf.Len() } |
| +func (b *limitedOutput) String() string { return b.buf.String() } |
| +func (b *limitedOutput) Bytes() []byte { return b.buf.Bytes() } |
| + |
| +func (b *limitedOutput) Write(p []byte) (int, error) { |
| + n := len(p) |
| + remaining := b.limit - b.Len() |
| + if n > remaining { |
| + b.overflow = true |
| + p = p[:remaining] |
| + } |
| + _, _ = b.buf.Write(p) |
| + return n, nil |
| +} |
| +func (r *Runtime) trialConsent() bool { |
| + r.mu.Lock() |
| + defer r.mu.Unlock() |
| + return r.current != nil && r.current.Assignment.Selection.Isolation.Trial != nil |
| +} |
diff --git a/internal/runner/trial_reconnect.go b/internal/runner/trial_reconnect.go| index 6e23bb38..71a13ea8 100644 |
| --- a/internal/runner/trial_reconnect.go |
| +++ b/internal/runner/trial_reconnect.go |
| @@ -27,8 +27,8 @@ func (s *Supervisor) trialTurnError(ctx context.Context, r *attemptState, err er |
| report, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second) |
| defer cancel() |
| lost := s.trialLost(report, r) |
| - if errors.Is(err, paseo.ErrUncertain) || errors.Is(err, paseo.ErrClosed) || errors.Is(err, paseo.ErrNotReady) || errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { |
| - return errors.Join(errTrialReconnect, err, lost) |
| + if errors.Is(err, paseo.ErrAccountMismatch) { |
| + return errors.Join(err, lost) |
| } |
| - return errors.Join(err, lost) |
| + return errors.Join(errTrialReconnect, err, lost) |
| } |
diff --git a/internal/runner/trial_test.go b/internal/runner/trial_test.go| index ffee596f..7f7d236e 100644 |
| --- a/internal/runner/trial_test.go |
| +++ b/internal/runner/trial_test.go |
| @@ -1,12 +1,17 @@ |
| package runner |
| import ( |
| + "amadan.net/oficina/equipo/internal/runnerproto" |
| "context" |
| "errors" |
| + "io" |
| + "net/http" |
| "os" |
| "path/filepath" |
| "slices" |
| + "strings" |
| "testing" |
| + "time" |
| "amadan.net/oficina/equipo/internal/equipo/team" |
| "amadan.net/oficina/equipo/internal/runner/paseo" |
| @@ -52,3 +57,80 @@ func TestTrialProviderVersionObservedLocally(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +func TestTrialOtherTurnErrorWaits(t *testing.T) { |
| + s, r, _, order := cleanupFixture(t) |
| + r.Claim.Assignment.Selection.Isolation.Trial = &team.TrialSnapshot{Label: "supervised trial"} |
| + r.InFlightAction = 1 |
| + err := s.trialTurnError(context.Background(), r, paseo.ErrContract) |
| + if !errors.Is(err, errTrialReconnect) { |
| + t.Fatalf("non-reconnect error fails job: %v", err) |
| + } |
| + _ = s.finishAttempt(context.Background(), r, err) |
| + if slices.Contains(*order, "complete") || slices.Contains(*order, "release") { |
| + t.Fatal(*order) |
| + } |
| +} |
| + |
| +func TestTrialVersionOutputBounded(t *testing.T) { |
| + out := limitedOutput{limit: 256} |
| + raw := []byte(strings.Repeat("x", 4096)) |
| + for range 100 { |
| + n, err := out.Write(raw) |
| + if err != nil || n != len(raw) { |
| + t.Fatal(n, err) |
| + } |
| + } |
| + if out.Len() != 256 || !out.overflow { |
| + t.Fatal("unbounded output", out.Len()) |
| + } |
| + path := filepath.Join(t.TempDir(), "version") |
| + if err := os.WriteFile(path, []byte("#!/bin/sh\nprintf '%0300d' 0\n"), 0700); err != nil { |
| + t.Fatal(err) |
| + } |
| + r := Runtime{cfg: Config{CodexPath: path}} |
| + if _, err := r.providerVersion(context.Background(), paseo.Selection{Provider: "codex"}); err == nil { |
| + t.Fatal("oversized version accepted") |
| + } |
| +} |
| + |
| +func TestTrialRuntimeCodexAcknowledgement(t *testing.T) { |
| + iso := team.IsolationSnapshot{Status: "unconfined", RunnerTainted: true, Trial: &team.TrialSnapshot{Label: "supervised trial", AcknowledgementIDs: []string{"trial"}, UnverifiedChecks: team.TrialChecks(), ProviderVersionSource: "observed_locally"}, ObservedTuples: []team.IsolationTuple{{Provider: "codex", ProviderVersion: "0.165.0", PaseoVersion: "0.14.0", IsolationConfigHash: strings.Repeat("a", 64)}}} |
| + r := Runtime{current: &RunClaim{Assignment: runnerproto.Assignment{Selection: runnerproto.Selection{Provider: "codex", Isolation: iso}}}} |
| + s := selection(r.current.Assignment) |
| + caps := paseo.Capabilities{ProviderVersion: "0.165.0", PaseoVersion: "0.14.0", IsolationConfigHash: strings.Repeat("a", 64)} |
| + calls := 0 |
| + current := r.current.Assignment.Selection |
| + current.Isolation.AcknowledgementIDs = []string{"codex-ack"} |
| + r.api = &HTTPInstance{origin: "https://instance.invalid", bearer: runnerproto.RunnerCredential{Token: "fixture", ExpiresAt: time.Now().Add(time.Hour)}, client: &http.Client{Transport: transportFunc(func(*http.Request) (*http.Response, error) { |
| + calls++ |
| + raw, _ := runnerproto.Marshal(map[string]any{"version": 1, "result": current}) |
| + return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(string(raw)))}, nil |
| + })}} |
| + if err := r.authorizeTrial(context.Background(), s, caps); !errors.Is(err, paseo.ErrCapability) || calls != 0 { |
| + t.Fatal("missing local acknowledgement accepted", err, calls) |
| + } |
| + r.current.Assignment.Selection.Isolation.AcknowledgementIDs = []string{"codex-ack"} |
| + current.Isolation.AcknowledgementIDs = nil |
| + if err := r.authorizeTrial(context.Background(), s, caps); !errors.Is(err, paseo.ErrCapability) { |
| + t.Fatal("missing current acknowledgement accepted", err) |
| + } |
| + current.Isolation.AcknowledgementIDs = []string{"codex-ack"} |
| + if err := r.authorizeTrial(context.Background(), s, caps); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func TestTrialAccountMismatchRemainsTerminal(t *testing.T) { |
| + s, r, _, order := cleanupFixture(t) |
| + r.Claim.Assignment.Selection.Isolation.Trial = &team.TrialSnapshot{Label: "supervised trial"} |
| + r.InFlightAction = 1 |
| + err := s.trialTurnError(context.Background(), r, paseo.ErrAccountMismatch) |
| + if errors.Is(err, errTrialReconnect) || attemptFailureReason(err) != "account_mismatch" { |
| + t.Fatal("lost terminal mismatch", err) |
| + } |
| + _ = s.finishAttempt(context.Background(), r, err) |
| + if slices.Contains(*order, "release") || !slices.Contains(*order, "complete") || !slices.Contains(*order, "lost") { |
| + t.Fatal(*order) |
| + } |
| +} |
diff --git a/internal/runner/workspace/workspace.go b/internal/runner/workspace/workspace.go| index 6860ec3b..3c42151d 100644 |
| --- a/internal/runner/workspace/workspace.go |
| +++ b/internal/runner/workspace/workspace.go |
| @@ -346,7 +346,7 @@ func (m *Manager) preflight(ctx context.Context, a runnerproto.Assignment) (pase |
| found = true |
| } |
| } |
| - if snap.Trial != nil && snap.Valid() && c.TrialReady && found { |
| + if snap.Trial != nil && snap.Valid() && c.TrialReady && found && (s.Provider != "codex" || len(snap.AcknowledgementIDs) > 0) { |
| return p, nil |
| } |
| if s.Provider != "codex" || c.ProviderVersion != "0.165.0" || c.PaseoVersion != "0.14.0" || snap.Status != "unconfined" || !snap.RunnerTainted || len(snap.AcknowledgementIDs) == 0 || !found { |
diff --git a/internal/runner/workspace/workspace_test.go b/internal/runner/workspace/workspace_test.go| index 00611641..7dce1f47 100644 |
| --- a/internal/runner/workspace/workspace_test.go |
| +++ b/internal/runner/workspace/workspace_test.go |
| @@ -687,3 +687,27 @@ func TestCandidateCaptureSHA256(t *testing.T) { |
| t.Fatal(err) |
| } |
| } |
| + |
| +func TestTrialCodexRequiresSeparateAcknowledgement(t *testing.T) { |
| + f := setup(t) |
| + original := f.m.cfg.Policy |
| + f.m.cfg.Policy = func(ctx context.Context, sel paseo.Selection) (paseo.ReadPolicy, error) { |
| + p, err := original(ctx, sel) |
| + p.ConfigHash = strings.Repeat("a", 64) |
| + return p, err |
| + } |
| + f.f.caps.IsolationConfigHash = strings.Repeat("a", 64) |
| + f.a.Selection.Provider = "codex" |
| + f.a.Selection.Isolation = team.IsolationSnapshot{Status: "unconfined", RunnerTainted: true, Trial: &team.TrialSnapshot{Label: "supervised trial", AcknowledgementIDs: []string{"trial"}, UnverifiedChecks: team.TrialChecks(), ProviderVersionSource: "observed_locally"}, ObservedTuples: []team.IsolationTuple{{Provider: "codex", ProviderVersion: "0.165.0", PaseoVersion: "0.14.0", IsolationConfigHash: strings.Repeat("a", 64)}}} |
| + f.f.caps.ReadIsolation = false |
| + f.f.caps.TrialReady = true |
| + f.f.caps.ProviderVersion = "0.165.0" |
| + f.f.caps.PaseoVersion = "0.14.0" |
| + if _, err := f.m.preflight(context.Background(), f.a); err == nil { |
| + t.Fatal("trial replaced Codex acknowledgement") |
| + } |
| + f.a.Selection.Isolation.AcknowledgementIDs = []string{"codex-ack"} |
| + if _, err := f.m.preflight(context.Background(), f.a); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
diff --git a/internal/runnerproto/types.go b/internal/runnerproto/types.go| index 7095c0fc..9f3a8405 100644 |
| --- a/internal/runnerproto/types.go |
| +++ b/internal/runnerproto/types.go |
| @@ -112,8 +112,8 @@ type Delivery struct { |
| } |
| type ConnectionRouting struct { |
| - BindingID, AccountID, ObservedAccountID, CredentialHomeHash string |
| - AccountPinned, NoFailover, TimelineRecovery, ProcessOwnership bool |
| + BindingID, AccountID, ObservedAccountID, CredentialHomeHash string |
| + AccountPinned, NoFailover, TimelineRecovery, ProcessOwnership, DedicatedUser bool |
| } |
| type ConnectionReport struct { |