equipo: hosted results count only from fresh certified admissions
Task 24 (Fable M8). A hosted worker's checks keep bubblewrap, and its base checks are read, only when hostedCertified holds. It needs the runner bound to an enrolled job for exactly this step and attempt, and the job's latest admission record kept whole, valid, running and checked within AdmissionFresh (2 min) of the report. The record must name the launch, VM, epoch, certificate and image recorded at enrolment (0129: image_digest, admission_json). A hello is never read. An uncertified hosted result is not kept and its runner is not tainted. The job stops (uncertified), and Task 21's path places the step again once. acceptBaseChecks takes a worker only when certified. The task view presents deps_new_module and deps_missing as needs_network. The dispatcher simulation now enrols through the store's enrolment steps. Its reports go through Store.Apply and stepReport, and it checks that no step is certified by a stale or invalid admission.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
15 files changed,
+705
−35
.rastrillo/budgets.txt+1 −1docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md+53 −0internal/equipo/chat/hosted_enrol.go+11 −1internal/equipo/chat/hosted_jobs.go+10 −1internal/equipo/chat/hosted_results.go+83 −0internal/equipo/chat/hosted_results_test.go+313 −0internal/equipo/chat/hosted_run.go+9 −4internal/equipo/chat/injection_merge_test.go+12 −2internal/equipo/chat/mergeauth.go+5 −3internal/equipo/chat/runners.go+3 −1internal/equipo/chat/tasks.go+34 −8internal/equipo/hostedrun/dispatcher_test.go+5 −1internal/equipo/hostedrun/sim_test.go+153 −13internal/equipo/migrations/0129_hosted_job_admission.sql+6 −0internal/equipo/migrations/schema.sql+7 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 472cbb6e..194eb7d2 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -60,7 +60,7 @@ perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| perf GET /api/v1/assistant/abilities skip Assistant person API: bearer-only JSON for Base's Settings line, not a browser screen. |
| -size internal/equipo/chat 46957 21199 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. |
| +size internal/equipo/chat 47094 21522 File facts/diffs, previews, merges, unfinished work, CI, receipts, Assistant files, places, abilities, lookups, go-aheads, Mac work, D1, Design specialists, grants, captures; 45093/18782. Hosted slice 2 Task 15: openHostedPack (the instance's send_pack for a hosted pack) and its test; 45105/18883. Its review round 1 added the report-ingestion test for pack_incomplete; 45105/18911. Task 18: hosted_setting.go (SetHostedChecks, hostedChecks, HostedSettings; owner only, roster in the transaction, audited) and its tests; 45208/19070. Its review round 1: the audit atomicity test; 45208/19113. Task 19: hosted_jobs.go (the hosted_jobs and hosted_challenges tables, HostedJob and its lifecycle: newHostedJob, the listed moves only, ended and failed only with stop proof or never-launched evidence, settleHostedJob once, hostedJobForRunner; each move audited in its transaction) and its tests, TestMigrationAdditive included; 45658/19577. Its review round 1: the never-launched evidence contract (HostedNeverLaunched, launch_by and launching_since, hostedLaunchReturned) and tests for it, settlement of unproven terminal records and audit atomicity; 45728/19739. Task 20: hosted_limits.go (per-person hosted limits, S2-9: hostedAdmit held in the write by a per-person lock row, hostedHoldFor, Allocate, hostedSettle at 4x the baseline, SetHostedLimits owner only with the roster, revision and audit in the transaction) and its tests; 46013/20214. Its coordinator ruling: a limit counts only while its setting owner is a current owner (defaults otherwise, checked in the admission transaction) and TestOwnerRaisesLimitRevoked; 46022/20284. Its review round 1: Allocate returns nothing for an empty or reversed span before widening, and its assertions; 46025/20290. Hosted slice 2 Task 21: placement on hosted VMs (placeHosted before the checks early return, its five rules), the bound runner's fits, Authorize by job identity, the hosted offline rule and withdrawal exemption, the hosted pack at dispatch, the step-terminal hook, and the dispatcher's store methods (HostedLive, HostedSweep, HostedLaunching with relaunch, HostedLaunched, HostedAdmitted, HostedFailed, HostedStopped, HostedNeverLaunched, HostedReplaces, PlaceHosted; end, settle, revoke, step moved on) in hosted_run.go, and hosted_place_test.go; 46665/20804. Task 21 review round 1: abandoned-intent evidence waits for the job's lifetime, the job keeps its lifetime and first running sight, admission takes the placing transaction's step attempt, provider-valid attempt IDs, HostedRunning, and the Retry, replacement-runner, cancelled-task and stopping-VM tests; 46709/20937. Its review round 2: TestHostedReplacesNeedsProof; 46709/20971. Task 22: hosted_enrol.go (the enrolment and renewal store steps inside the instance's write transaction: HostedClaimCode, HostedEnrolAdmit, HostedEnrolBind, HostedRunnerJob, HostedNewChallenge, HostedUseChallenge; hostedAdmitted shared with HostedAdmitted); its tests drive it through the instance's routes (internal/equipo); 46848/20971. Its review round 1: hostedAdmitted reports whether the record was kept, the enrolment records the first sighting and applies the window from it, and the launch view's deadline is kept (hosted_jobs.deadline, earliest wins); 46903/20971. Its review round 2: an admission record's current deadline is kept too (hostedAdmitted, for the dispatcher's refresh and the renewal's HostedRenewAdmit); 46932/20971. Round 3: HostedEnrolAdmit returns the job re-read after recording the admission, so the enrolment caps by its deadline; 46937/20971. Task 23: openHostedPack opens the deps bundle after the hosted pack (send_pack with Deps), the instance's chunk and byte checks per kind (wire.MaxChunks, wire.MaxBytes), deps_too_large for a bundle past its limit, and a hosted attempt's pack and bundle closed when its checks end; hosted_deps_test.go; 46957/21199. Task 24: hosted_results.go (hostedCertified, AdmissionFresh: a hosted worker's checks count as sandboxed and its base checks as trusted only through the job's fresh, valid admission record, never its hello; an uncertified hosted result is not kept, its job stops and the step goes again once; deps_new_module and deps_missing presented as needs_network), stepReport and acceptBaseChecks wired to it, the admission kept whole and the enrolment image (0129), and hosted_results_test.go; 47094/21522. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
diff --git a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md| index 54278a39..df34f14f 100644 |
| --- a/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| +++ b/docs/superpowers/plans/HOSTED-SLICE2-PROGRESS.md |
| @@ -1841,3 +1841,56 @@ Green: |
| - The brief's command (thin 11.7 s, chat 0.4 s). |
| - `make migration-check budget build vet`: exit 0. The thin record is raised by one line for the comment, to 36174. |
| - staticcheck v0.7.0 on linuxworker: clean. `git diff --check`: clean. |
| + |
| +## Task 24 |
| + |
| +Certified results from hosted workers (Fable M8). |
| + |
| +- **`hostedCertified(runnerID, stepID, stepAttempt, now)`** (new `internal/equipo/chat/hosted_results.go`, `AdmissionFresh = 2 * time.Minute`). It is true only when all of these hold, every value read in the report's transaction: |
| + - the runner is bound to a job (`hostedJobForRunner`) that is `enrolled`, for exactly this step and step attempt; |
| + - the job's latest admission record has `cert_valid` set, and its `cert_checked_at` is within `AdmissionFresh` of the report's arrival (`t.now()`), either side; |
| + - the record itself, kept whole in the new `admission_json`, says `CertValid`, state `running`, and names this attempt, the job's launch, VM and epoch, the job's certificate digest (pinned by the first record), and the image recorded at enrolment (new `image_digest`). |
| + A lookup error is false and is returned, so the report's transaction rolls back and the durable report is retried. Bad JSON is false. |
| +- **Store:** migration `0129_hosted_job_admission.sql` adds `image_digest` and `admission_json` to `hosted_jobs`; `schema.sql` is appended. The image digest was not recorded before this task. `HostedEnrolAdmit` records the admitting record's image, once. `hostedAdmitted` writes the record as `admission_json` along with `cert_*`. A record naming a different image from the enrolment's is no longer valid, so it refuses renewals too. |
| +- **`stepReport`** (judgement branch): for a worker's checks, `certified := hostedCertified(...)`. A runner bound to a hosted job that is not certified keeps nothing: no result, no sandbox, no base checks, no taint. Its job moves to `stopping` with reason `uncertified` (`hostedUncertified`). Once the VM's stop proof arrives, Task 21's path (`hostedFinish`, then `hostedStepAgain`, then `placeHosted` rule 2) places the step again once under the same attempt. A second failure ends it `cannot_run` `hosted_unavailable` (`hostedFailure` maps the unknown stop reason). A certified result keeps `bubblewrap` only when it reported `bubblewrap` and the runner is untainted. The primary-only `BaseChecks` branch also reads a certified worker's `BaseChecks`. Any other worker follows the old rules: seatbelt only, otherwise `none` and tainted. |
| +- **`acceptBaseChecks(l, role, certified, s, v)`** accepts the primary, or a worker only when `certified`. |
| +- **`cleanHello`**: its comment now says a hello is diagnostic only. No decision reads the hello. |
| +- **Presentation:** `taskView` shows `deps_new_module` and `deps_missing` as `checks_reason` `needs_network` (`presentedChecksReason`). That is the state the existing badge, decision, headline and roster keys read. The step keeps its own reason for Task 25's words. The merge gate gets the step's own reason, and the outcome is the same, since neither reason counts as environment. |
| +- **Simulation (Task 21's `TestDispatcherSimulation`):** VMs now enrol through the store's enrolment steps: `HostedClaimCode`, then the fake controller's `Admission`, then `HostedEnrolAdmit` (which must admit), then `HostedEnrolBind`. A step on a VM reports through `Store.Apply` (the production `stepReport`) with checks passed in `bubblewrap` and base checks passed. Each VM's checks take 0 to 4 minutes, so some reports arrive during controller outages or after a withdrawal. After every report: |
| + - Invariant: a certified result (`bubblewrap` or a `BaseChecksSHA`) requires that the job's latest record, read just before the report, was valid and asked for within `AdmissionFresh`, at a time the controller held the certificate valid, for the VM, launch and image the controller launched. |
| + - An uncertified report keeps nothing, taints no runner, and stops its job. |
| + - Across the 200 seeds, certified, stale-refused and withdrawn-refused reports must each occur. This run: 157 certified and 47 refused (10 on a stale admission, 37 on a withdrawn one). |
| + - The rig's `stepRow` gains `task_id`, `checks_sandbox` and `base_checks_sha`. |
| + |
| +Red: |
| +1. With only the test file: `CGO_ENABLED=0 go test ./internal/equipo/chat -run 'TestHelloCannotCertify|TestHostedCertified|TestStaleAdmission|TestCertWithdrawn|TestWrongStepAttempt|TestMacRules' -count=1` failed to build (`undefined: hostedStopUncertified`, `undefined: AdmissionFresh`, `j.AdmissionJSON undefined`). |
| +2. With stubs only (the two fields and the migration, the constants, `hostedCertified` returning false), the same command failed on its assertions: |
| + - `hosted_results_test.go:166: certified result: done sandbox "none" base checks "" "" checks "passed"`. |
| + - `TestStaleAdmissionNotCertified`, both `TestCertWithdrawnNotCertified` subtests and `TestWrongStepAttemptNotCertified`: `...: s1 done sandbox "none" base checks "" "" checks "passed", want nothing kept`. |
| + - `TestHostedCertifiedNewModuleNeedsNetwork` (both reasons): `task presents checks "" reason ""...` (the test lacked an Engineering candidate, which was then added). |
| + - `TestHostedCertifiedKeepsLastAdmission`: `job keeps admission "" (unexpected end of JSON input), image ""`. |
| + `TestHelloCannotCertify` and `TestMacRulesUnchanged` passed: they guard behaviour that already held. Mutations 346 and 348 are their failing evidence. |
| + |
| +Green: the brief's command, `CGO_ENABLED=0 go test ./internal/equipo/chat ./internal/equipo/mergegate -run 'TestHelloCannotCertify|TestHostedCertified|TestStaleAdmission|TestCertWithdrawn|TestWrongStepAttempt|TestMacRules' -count=1`: ok (chat 0.5 s; mergegate has no matching test, since its criteria needed no change). Also ok: |
| +- the whole `./internal/equipo/chat` (30 s under load), with `TestBaseChecksAttestationAcceptance` updated for the new parameter (a certified worker accepted, an uncertified one refused); |
| +- `./internal/equipo/hostedrun` (simulation 16 s alone, 22.6 s alongside chat; budget 60 s); |
| +- `./internal/equipo/mergegate`; |
| +- `./internal/equipo -run 'Enrol|Renew|HostedCredential|Migration|Schema|Hosted'`; |
| +- `./internal/equipotest -run 'Migration|Schema'`. |
| +`make migration-check budget build vet`: exit 0. staticcheck v0.7.0 on chat and hostedrun: clean. gofmt and `git diff --check`: clean. |
| + |
| +Mutations. Each was an exact-string replace by a script under `~/.cache/t24`, one at a time; the named test was run, and the text was replaced back and checked present: |
| +- **346** (brief) `hostedCertified` reads the hello: it returns true when the runner's stored hello says `bubblewrap` and names an image. `CGO_ENABLED=0 go test ./internal/equipo/chat -run TestHelloCannotCertify -count=1`: exit 1, `hosted_results_test.go:146: hello-certified result: done sandbox "bubblewrap" base checks "passed" "aaaa…"; want done, none, no base checks`. Restored. |
| +- **347** (brief) the freshness check skipped (the `now.Sub(*j.CertCheckedAt) > AdmissionFresh, …` case removed). `… -run TestStaleAdmissionNotCertified`: exit 1, `hosted_results_test.go:220: stale admission: s1 done sandbox "bubblewrap" base checks "passed" "aaaa…" checks "passed", want nothing kept`. The simulation is also a witness: `CGO_ENABLED=0 go test ./internal/equipo/hostedrun -run TestDispatcherSimulation -count=1` exits 1 with `sim_test.go:150: seed 66: s1 certified by hj-… on an admission from 2026-11-08 12:04:40 +0000 UTC at 2026-11-08 12:08:20 +0000 UTC` (seeds 43, 35 and 151 too). Before the 0-to-4-minute check duration was added, the simulation did not catch this mutation, because no report met a stale admission. Restored. |
| +- **348** (brief) `acceptBaseChecks` accepts any worker (`role != wire.RolePrimary && !(role == wire.RoleWorker && certified)` → `role != wire.RolePrimary && role != wire.RoleWorker`). `… -run 'TestHelloCannotCertify|TestMacRulesUnchanged|TestBaseChecksAttestationAcceptance'`: exit 1: |
| + - `hosted_results_test.go:146: hello-certified result: done sandbox "none" base checks "" "aaaa…"`; |
| + - `hosted_results_test.go:294: seatbelt: sandbox "seatbelt" base checks "" "aaaa…" tainted false`; |
| + - `injection_merge_test.go:28: an uncertified worker's base evidence accepted`. |
| + Restored. |
| +- **349** (extra) the step attempt binding dropped (`j.StepAttempt != stepAttempt` removed). `… -run TestWrongStepAttemptNotCertified`: exit 1, `hosted_results_test.go:274: another step attempt: s1 done sandbox "bubblewrap" … want nothing kept`. Restored. |
| +- **350** (extra) certificate validity ignored (`!j.CertValid` and `!a.CertValid` removed). `… -run TestCertWithdrawnNotCertified`: exit 1, `withdrawn: hosted_results_test.go:261: withdrawn: s1 done sandbox "bubblewrap" … want nothing kept`. Restored. |
| +- **351** (extra) the image binding dropped, in both `hostedCertified` and `hostedAdmitted`. Same command: exit 1, `another_image: hosted_results_test.go:261: another image: s1 done sandbox "bubblewrap" … want nothing kept`. Restored. |
| +- **352** (extra) an uncertified hosted runner taken by the old rules (`if bound {` → `if bound && false {`). `… -run TestStaleAdmissionNotCertified`: exit 1, `hosted_results_test.go:220: stale admission: s1 done sandbox "none" base checks "" "" checks "passed", want nothing kept`. Restored. |
| +- **353** (extra) the needs-network presentation removed. `… -run TestHostedCertifiedNewModuleNeedsNetwork`: exit 1, `hosted_results_test.go:203: task presents checks "cannot_run" reason "deps_new_module", want cannot_run needs_network` (and the same for `deps_missing`). Restored. |
| + |
| +Budgets, each with its reason: `internal/equipo/chat` 46957/21199 → 47094/21522. `internal/equipo/mergegate` and `hostedrun` are unchanged and within budget. |
diff --git a/internal/equipo/chat/hosted_enrol.go b/internal/equipo/chat/hosted_enrol.go| index 906d1a42..c6d93ee2 100644 |
| --- a/internal/equipo/chat/hosted_enrol.go |
| +++ b/internal/equipo/chat/hosted_enrol.go |
| @@ -70,7 +70,9 @@ func (s *Store) HostedClaimCode(tx *gorm.DB, code, launchID string, now time.Tim |
| // valid certificate, at the job's epoch; and now is within |
| // HostedEnrolTimeout of the earliest sighting of the VM running. A |
| // verified running record is a sighting: with none recorded, at is |
| -// recorded as the first. The record and the sighting are kept either way. |
| +// recorded as the first. The first admitting record's image is kept as |
| +// the VM's (image_digest). The record and the sighting are kept either |
| +// way. |
| func (s *Store) HostedEnrolAdmit(tx *gorm.DB, attempt, launchID, vmRef string, a hostedwire.AdmissionView, at, now time.Time) (HostedJob, bool, error) { |
| t := s.hostedTx(tx) |
| var j HostedJob |
| @@ -88,6 +90,14 @@ func (s *Store) HostedEnrolAdmit(tx *gorm.DB, attempt, launchID, vmRef string, a |
| if !ok { |
| return j, false, nil |
| } |
| + if j.ImageDigest == "" && a.Image != "" { |
| + // The image this admission names is the VM's from now on: a later |
| + // record naming another is not valid (hostedAdmitted), and none |
| + // certifies its results (hostedCertified). |
| + if err := tx.Model(&HostedJob{}).Where("attempt_id = ? AND coalesce(image_digest, '') = ''", attempt).Update("image_digest", string(a.Image)).Error; err != nil { |
| + return j, false, err |
| + } |
| + } |
| seen := at.UTC() |
| if j.RunningSeenAt == nil { |
| res := tx.Model(&HostedJob{}).Where("attempt_id = ? AND state = ? AND running_seen_at IS NULL", attempt, HostedJobEnrolling). |
diff --git a/internal/equipo/chat/hosted_jobs.go b/internal/equipo/chat/hosted_jobs.go| index f72ee0bd..192e5a98 100644 |
| --- a/internal/equipo/chat/hosted_jobs.go |
| +++ b/internal/equipo/chat/hosted_jobs.go |
| @@ -84,10 +84,19 @@ type HostedJob struct { |
| // running while it waited to enrol: the enrolment window runs from it |
| // (HostedEnrolTimeout), across restarts and controller outages. |
| RunningSeenAt *time.Time |
| - // Cert* is the controller's latest admission record for the VM. |
| + // Cert* is the controller's latest admission record for the VM: |
| + // CertDigest the certificate's, from the first record (one naming |
| + // another never counts as valid), CertValid whether the latest |
| + // record was valid for the job, CertCheckedAt when it was asked for. |
| CertDigest string |
| CertValid bool |
| CertCheckedAt *time.Time |
| + // ImageDigest is the image the admission that enrolled the VM named; |
| + // AdmissionJSON is the latest admission record kept, whole (a |
| + // hostedwire.AdmissionView). Only these, never a hello, certify the |
| + // VM's results (hostedCertified). |
| + ImageDigest string |
| + AdmissionJSON string `gorm:"column:admission_json"` |
| CodeHash string `gorm:"uniqueIndex:hosted_jobs_code,where:code_hash <> ''"` |
| CodeExpiresAt *time.Time |
| CodeUsedAt *time.Time |
diff --git a/internal/equipo/chat/hosted_results.go b/internal/equipo/chat/hosted_results.go| new file mode 100644 |
| index 00000000..1f131eba |
| --- /dev/null |
| +++ b/internal/equipo/chat/hosted_results.go |
| @@ -0,0 +1,83 @@ |
| +package chat |
| + |
| +import ( |
| + "encoding/json" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/hostedwire" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Certified results from hosted workers (hosted runners slice 2, Task 24; |
| +// Fable M8). A hosted worker's checks count as sandboxed, and its base |
| +// checks as trusted, only through the controller's admission record the |
| +// instance kept for the job its runner is bound to: fresh, valid, and |
| +// naming what the VM enrolled with. What the runner says of itself (its |
| +// hello, its report's sandbox) never certifies it. |
| + |
| +// AdmissionFresh is how far from a report's arrival the reporting VM's |
| +// latest admission record may have been asked for, for the report to be |
| +// certified. The dispatcher refreshes it every pass (about 10 s). |
| +const AdmissionFresh = 2 * time.Minute |
| + |
| +// hostedStopUncertified is why a hosted job stops when its runner's |
| +// checks result could not be certified: the job ends failed, and its |
| +// step is placed again once (placeHosted's rule 2). |
| +const hostedStopUncertified = "uncertified" |
| + |
| +// hostedCertified reports whether runnerID's checks result for attempt |
| +// stepAttempt of step stepID, arriving at now, is certified: the runner |
| +// is bound to an enrolled job for exactly that step and attempt, and the |
| +// job's latest admission record (asked for within AdmissionFresh of now) |
| +// was valid, shows the VM running and names the launch, VM, epoch, image |
| +// and certificate the job recorded at its enrolment. Everything is read |
| +// in the caller's transaction; a read error is false (and returned). |
| +func (t *txn) hostedCertified(runnerID, stepID string, stepAttempt int64, now time.Time) (bool, error) { |
| + if runnerID == "" { |
| + return false, nil |
| + } |
| + j, found, err := t.hostedJobForRunner(runnerID) |
| + if err != nil || !found { |
| + return false, err |
| + } |
| + var a hostedwire.AdmissionView |
| + if j.AdmissionJSON == "" || json.Unmarshal([]byte(j.AdmissionJSON), &a) != nil { |
| + return false, nil |
| + } |
| + switch { |
| + case j.State != HostedJobEnrolled, j.StepID != stepID, j.StepAttempt != stepAttempt: |
| + case !j.CertValid, j.CertCheckedAt == nil: |
| + case now.Sub(*j.CertCheckedAt) > AdmissionFresh, j.CertCheckedAt.Sub(now) > AdmissionFresh: |
| + case !a.CertValid, a.State != hostedRunning, a.AttemptID != j.AttemptID: |
| + case j.LaunchID == "" || a.LaunchID != j.LaunchID, j.VMRef == "" || string(a.VMRef) != j.VMRef, a.Epoch != j.Epoch: |
| + case j.ImageDigest == "" || string(a.Image) != j.ImageDigest: |
| + case j.CertDigest == "" || a.CertDigest != j.CertDigest: |
| + default: |
| + return true, nil |
| + } |
| + return false, nil |
| +} |
| + |
| +// hostedUncertified stops j, whose runner's checks result could not be |
| +// certified. The runner is not tainted (it may have run them in its |
| +// sandbox; nothing certifies that it did) and the result is not kept: |
| +// once the VM is proven stopped the step is placed again under the same |
| +// attempt (hostedStepAgain), once. |
| +func (t *txn) hostedUncertified(j HostedJob) error { |
| + if !j.Live() || j.State == HostedJobStopping { |
| + return nil |
| + } |
| + return t.hostedStopping(j.AttemptID, hostedStopUncertified) |
| +} |
| + |
| +// presentedChecksReason is a checks reason as the person sees it: a |
| +// hosted VM that could not stage a module (one the base does not pin, or |
| +// one the bundle lacks) needs the network to run those checks. The step |
| +// keeps its own reason. |
| +func presentedChecksReason(reason string) string { |
| + switch reason { |
| + case wire.ReasonDepsNewModule, wire.ReasonDepsMissing: |
| + return "needs_network" |
| + } |
| + return reason |
| +} |
diff --git a/internal/equipo/chat/hosted_results_test.go b/internal/equipo/chat/hosted_results_test.go| new file mode 100644 |
| index 00000000..08db3421 |
| --- /dev/null |
| +++ b/internal/equipo/chat/hosted_results_test.go |
| @@ -0,0 +1,313 @@ |
| +package chat |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/base64" |
| + "encoding/json" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| + "amadan.net/oficina/equipo/internal/hostedwire" |
| + "amadan.net/oficina/equipo/internal/isolatedjob" |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// Hosted slice 2, Task 24 (Fable M8): a hosted worker's checks result |
| +// counts as sandboxed, and its base checks as trusted, only through a |
| +// fresh, valid controller admission the instance recorded for the job its |
| +// runner is bound to, never because the runner says so. |
| + |
| +const hrCert = "cert-digest-1" |
| + |
| +var hrImage = isolatedjob.ImageDigest("sha256:" + strings.Repeat("c", 64)) |
| + |
| +// hrAdmission is the controller's admission record for attempt's job on |
| +// VM vm (launch "launch-"+vm, epoch 0), certificate valid or not. |
| +func hrAdmission(attempt, vm string, valid bool) hostedwire.AdmissionView { |
| + return hostedwire.AdmissionView{AttemptID: attempt, LaunchID: "launch-" + vm, State: "running", VMRef: isolatedjob.Ref(vm), Epoch: 0, Image: hrImage, |
| + CertDigest: hrCert, CertValid: valid, DeadlineInMS: HostedChecksLifetime.Milliseconds()} |
| +} |
| + |
| +// certifiedOnVM launches s1's newest job on VM vm and enrols it as runner |
| +// the way the instance does (Task 22: the code used, a valid admission |
| +// recorded, the runner bound), at r.now; the step is placed on it. |
| +func (r *hkRig) certifiedOnVM(vm, runner string) HostedJob { |
| + r.t.Helper() |
| + jobs := r.jobsOf("s1") |
| + a := jobs[len(jobs)-1].AttemptID |
| + r.launched(a, vm) |
| + sum := sha256.Sum256([]byte(vm)) |
| + code := base64.RawURLEncoding.EncodeToString(sum[:]) |
| + r.runner(runner, wire.RoleWorker) |
| + r.must(r.tx(func(t *txn) error { |
| + if _, err := r.s.HostedClaimCode(t.db, code, "launch-"+vm, r.now); err != nil { |
| + return err |
| + } |
| + _, ok, err := r.s.HostedEnrolAdmit(t.db, a, "launch-"+vm, vm, hrAdmission(a, vm, true), r.now, r.now) |
| + if err != nil || !ok { |
| + r.t.Fatalf("enrolment of %s admitted %t: %v", a, ok, err) |
| + } |
| + return r.s.HostedEnrolBind(t.db, a, runner, "machine-key") |
| + })) |
| + r.online(runner, wire.ProtocolHostedRunners) |
| + r.online(hpPrimary, wire.ProtocolHostedRunners) |
| + r.place() |
| + if s := r.step("s1"); s.RunnerID != runner { |
| + r.t.Fatalf("s1 on %q, want %s", s.RunnerID, runner) |
| + } |
| + return r.job(a) |
| +} |
| + |
| +// passedReport is a checks pass for s1's candidate with base checks |
| +// passed on its base, confined as sandbox says. |
| +func passedReport(step string, attempt int64, sandbox string) wire.StepReport { |
| + zero := 0 |
| + return wire.StepReport{TaskID: "tkp", StepID: step, Attempt: attempt, State: wire.StepDone, Termination: true, BaseSHA: hpBase, CandidateSHA: hpCandidate, |
| + Checks: wire.ChecksPassed, Gate: "make ci", ExitCode: &zero, ChecksSandbox: sandbox, BaseChecks: wire.ChecksPassed, BaseChecksSHA: hpBase, Findings: []wire.Finding{}} |
| +} |
| + |
| +// reportAs applies rep from runner through the production step report. |
| +func (r *hkRig) reportAs(runner string, rep wire.StepReport) { |
| + r.t.Helper() |
| + r.must(r.tx(func(t *txn) error { return t.stepReport(hostedLease(runner), &rep) })) |
| +} |
| + |
| +func (r *hkRig) tainted(runner string) bool { |
| + r.t.Helper() |
| + return r.count("SELECT count(*) FROM runners WHERE id = ? AND tainted_at IS NOT NULL", runner) > 0 |
| +} |
| + |
| +// uncertified checks that a hosted runner's result did not count: s1 is |
| +// not done, nothing of the report was kept, the runner is not tainted, |
| +// and its job is stopping for want of certification. |
| +func (r *hkRig) uncertified(what, runner string, j HostedJob) { |
| + r.t.Helper() |
| + s := r.step("s1") |
| + if s.State == wire.StepDone || s.ChecksSandbox != "" || s.BaseChecks != "" || s.BaseChecksSHA != "" || s.Checks != "" { |
| + r.t.Fatalf("%s: s1 %s sandbox %q base checks %q %q checks %q, want nothing kept", what, s.State, s.ChecksSandbox, s.BaseChecks, s.BaseChecksSHA, s.Checks) |
| + } |
| + if r.tainted(runner) { |
| + r.t.Fatalf("%s: hosted runner %s tainted", what, runner) |
| + } |
| + if got := r.job(j.AttemptID); got.State != HostedJobStopping || got.StopReason != hostedStopUncertified { |
| + r.t.Fatalf("%s: job %s %q, want stopping %q", what, got.State, got.StopReason, hostedStopUncertified) |
| + } |
| +} |
| + |
| +// gate is the merge gate's decision for tkp with s1 as its checks and an |
| +// approving review of the same candidate. |
| +func (r *hkRig) gate() mergegate.Decision { |
| + r.t.Helper() |
| + checks := r.step("s1") |
| + k := r.load("tkp") |
| + p := progress{candidate: hpCandidate, checks: &checks, review: &stepRecord{State: wire.StepDone, Verdict: wire.VerdictApprove, CandidateSHA: hpCandidate}} |
| + var d mergegate.Decision |
| + r.must(r.tx(func(t *txn) error { |
| + in, _, err := t.mergeInputs(k, p, false, wire.ProtocolHostedRunners) |
| + d = mergegate.Decide(in) |
| + return err |
| + })) |
| + return d |
| +} |
| + |
| +func criterion(d mergegate.Decision, name string) (bool, bool) { |
| + for _, c := range d.Reasons { |
| + if c.Name == name { |
| + return c.OK, true |
| + } |
| + } |
| + return false, false |
| +} |
| + |
| +// TestHelloCannotCertify: a Linux worker bound to no hosted job, whose |
| +// hello claims bubblewrap and the certified image and VM of a job that |
| +// is certified, reports checks run in bubblewrap with base checks: the |
| +// result is stored as run outside the sandbox (none), the runner is |
| +// tainted, and no base checks are kept. The hello is still stored. |
| +func TestHelloCannotCertify(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + r.certifiedOnVM("vm-1", "H1") |
| + r.runner("L1", wire.RoleWorker) |
| + r.online("L1", wire.ProtocolHostedRunners) |
| + hello := wire.Hello{Protocol: wire.ProtocolHostedRunners, Label: "vm-1", Sandbox: wire.SandboxBubblewrap, Platform: &wire.Platform{OS: "linux", Arch: "amd64"}, |
| + Versions: map[string]string{"image": string(hrImage), "cert_digest": hrCert, "vm_ref": "vm-1", "certified": "true"}} |
| + r.must(r.s.Heartbeat(r.ctx, hostedLease("L1"), hello)) |
| + if n := r.count("SELECT count(*) FROM runner_sessions WHERE runner_id = 'L1' AND hello LIKE ?", "%"+string(hrImage)+"%"); n != 1 { |
| + t.Fatalf("the hello was not kept for diagnostics: %d", n) |
| + } |
| + st := stepRecord{ID: "s2", TaskID: "tkp", Idx: 3, Person: hkOwner, RunnerID: "L1", Specialist: wire.SpecialistChecks, State: wire.StepRunning, Attempt: 1, BaseSHA: hpBase, CandidateSHA: hpCandidate, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + r.must(r.s.db.G.Create(&st).Error) |
| + r.reportAs("L1", passedReport("s2", 1, wire.SandboxBubblewrap)) |
| + s := r.step("s2") |
| + if s.State != wire.StepDone || s.ChecksSandbox != wire.SandboxNone || s.BaseChecks != "" || s.BaseChecksSHA != "" { |
| + t.Fatalf("hello-certified result: %s sandbox %q base checks %q %q; want done, none, no base checks", s.State, s.ChecksSandbox, s.BaseChecks, s.BaseChecksSHA) |
| + } |
| + if !r.tainted("L1") { |
| + t.Fatal("a worker that ran checks outside the sandbox was not tainted") |
| + } |
| +} |
| + |
| +// TestHostedCertifiedResultCounts: a certified VM's runner, its admission |
| +// refreshed within AdmissionFresh, reports checks passed in bubblewrap |
| +// with base checks: both are kept, and the merge gate's checked_in_sandbox |
| +// and trusted_base_checks hold. Its runner is not tainted. |
| +func TestHostedCertifiedResultCounts(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(5 * time.Minute) |
| + r.must(r.s.HostedAdmitted(r.ctx, j.AttemptID, hrAdmission(j.AttemptID, "vm-1", true), r.now.Add(-AdmissionFresh))) |
| + r.reportAs("H1", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + s := r.step("s1") |
| + if s.State != wire.StepDone || s.ChecksSandbox != wire.SandboxBubblewrap || s.BaseChecks != wire.ChecksPassed || s.BaseChecksSHA != hpBase || s.Checks != wire.ChecksPassed { |
| + t.Fatalf("certified result: %s sandbox %q base checks %q %q checks %q", s.State, s.ChecksSandbox, s.BaseChecks, s.BaseChecksSHA, s.Checks) |
| + } |
| + if r.tainted("H1") { |
| + t.Fatal("a certified hosted runner was tainted") |
| + } |
| + d := r.gate() |
| + for _, name := range []string{mergegate.CritSandbox, mergegate.CritBaseChecks} { |
| + if ok, found := criterion(d, name); !found || !ok { |
| + t.Fatalf("merge gate %s: ok %t found %t (%+v)", name, ok, found, d.Reasons) |
| + } |
| + } |
| +} |
| + |
| +// TestHostedCertifiedNewModuleNeedsNetwork: a certified VM's checks that |
| +// could not stage a module (deps_new_module, deps_missing) end cannot_run |
| +// with that reason on the step, and the task presents them to the person |
| +// as needing the network. |
| +func TestHostedCertifiedNewModuleNeedsNetwork(t *testing.T) { |
| + for _, reason := range []string{wire.ReasonDepsNewModule, wire.ReasonDepsMissing} { |
| + t.Run(reason, func(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + eng := stepRecord{ID: "s0", TaskID: "tkp", Idx: 1, Person: hkOwner, Specialist: wire.SpecialistEngineering, State: wire.StepDone, Attempt: 1, CandidateSHA: hpCandidate, Pushed: true, Terminated: true, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + r.must(r.s.db.G.Create(&eng).Error) |
| + r.checksStep("s1", "tkp") |
| + r.certifiedOnVM("vm-1", "H1") |
| + r.reportAs("H1", wire.StepReport{TaskID: "tkp", StepID: "s1", Attempt: 1, State: wire.StepDone, Termination: true, BaseSHA: hpBase, CandidateSHA: hpCandidate, |
| + Checks: wire.ChecksCannotRun, Reason: reason, Findings: []wire.Finding{}}) |
| + if s := r.step("s1"); s.State != wire.StepDone || s.Checks != wire.ChecksCannotRun || s.Reason != reason { |
| + t.Fatalf("step: %s %s %q", s.State, s.Checks, s.Reason) |
| + } |
| + var v wire.Task |
| + r.must(r.tx(func(t *txn) error { |
| + var err error |
| + v, err = t.taskView(r.load("tkp")) |
| + return err |
| + })) |
| + if v.Checks != wire.ChecksCannotRun || v.ChecksReason != "needs_network" { |
| + t.Fatalf("task presents checks %q reason %q, want cannot_run needs_network", v.Checks, v.ChecksReason) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestStaleAdmissionNotCertified: the job's last admission was checked |
| +// 2 min 1 s before the report arrived. The result is not certified (not |
| +// kept), the runner is not tainted, and the job stops; once its VM is |
| +// proven stopped the step is placed again under the same attempt, once. |
| +// The retry's VM, stale too, ends the step not run. |
| +func TestStaleAdmissionNotCertified(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(AdmissionFresh + time.Second) |
| + r.reportAs("H1", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + r.uncertified("stale admission", "H1", j) |
| + r.online(hpPrimary, wire.ProtocolHostedRunners) |
| + r.must(r.s.HostedStopped(r.ctx, j.AttemptID, hostedwire.StopProof{AttemptID: j.AttemptID, VMRef: "vm-1", State: isolatedjob.StateStopped}, r.now)) |
| + jobs := r.jobsOf("s1") |
| + if s := r.step("s1"); len(jobs) != 2 || jobs[1].RetryOf != j.AttemptID || jobs[1].StepAttempt != 1 || s.Attempt != 1 || s.State != wire.StepQueued { |
| + t.Fatalf("after the uncertified VM stopped: step %s attempt %d, jobs %+v", s.State, s.Attempt, jobs) |
| + } |
| + second := r.certifiedOnVM("vm-2", "H2") |
| + r.now = r.now.Add(AdmissionFresh + time.Second) |
| + r.reportAs("H2", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + r.uncertified("the retry, stale too", "H2", second) |
| + r.online(hpPrimary, wire.ProtocolHostedRunners) |
| + r.must(r.s.HostedStopped(r.ctx, second.AttemptID, hostedwire.StopProof{AttemptID: second.AttemptID, VMRef: "vm-2", State: isolatedjob.StateStopped}, r.now)) |
| + s := r.step("s1") |
| + if len(r.jobsOf("s1")) != 2 || s.State != wire.StepDone || s.Checks != wire.ChecksCannotRun || s.Reason != wire.ReasonHostedUnavailable || s.ChecksSandbox != "" || s.BaseChecksSHA != "" { |
| + t.Fatalf("after the retry: %d jobs, step %s %s %q sandbox %q base %q", len(r.jobsOf("s1")), s.State, s.Checks, s.Reason, s.ChecksSandbox, s.BaseChecksSHA) |
| + } |
| +} |
| + |
| +// TestCertWithdrawnNotCertified: the job's latest admission, fresh, says |
| +// the certificate is no longer valid; or names another image than the one |
| +// the VM enrolled with. Either way the result is not certified. |
| +func TestCertWithdrawnNotCertified(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + edit func(*hostedwire.AdmissionView) |
| + }{ |
| + {"withdrawn", func(a *hostedwire.AdmissionView) { a.CertValid = false }}, |
| + {"another image", func(a *hostedwire.AdmissionView) { |
| + a.Image = isolatedjob.ImageDigest("sha256:" + strings.Repeat("d", 64)) |
| + }}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.now = r.now.Add(30 * time.Second) |
| + a := hrAdmission(j.AttemptID, "vm-1", true) |
| + tc.edit(&a) |
| + r.must(r.s.HostedAdmitted(r.ctx, j.AttemptID, a, r.now)) |
| + r.reportAs("H1", passedReport("s1", 1, wire.SandboxBubblewrap)) |
| + r.uncertified(tc.name, "H1", j) |
| + }) |
| + } |
| +} |
| + |
| +// TestWrongStepAttemptNotCertified: the runner's job is for attempt 1 of |
| +// s1; a report for attempt 2 on the same runner is not certified by it. |
| +func TestWrongStepAttemptNotCertified(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + r.exec("UPDATE chat_steps SET attempt = 2 WHERE id = 's1'") |
| + r.reportAs("H1", passedReport("s1", 2, wire.SandboxBubblewrap)) |
| + r.uncertified("another step attempt", "H1", j) |
| +} |
| + |
| +// TestMacRulesUnchanged: a Mac worker (no hosted job) still counts as |
| +// sandboxed only for seatbelt and only while untainted; its base checks |
| +// are never read; anything else taints it for good. |
| +func TestMacRulesUnchanged(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.runner("M1", wire.RoleWorker) |
| + r.online("M1", wire.ProtocolHostedRunners) |
| + idx := 2 |
| + run := func(id, sandbox string) stepRecord { |
| + t.Helper() |
| + idx++ |
| + st := stepRecord{ID: id, TaskID: "tkp", Idx: idx, Person: hkOwner, RunnerID: "M1", Specialist: wire.SpecialistChecks, State: wire.StepRunning, Attempt: 1, BaseSHA: hpBase, CandidateSHA: hpCandidate, Revision: 1, CreatedAt: r.now, UpdatedAt: r.now} |
| + r.must(r.s.db.G.Create(&st).Error) |
| + r.reportAs("M1", passedReport(id, 1, sandbox)) |
| + return r.step(id) |
| + } |
| + if s := run("m1", wire.SandboxSeatbelt); s.ChecksSandbox != wire.SandboxSeatbelt || s.BaseChecks != "" || s.BaseChecksSHA != "" || r.tainted("M1") { |
| + t.Fatalf("seatbelt: sandbox %q base checks %q %q tainted %t", s.ChecksSandbox, s.BaseChecks, s.BaseChecksSHA, r.tainted("M1")) |
| + } |
| + if s := run("m2", wire.SandboxBubblewrap); s.ChecksSandbox != wire.SandboxNone || s.BaseChecksSHA != "" || !r.tainted("M1") { |
| + t.Fatalf("bubblewrap on a Mac worker: sandbox %q base %q tainted %t", s.ChecksSandbox, s.BaseChecksSHA, r.tainted("M1")) |
| + } |
| + if s := run("m3", wire.SandboxSeatbelt); s.ChecksSandbox != wire.SandboxNone { |
| + t.Fatalf("seatbelt after a taint: %q", s.ChecksSandbox) |
| + } |
| +} |
| + |
| +// The job keeps the last admission it recorded, whole. |
| +func TestHostedCertifiedKeepsLastAdmission(t *testing.T) { |
| + r := hostedPlaceRig(t) |
| + r.checksStep("s1", "tkp") |
| + j := r.certifiedOnVM("vm-1", "H1") |
| + var a hostedwire.AdmissionView |
| + if err := json.Unmarshal([]byte(j.AdmissionJSON), &a); err != nil || a.Image != hrImage || a.CertDigest != hrCert || j.ImageDigest != string(hrImage) { |
| + t.Fatalf("job keeps admission %q (%v), image %q", j.AdmissionJSON, err, j.ImageDigest) |
| + } |
| +} |
diff --git a/internal/equipo/chat/hosted_run.go b/internal/equipo/chat/hosted_run.go| index 3ddcf834..b0ba85c8 100644 |
| --- a/internal/equipo/chat/hosted_run.go |
| +++ b/internal/equipo/chat/hosted_run.go |
| @@ -339,8 +339,9 @@ func (t *txn) hostedDeadlineSeen(attempt string, inMS int64, asked time.Time) er |
| // HostedAdmitted records the controller's admission record for the job's |
| // VM, observed at at on the instance's clock: valid only when the |
| // controller says the certificate is valid and it names the job's launch, |
| -// VM, epoch and (once recorded) certificate. A record older than the one |
| -// held is ignored. |
| +// VM, epoch and (once recorded) certificate and enrolment image. The |
| +// record is kept whole (admission_json). A record older than the one held |
| +// is ignored. |
| func (s *Store) HostedAdmitted(ctx context.Context, attempt string, a hostedwire.AdmissionView, at time.Time) error { |
| return s.tx(ctx, func(t *txn) error { |
| var j HostedJob |
| @@ -369,14 +370,18 @@ func (t *txn) hostedAdmitted(j HostedJob, a hostedwire.AdmissionView, at time.Ti |
| } |
| } |
| valid = a.CertValid && a.LaunchID == j.LaunchID && string(a.VMRef) == j.VMRef && a.Epoch == j.Epoch && a.CertDigest != "" && |
| - (j.CertDigest == "" || j.CertDigest == a.CertDigest) |
| + (j.CertDigest == "" || j.CertDigest == a.CertDigest) && (j.ImageDigest == "" || string(a.Image) == j.ImageDigest) |
| digest := j.CertDigest |
| if digest == "" { |
| digest = a.CertDigest |
| } |
| + raw, err := json.Marshal(a) |
| + if err != nil { |
| + return false, false, err |
| + } |
| when := at.UTC() |
| res := t.db.Model(&HostedJob{}).Where("attempt_id = ? AND (cert_checked_at IS NULL OR cert_checked_at <= ?)", attempt, when). |
| - Updates(map[string]any{"cert_digest": digest, "cert_valid": valid, "cert_checked_at": when}) |
| + Updates(map[string]any{"cert_digest": digest, "cert_valid": valid, "cert_checked_at": when, "admission_json": string(raw)}) |
| if res.Error != nil { |
| return false, false, res.Error |
| } |
diff --git a/internal/equipo/chat/injection_merge_test.go b/internal/equipo/chat/injection_merge_test.go| index 332bb144..08edd62b 100644 |
| --- a/internal/equipo/chat/injection_merge_test.go |
| +++ b/internal/equipo/chat/injection_merge_test.go |
| @@ -14,9 +14,19 @@ func TestBaseChecksAttestationAcceptance(t *testing.T) { |
| s := stepRecord{Specialist: wire.SpecialistChecks, BaseSHA: base, CandidateSHA: candidate} |
| l := Lease{Protocol: wire.ProtocolInjectionDefences} |
| v := wire.StepReport{BaseSHA: base, CandidateSHA: candidate, BaseChecksSHA: base, Checks: wire.ChecksPassed, Termination: true, Gate: "make ci"} |
| - if got := acceptBaseChecks(l, wire.RolePrimary, s, &v); got != base { |
| + if got := acceptBaseChecks(l, wire.RolePrimary, false, s, &v); got != base { |
| t.Fatal("trusted base evidence refused") |
| } |
| + // A worker's, only when certified (a hosted VM's fresh admission, |
| + // Task 24): its own report's sandbox claim is not enough. |
| + w := v |
| + w.ChecksSandbox = wire.SandboxBubblewrap |
| + if got := acceptBaseChecks(l, wire.RoleWorker, true, s, &w); got != base { |
| + t.Fatal("a certified worker's base evidence refused") |
| + } |
| + if got := acceptBaseChecks(l, wire.RoleWorker, false, s, &w); got != "" { |
| + t.Fatal("an uncertified worker's base evidence accepted") |
| + } |
| for _, tc := range []struct { |
| name string |
| edit func(*Lease, *stepRecord, *wire.StepReport) |
| @@ -39,7 +49,7 @@ func TestBaseChecksAttestationAcceptance(t *testing.T) { |
| t.Run(tc.name, func(t *testing.T) { |
| l, s, v := l, s, v |
| tc.edit(&l, &s, &v) |
| - if acceptBaseChecks(l, tc.role, s, &v) != "" { |
| + if acceptBaseChecks(l, tc.role, false, s, &v) != "" { |
| t.Fatal("untrusted checks accepted") |
| } |
| }) |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| index ff0d9325..0467d29b 100644 |
| --- a/internal/equipo/chat/mergeauth.go |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -1380,9 +1380,11 @@ const ( |
| toolNoProject = "No such project. Use its repository as add_project returned it." |
| ) |
| -// acceptBaseChecks binds trusted gate execution to this checks attempt. |
| -func acceptBaseChecks(l Lease, role string, s stepRecord, v *wire.StepReport) string { |
| - if l.Protocol < wire.ProtocolInjectionDefences || role != wire.RolePrimary || s.Specialist != wire.SpecialistChecks || v.Checks != wire.ChecksPassed || v.BaseChecks == wire.ChecksFailed || v.BaseChecks == wire.ChecksCannotRun || !v.Termination || v.Hosted != nil || v.Gate == wire.GateHosted || v.ChecksSandbox == wire.SandboxHosted || v.ChecksSandbox == wire.SandboxNone || !validSHA(v.BaseChecksSHA) || v.BaseChecksSHA != s.BaseSHA || v.BaseSHA != s.BaseSHA || v.CandidateSHA != s.CandidateSHA { |
| +// acceptBaseChecks binds trusted gate execution to this checks attempt: |
| +// the primary's, or a worker's only when certified (hostedCertified, a |
| +// hosted VM's fresh admission record). |
| +func acceptBaseChecks(l Lease, role string, certified bool, s stepRecord, v *wire.StepReport) string { |
| + if l.Protocol < wire.ProtocolInjectionDefences || role != wire.RolePrimary && !(role == wire.RoleWorker && certified) || s.Specialist != wire.SpecialistChecks || v.Checks != wire.ChecksPassed || v.BaseChecks == wire.ChecksFailed || v.BaseChecks == wire.ChecksCannotRun || !v.Termination || v.Hosted != nil || v.Gate == wire.GateHosted || v.ChecksSandbox == wire.SandboxHosted || v.ChecksSandbox == wire.SandboxNone || !validSHA(v.BaseChecksSHA) || v.BaseChecksSHA != s.BaseSHA || v.BaseSHA != s.BaseSHA || v.CandidateSHA != s.CandidateSHA { |
| return "" |
| } |
| return v.BaseChecksSHA |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index fe7a23b3..39cf0158 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -237,7 +237,9 @@ const MaxRunnerLabel = 80 |
| // cleanHello keeps what the instance stores of a hello within bounds: a |
| // capability report out of bounds is dropped (the runner is treated as |
| -// able to do nothing special), the label is one short line. |
| +// able to do nothing special), the label is one short line. A hello is |
| +// diagnostic only (Fable M8): its sandbox, versions or image never make a |
| +// result sandboxed or base checks trusted (hostedCertified decides). |
| func cleanHello(h wire.Hello) wire.Hello { |
| if h.Capabilities != nil && wire.ValidCapabilities(*h.Capabilities) != nil { |
| h.Capabilities = nil |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index a8aa392b..5f238f13 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -669,6 +669,7 @@ func (t *txn) taskViewWith(k taskRecord, options taskViewOptions) (wire.Task, er |
| v.BranchHead = k.BranchHead |
| } |
| v.Checks, v.ChecksReason, v.Verdict, v.ReviewLabel = pr.judged() |
| + v.ChecksReason = presentedChecksReason(v.ChecksReason) |
| if (v.Checks == wire.ChecksPassed || v.Checks == wire.ChecksFailed) && pr.checks != nil { |
| v.ChecksSandbox = pr.checks.ChecksSandbox |
| } |
| @@ -1862,8 +1863,28 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| if !ok { |
| return nil |
| } |
| + // certified: a hosted worker's result, through the |
| + // controller's fresh admission record for its job alone |
| + // (never its hello or its word). A hosted runner that is |
| + // not certified keeps nothing and is not tainted: its job |
| + // stops and the step is placed again, once. |
| + certified := false |
| + if s.Specialist == wire.SpecialistChecks && role == wire.RoleWorker { |
| + if certified, err = t.hostedCertified(l.Runner.RunnerID, s.ID, s.Attempt, now); err != nil { |
| + return err |
| + } |
| + if !certified { |
| + j, bound, err := t.hostedJobForRunner(l.Runner.RunnerID) |
| + if err != nil { |
| + return err |
| + } |
| + if bound { |
| + return t.hostedUncertified(j) |
| + } |
| + } |
| + } |
| s.Reason, s.Verdict, s.ReviewLabel, s.Checks, s.Gate, s.ExitCode = v.Reason, v.Verdict, v.ReviewLabel, v.Checks, v.Gate, v.ExitCode |
| - if s.Specialist == wire.SpecialistChecks && role == wire.RolePrimary && l.Protocol >= wire.ProtocolInjectionDefences { |
| + if s.Specialist == wire.SpecialistChecks && (role == wire.RolePrimary || certified) && l.Protocol >= wire.ProtocolInjectionDefences { |
| switch v.BaseChecks { |
| case wire.ChecksPassed, wire.ChecksFailed, wire.ChecksCannotRun: |
| s.BaseChecks = v.BaseChecks |
| @@ -1877,17 +1898,22 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| } |
| if s.Specialist == wire.SpecialistChecks && role == wire.RoleWorker { |
| // A worker's word on how its checks were confined; |
| - // anything but seatbelt is outside the sandbox, and a |
| - // runner that once ran checks outside it never again |
| - // counts as sandboxed (the instance's record, which the |
| - // runner cannot clear). |
| + // anything but seatbelt (bubblewrap on a certified |
| + // hosted VM) is outside the sandbox, and a runner that |
| + // once ran checks outside it never again counts as |
| + // sandboxed (the instance's record, which the runner |
| + // cannot clear). |
| tainted, err := t.tainted(l.Runner.RunnerID) |
| if err != nil { |
| return err |
| } |
| + confined := wire.SandboxSeatbelt |
| + if certified { |
| + confined = wire.SandboxBubblewrap |
| + } |
| s.ChecksSandbox = wire.SandboxNone |
| - if v.ChecksSandbox == wire.SandboxSeatbelt && !tainted { |
| - s.ChecksSandbox = wire.SandboxSeatbelt |
| + if v.ChecksSandbox == confined && !tainted { |
| + s.ChecksSandbox = confined |
| } |
| if s.ChecksSandbox == wire.SandboxNone { |
| if err := t.markTainted(l.Runner.RunnerID); err != nil { |
| @@ -1899,7 +1925,7 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| raw, _ := json.Marshal(v.Failure) |
| s.FailureSignature = string(raw) |
| } |
| - s.BaseChecksSHA = acceptBaseChecks(l, role, s, v) |
| + s.BaseChecksSHA = acceptBaseChecks(l, role, certified, s, v) |
| s.Output = clipText(v.Output, wire.MaxChecksOutput) |
| if hosted != "" { |
| s.HostedCI, s.ChecksSandbox = hosted, wire.SandboxHosted |
diff --git a/internal/equipo/hostedrun/dispatcher_test.go b/internal/equipo/hostedrun/dispatcher_test.go| index 37407d74..3e800579 100644 |
| --- a/internal/equipo/hostedrun/dispatcher_test.go |
| +++ b/internal/equipo/hostedrun/dispatcher_test.go |
| @@ -109,6 +109,8 @@ type rig struct { |
| ctl *fakeCtl |
| disp *Dispatcher |
| logs *bytes.Buffer |
| + // frames numbers the runner frames the simulation applies. |
| + frames int |
| } |
| func newRig(t testing.TB, rng *rand.Rand) *rig { |
| @@ -217,13 +219,15 @@ func (r *rig) checks(id, tk string) { |
| type stepRow struct { |
| State, Placement, RunnerID, Reason, Checks string |
| + TaskID, ChecksSandbox, BaseChecksSHA string |
| Attempt int64 |
| } |
| func (r *rig) step(id string) stepRow { |
| r.t.Helper() |
| var rows []stepRow |
| - r.must(r.d.G.Raw("SELECT coalesce(state, '') AS state, coalesce(placement, '') AS placement, coalesce(runner_id, '') AS runner_id, coalesce(reason, '') AS reason, coalesce(checks, '') AS checks, attempt FROM chat_steps WHERE id = ?", id).Scan(&rows).Error) |
| + r.must(r.d.G.Raw("SELECT coalesce(state, '') AS state, coalesce(placement, '') AS placement, coalesce(runner_id, '') AS runner_id, coalesce(reason, '') AS reason, coalesce(checks, '') AS checks, "+ |
| + "task_id, coalesce(checks_sandbox, '') AS checks_sandbox, coalesce(base_checks_sha, '') AS base_checks_sha, attempt FROM chat_steps WHERE id = ?", id).Scan(&rows).Error) |
| if len(rows) != 1 { |
| r.t.Fatalf("step %s: %d rows", id, len(rows)) |
| } |
diff --git a/internal/equipo/hostedrun/sim_test.go b/internal/equipo/hostedrun/sim_test.go| index e649b15b..def7c237 100644 |
| --- a/internal/equipo/hostedrun/sim_test.go |
| +++ b/internal/equipo/hostedrun/sim_test.go |
| @@ -2,14 +2,17 @@ package hostedrun |
| import ( |
| "encoding/json" |
| + "errors" |
| "fmt" |
| "math/rand" |
| "slices" |
| + "sync/atomic" |
| "testing" |
| "time" |
| "amadan.net/oficina/equipo/internal/equipo/chat" |
| "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| ) |
| // simSeeds is how many seeded runs TestDispatcherSimulation makes. |
| @@ -38,19 +41,48 @@ const simEvery = 2 * Every |
| // than the one before, valid only if the certificate was valid then, |
| // and naming the job's own launch and VM. |
| // |
| -// Whether a step's result counts as certified is Task 24's (report |
| -// acceptance); the simulation only ends steps. Every step ends, and every |
| -// job ends with proof and is settled. A failure names its seed. |
| +// VMs enrol through the store's enrolment steps (Task 22: the code used, |
| +// the controller's admission recorded and required), and a VM's runner |
| +// reports its checks through the production report path (Store.Apply, so |
| +// stepReport), claiming bubblewrap and trusted base checks every time. |
| +// After every report (Task 24): |
| +// |
| +// - no step is certified (kept as sandboxed, or with base checks) by a |
| +// VM whose admission was stale or invalid: the job's latest record, |
| +// read just before the report, was valid, asked for within |
| +// AdmissionFresh, at a time the controller held the certificate |
| +// valid, for the VM and image the controller launched; |
| +// - an uncertified report keeps nothing, taints no runner, and stops |
| +// its job (the step is placed again, once). |
| +// |
| +// A VM's checks take 0 to 4 minutes, so some reports arrive while the |
| +// controller is away (a stale admission) or after a withdrawal. Across all |
| +// seeds, reports are certified, refused on a stale admission and refused |
| +// on a withdrawn one. Every step ends, and every job ends with proof and |
| +// is settled. A failure names its seed. |
| func TestDispatcherSimulation(t *testing.T) { |
| - for seed := int64(1); seed <= simSeeds; seed++ { |
| - t.Run(fmt.Sprintf("seed-%d", seed), func(t *testing.T) { |
| - t.Parallel() |
| - simulate(t, seed) |
| - }) |
| + var tally simTally |
| + t.Run("seeds", func(t *testing.T) { |
| + for seed := int64(1); seed <= simSeeds; seed++ { |
| + t.Run(fmt.Sprintf("seed-%d", seed), func(t *testing.T) { |
| + t.Parallel() |
| + simulate(t, seed, &tally) |
| + }) |
| + } |
| + }) |
| + got := fmt.Sprintf("reports: %d certified, %d not (%d on a stale admission, %d on a withdrawn one)", tally.certified.Load(), tally.uncertified.Load(), tally.stale.Load(), tally.withdrawn.Load()) |
| + if tally.certified.Load() == 0 || tally.stale.Load() == 0 || tally.withdrawn.Load() == 0 { |
| + t.Fatalf("%s: the simulation must exercise each", got) |
| } |
| + t.Log(got) |
| } |
| -func simulate(t *testing.T, seed int64) { |
| +// simTally counts, across seeds, the reports certified and not; stale |
| +// and withdrawn count the uncertified ones whose job's latest admission |
| +// was valid but older than AdmissionFresh, or not valid. |
| +type simTally struct{ certified, uncertified, stale, withdrawn atomic.Int64 } |
| + |
| +func simulate(t *testing.T, seed int64, tally *simTally) { |
| rng := rand.New(rand.NewSource(seed)) |
| r := newRig(t, rng) |
| c := r.ctl |
| @@ -63,6 +95,9 @@ func simulate(t *testing.T, seed int64) { |
| } |
| limits := chat.DefaultHostedLimits |
| checked := map[string]time.Time{} |
| + // reportAt is when each job's checks finish, from when its step was |
| + // first seen on its VM. |
| + reportAt := map[string]time.Time{} |
| runners := 0 |
| for tick := 0; ; tick++ { |
| if tick > 540 { |
| @@ -91,21 +126,28 @@ func simulate(t *testing.T, seed int64) { |
| c.down = outage > 0 |
| c.mu.Unlock() |
| r.pass() |
| - // VMs enrol (Task 22's part), and steps on a VM report. |
| + // VMs enrol (Task 22's store steps), and steps on a VM report |
| + // through the production path. |
| for _, j := range r.liveJobs() { |
| switch j.State { |
| case chat.HostedJobEnrolling: |
| if v := c.vm(j.AttemptID); v != nil && !v.noEnrol && rng.Float64() < 0.7 { |
| runners++ |
| - r.enrol(j.AttemptID, fmt.Sprintf("H%d", runners)) |
| + r.enrolVM(j.AttemptID, fmt.Sprintf("H%d", runners)) |
| } |
| case chat.HostedJobEnrolled: |
| s := r.step(j.StepID) |
| v := c.vm(j.AttemptID) |
| - if s.RunnerID != j.RunnerID || s.State == wire.StepDone || v == nil || !v.alive() || rng.Float64() > 0.35 { |
| + if s.RunnerID != j.RunnerID || s.State == wire.StepDone || v == nil || !v.alive() { |
| continue |
| } |
| - r.exec("UPDATE chat_steps SET state = ?, checks = ? WHERE id = ?", wire.StepDone, wire.ChecksPassed, j.StepID) |
| + if _, ok := reportAt[j.AttemptID]; !ok { |
| + reportAt[j.AttemptID] = r.now.Add(time.Duration(rng.Intn(13)) * simEvery) |
| + } |
| + if r.now.Before(reportAt[j.AttemptID]) { |
| + continue |
| + } |
| + r.checksReport(seed, j, tally) |
| } |
| } |
| r.invariants(seed, limits) |
| @@ -130,6 +172,104 @@ func simulate(t *testing.T, seed int64) { |
| } |
| } |
| +// enrolVM enrols attempt's VM as runner through the store's enrolment |
| +// steps, as the instance's POST /api/hosted/enrol does: the VM's code is |
| +// used, the controller's admission record read (outside the transaction) |
| +// and required to admit the VM, the runner created and bound. A refused |
| +// enrolment leaves the code used and the job enrolling. |
| +func (r *rig) enrolVM(attempt, runner string) { |
| + r.t.Helper() |
| + vm := r.ctl.vm(attempt) |
| + j := r.job(attempt) |
| + if vm == nil || j.LaunchID == "" { |
| + return |
| + } |
| + r.ctl.mu.Lock() |
| + code, ref := vm.q.InstanceCode, string(vm.ref) |
| + r.ctl.mu.Unlock() |
| + var claimed bool |
| + r.must(r.d.G.Transaction(func(tx *gorm.DB) error { |
| + _, err := r.s.HostedClaimCode(tx, code, j.LaunchID, r.now) |
| + claimed = err == nil |
| + if errors.Is(err, chat.ErrForbidden) { |
| + return nil |
| + } |
| + return err |
| + })) |
| + if !claimed { |
| + return |
| + } |
| + a, err := r.ctl.Admission(r.ctx, attempt) |
| + if err != nil { |
| + return |
| + } |
| + r.must(r.d.G.Transaction(func(tx *gorm.DB) error { |
| + _, ok, err := r.s.HostedEnrolAdmit(tx, attempt, j.LaunchID, ref, a, r.now, r.now) |
| + if err != nil || !ok { |
| + return err |
| + } |
| + if err := tx.Exec("INSERT INTO runners(id, person, role, label) VALUES (?, ?, 'worker', ?)", runner, owner, ref).Error; err != nil { |
| + return err |
| + } |
| + return r.s.HostedEnrolBind(tx, attempt, runner, "key-"+runner) |
| + })) |
| + if j := r.job(attempt); j.RunnerID == runner { |
| + r.online(runner) |
| + } |
| +} |
| + |
| +// checksReport has j's runner report its step's checks passed in |
| +// bubblewrap with base checks passed, through Store.Apply, and checks |
| +// the result against the job's admission as it stood just before. |
| +func (r *rig) checksReport(seed int64, j chat.HostedJob, tally *simTally) { |
| + r.t.Helper() |
| + before := r.job(j.AttemptID) |
| + s := r.step(j.StepID) |
| + zero := 0 |
| + rep := wire.StepReport{TaskID: s.TaskID, StepID: j.StepID, Attempt: s.Attempt, State: wire.StepDone, Termination: true, BaseSHA: baseSHA, CandidateSHA: candidateSHA, |
| + Checks: wire.ChecksPassed, Gate: "make ci", ExitCode: &zero, ChecksSandbox: wire.SandboxBubblewrap, BaseChecks: wire.ChecksPassed, BaseChecksSHA: baseSHA, Findings: []wire.Finding{}} |
| + r.frames++ |
| + l := chat.Lease{Runner: chat.RunnerPrincipal{RunnerID: j.RunnerID, Person: owner}, Generation: 1, Process: "p", Protocol: wire.ProtocolHostedRunners, Role: wire.RoleWorker} |
| + r.must(r.s.Apply(r.ctx, l, wire.Frame{ID: fmt.Sprintf("f%d", r.frames), Type: wire.FrameStep}, &rep)) |
| + after := r.step(j.StepID) |
| + if after.ChecksSandbox == wire.SandboxBubblewrap || after.BaseChecksSHA != "" { |
| + tally.certified.Add(1) |
| + at := before.CertCheckedAt |
| + r.ctl.mu.Lock() |
| + v := r.ctl.jobs[j.AttemptID] |
| + launched := v != nil && string(v.ref) == before.VMRef && v.launchID == before.LaunchID && string(v.q.Image) == before.ImageDigest |
| + r.ctl.mu.Unlock() |
| + switch { |
| + case after.State != wire.StepDone || after.ChecksSandbox != wire.SandboxBubblewrap || after.BaseChecksSHA != baseSHA: |
| + r.fail(seed, "%s certified in part: %+v", j.StepID, after) |
| + case !before.CertValid || at == nil: |
| + r.fail(seed, "%s certified by %s with no valid admission", j.StepID, j.AttemptID) |
| + case r.now.Sub(*at) > chat.AdmissionFresh || at.Sub(r.now) > chat.AdmissionFresh: |
| + r.fail(seed, "%s certified by %s on an admission from %v at %v", j.StepID, j.AttemptID, at, r.now) |
| + case !r.ctl.validAt(*at): |
| + r.fail(seed, "%s certified by %s on an admission at %v, when the certificate was withdrawn", j.StepID, j.AttemptID, at) |
| + case !launched: |
| + r.fail(seed, "%s certified by %s on VM %s image %s, which the controller did not launch", j.StepID, j.AttemptID, before.VMRef, before.ImageDigest) |
| + } |
| + return |
| + } |
| + tally.uncertified.Add(1) |
| + switch { |
| + case !before.CertValid: |
| + tally.withdrawn.Add(1) |
| + case before.CertCheckedAt != nil && r.now.Sub(*before.CertCheckedAt) > chat.AdmissionFresh: |
| + tally.stale.Add(1) |
| + } |
| + if after.State == wire.StepDone || after.Checks != "" { |
| + r.fail(seed, "%s kept an uncertified result: %+v", j.StepID, after) |
| + } |
| + var tainted int64 |
| + r.must(r.d.G.Raw("SELECT count(*) FROM runners WHERE id = ? AND tainted_at IS NOT NULL", j.RunnerID).Scan(&tainted).Error) |
| + if got := r.job(j.AttemptID); tainted != 0 || got.State != chat.HostedJobStopping { |
| + r.fail(seed, "%s uncertified: runner tainted %d, job %s %q", j.AttemptID, tainted, got.State, got.StopReason) |
| + } |
| +} |
| + |
| func (r *rig) liveJobs() []chat.HostedJob { |
| r.t.Helper() |
| var rows []chat.HostedJob |
diff --git a/internal/equipo/migrations/0129_hosted_job_admission.sql b/internal/equipo/migrations/0129_hosted_job_admission.sql| new file mode 100644 |
| index 00000000..edaef035 |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0129_hosted_job_admission.sql |
| @@ -0,0 +1,6 @@ |
| +-- Hosted runners slice 2 (Task 24): what certifies a hosted VM's results. |
| +-- image_digest is the image named by the admission that enrolled the VM; |
| +-- admission_json is the latest admission record kept for the job, whole. |
| +-- Two new columns; no existing row changes. |
| +ALTER TABLE hosted_jobs ADD COLUMN image_digest text; |
| +ALTER TABLE hosted_jobs ADD COLUMN admission_json text; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 071a5088..29674461 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -953,3 +953,10 @@ CREATE TABLE hosted_admit_locks (person text, admissions integer, PRIMARY KEY (p |
| -- so a hosted runner's credentials never outlive it. One new column; no |
| -- existing row changes. |
| ALTER TABLE hosted_jobs ADD COLUMN deadline datetime; |
| + |
| +-- Hosted runners slice 2 (Task 24): what certifies a hosted VM's results. |
| +-- image_digest is the image named by the admission that enrolled the VM; |
| +-- admission_json is the latest admission record kept for the job, whole. |
| +-- Two new columns; no existing row changes. |
| +ALTER TABLE hosted_jobs ADD COLUMN image_digest text; |
| +ALTER TABLE hosted_jobs ADD COLUMN admission_json text; |