alta-adopt: keyset prerequisite in runbook; dead processes cut off
README: the shared production keyset (alta keygen, home team-keygen, oficina-id then oficina, the operator key's machine) comes before the CARLOS credential and the Home counts; Paul's steps renumbered. Rehearsal: a process killed at its crash point is cut off at once (journal handle closed, context cancelled), not when its console client's 60 s timeout ends, and every wait on a process is bounded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+149
−49
README.md+45 −18adopt/rehearsal_test.go+104 −31
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 16.847s ok amadan.net/oficina/alta/carlosop 0.034s ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta 0.165s ok amadan.net/oficina/alta/cmd/alta-adopt 16.774s ok amadan.net/oficina/alta/console 0.003s ? amadan.net/oficina/alta/console/fakeconsole [no test files] ok amadan.net/oficina/alta/homeop 0.004s ok amadan.net/oficina/alta/homeop/fakehome 0.057s ok amadan.net/oficina/alta/internal/web 0.136s ok amadan.net/oficina/alta/provision 11.459s === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... go: downloading amadan.net/oficina/home v0.1.1-0.20261116154649-16da7bad9395 go: downloading amadan.net/oficina/home/handoff v0.0.0-20261116154649-16da7bad9395 go: downloading amadan.net/oficina/home/roster v0.0.0-20261116154649-16da7bad9395 go: downloading golang.org/x/sync v0.22.0 ok amadan.net/oficina/home/altacompat 0.568s
diff --git a/README.md b/README.md| index 6232362..8e6d899 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -224,6 +224,24 @@ is a dry run unless given `--apply`. Build it with `make adopt`. |
| ### Before the first run |
| +The shared production keyset comes first, before the CARLOS credential |
| +and the Home counts (critical path step 5; home 101 §5, with its |
| +corrections). Adoption and Alta share one operator signer, installation, |
| +registry and device on both Home roles, so this one keyset is what the |
| +config file carries. |
| + |
| +- **Paul approves one `alta keygen`** (Alta's operator key, the |
| + prefilter and the pins) **and one `home team-keygen -subject |
| + pr_tsoeky4xus2habsdlun2jvzmku`** (Home's side, for Paul's person ref). |
| + One of each: the pins and key Home holds must be the ones in the |
| + config file. |
| +- **The team configuration is applied to `oficina-id`, then to |
| + `oficina`**, in that canaried order: the credential role first, checked, |
| + then the directory. Follow home 101 §5 as corrected there, not an |
| + earlier copy. |
| +- **Paul names the machine that holds the operator key.** `alta-adopt` |
| + runs only there, and the config file and the state database stay there. |
| + |
| - **The config file** (`--config`, mode 0600, Paul's own) holds Alta's |
| operator key, prefilter and pins, `ALTA_DEK`, the directory's |
| provisioning key, the console and account, the state database's path, |
| @@ -273,46 +291,55 @@ run it again if it stops (`status` shows where every run is). |
| ### Paul's steps, in order |
| -1. **Home counts, before initialize.** Run |
| +1. **The shared production keyset** (see the prerequisite above). Approve |
| + the one `alta keygen` and the `home team-keygen -subject |
| + pr_tsoeky4xus2habsdlun2jvzmku`, apply the team configuration to |
| + `oficina-id` and then `oficina`, and name the machine that holds the |
| + operator key. |
| +2. **CARLOS credential.** Run `carlos services create --account oficina |
| + --role admin oficina-adoption`, and pass the result to `alta-adopt` |
| + only on a file descriptor. |
| +3. **Home counts, before initialize.** Run |
| `alta-adopt home-preflight --phase pre-initialize`. It prints eight |
| read-only queries; run each with `carlos db query` against Home's |
| directory and paste the counts. Rerun with `--apply` to record them. |
| -2. **CARLOS preflight.** Run `alta-adopt preflight`. Any code stops the |
| +4. **CARLOS preflight.** Run `alta-adopt preflight`. Any code stops the |
| run; `inherits-<host>` means another instance shares the layer the keys |
| would go to. |
| -3. **Initialize.** Run `alta-adopt initialize --apply` and type the |
| +5. **Initialize.** Run `alta-adopt initialize --apply` and type the |
| attestation. Confirm on |
| [https://oficina.works/operator/confirm](https://oficina.works/operator/confirm) |
| with a fresh passkey in the system browser, then |
| `advance --run <id> --apply`. |
| -4. **Wait out the initialize window: 15 minutes from the confirmation.** |
| +6. **Wait out the initialize window: 15 minutes from the confirmation.** |
| The pre-plan-a preflight refuses (`plan-open`) while it is open. |
| -5. **Home counts, before Plan A.** Run |
| +7. **Home counts, before Plan A.** Run |
| `home-preflight --phase pre-plan-a --apply` with fresh counts. After |
| initialize, `roster_generation` and `roster_operator_receipts` hold one |
| row each; every other table is empty. |
| -6. **Plan A.** Run `plan-a --apply` and type the owner (Paul's own |
| +8. **Plan A.** Run `plan-a --apply` and type the owner (Paul's own |
| address). Confirm on |
| [https://oficina.works/operator/confirm](https://oficina.works/operator/confirm), |
| then on |
| [https://id.oficina.works/operator/confirm](https://id.oficina.works/operator/confirm), |
| retyping the owner. Both pages should show the SQID, the six canonical |
| hosts, "Oficina" and the same 8-hex prefix. Then `advance`. |
| -7. **Configure.** For each app, `configure --app <a>` (dry run) and then |
| +9. **Configure.** For each app, `configure --app <a>` (dry run) and then |
| with `--apply`: one config write and one restart, of that host only. |
| `configure` waits until the app serves agent-access's challenge, then |
| records the after snapshot. |
| -8. **Witness.** Sign in at `https://<app>.oficina.works` in the system |
| - browser, check it works as before, then run `witness --app <a> --apply` |
| - and type the sentence it prints. |
| -9. **Plan B.** Run `activate --apps calendar --apply`, confirm on both |
| - pages, then `advance`. |
| -10. **Test account.** Create a throwaway Oficina ID account. It must |
| +10. **Witness.** Sign in at `https://<app>.oficina.works` in the system |
| + browser, check it works as before, then run `witness --app <a> --apply` |
| + and type the sentence it prints. |
| +11. **Plan B.** Run `activate --apps calendar --apply`, confirm on both |
| + pages, then `advance`. |
| +12. **Test account.** Create a throwaway Oficina ID account. It must |
| already belong to some team other than Oficina: connect refuses to |
| authorize a person with no team (403 `access_denied`), and the |
| - browser sign-in then hangs until cancelled. Sign it in to calendar.oficina.works once. Pick one of |
| - Paul's own calendar events and note its id for `--event`. |
| -11. **Live checks.** Run `live --event <id> --apply` and follow its |
| + browser sign-in then hangs until cancelled. Sign it in to |
| + calendar.oficina.works once. Pick one of Paul's own calendar events |
| + and note its id for `--event`. |
| +13. **Live checks.** Run `live --event <id> --apply` and follow its |
| prompts: sign the test account in to connect; add it to the Oficina |
| team on the Team page, and remove it again; witness both local |
| sign-ins; connect Paul's own account. **Remove the member within 5 |
| @@ -320,9 +347,9 @@ run it again if it stops (`status` shows where every run is). |
| removal, and a token older than its 5-minute life proves nothing (the |
| check is inconclusive and Plan C stays refused). The runner revokes |
| every connection it makes, whatever happens. |
| -12. **Plan C.** Run `activate --apps docs,sheets,slides,calls,memoria |
| +14. **Plan C.** Run `activate --apps docs,sheets,slides,calls,memoria |
| --apply`, confirm on both pages, then `advance`. |
| -13. **Clean up.** `carlos services delete oficina-adoption`, back up the |
| +15. **Clean up.** `carlos services delete oficina-adoption`, back up the |
| state database, and delete the test account if Paul wishes. |
| ### When a step stops |
diff --git a/adopt/rehearsal_test.go b/adopt/rehearsal_test.go| index 6e19600..bee74b0 100644 |
| --- a/adopt/rehearsal_test.go |
| +++ b/adopt/rehearsal_test.go |
| @@ -431,8 +431,10 @@ func (r *rehearsal) activate(apps ...string) { |
| // proc is one alta-adopt process's console client, through a door that |
| // kills the process at its crash point: the request is held for good |
| -// (before) or answered to no one (after), and the process never runs |
| -// another line. |
| +// (before) or answered to no one (after). From then on the door forwards |
| +// nothing, and process.await cuts the process off (its journal handle |
| +// closed, its context cancelled), so nothing it does next, even after |
| +// its client's own timeout, reaches the console or the journal. |
| type proc struct { |
| c *carlosop.Client |
| dead chan struct{} |
| @@ -535,33 +537,73 @@ func (r *rehearsal) classify(req *http.Request, body []byte) (app, kind string) |
| // step runs fn as one alta-adopt process at a time, killed at point the |
| // first time app reaches it, until a process finishes. A dead process is |
| -// left where it died; the next one opens the journal afresh. |
| +// cut off where it died; the next one opens the journal afresh. |
| func (r *rehearsal) step(app string, point crashPoint, fn func(ctx context.Context, c *carlosop.Client, js *Store) error) (deaths int) { |
| r.t.Helper() |
| for { |
| - p := r.newProc(point) |
| - _, js := r.journal() |
| - ctx, cancel := context.WithCancel(context.Background()) |
| - r.cancels = append(r.cancels, cancel) |
| - done := make(chan error, 1) |
| - r.zombies.Add(1) |
| - go func() { |
| - defer r.zombies.Done() |
| - done <- fn(ctx, p.c, js) |
| - }() |
| - select { |
| - case err := <-done: |
| + died, err := r.spawn(point, fn).await() |
| + if !died { |
| if err != nil { |
| r.t.Fatalf("%s: %v", app, err) |
| } |
| return deaths |
| - case <-p.dead: |
| - deaths++ |
| - if deaths > 1 { |
| - r.t.Fatalf("%s died twice", app) |
| - } |
| - r.sawBaseline(app) |
| } |
| + deaths++ |
| + if deaths > 1 { |
| + r.t.Fatalf("%s died twice", app) |
| + } |
| + r.sawBaseline(app) |
| + } |
| +} |
| + |
| +// processLimit bounds how long one process may run before it either |
| +// finishes or dies: a test that hangs fails here, not at the package |
| +// timeout. |
| +const processLimit = time.Minute |
| + |
| +// process is one alta-adopt process: fn on its own console door, journal |
| +// handle and context. |
| +type process struct { |
| + r *rehearsal |
| + p *proc |
| + db *sql.DB |
| + cancel context.CancelFunc |
| + done chan error |
| +} |
| + |
| +func (r *rehearsal) spawn(point crashPoint, fn func(ctx context.Context, c *carlosop.Client, js *Store) error) *process { |
| + x := &process{r: r, p: r.newProc(point), done: make(chan error, 1)} |
| + ps, js := r.journal() |
| + x.db = ps.DB() |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + x.cancel = cancel |
| + r.cancels = append(r.cancels, cancel) |
| + r.zombies.Add(1) |
| + go func() { |
| + defer r.zombies.Done() |
| + x.done <- fn(ctx, x.p.c, js) |
| + }() |
| + return x |
| +} |
| + |
| +// await waits, at most processLimit, for the process to finish (its |
| +// error) or die (died). A process dies while blocked in its console |
| +// request, so it is cut off there and then: its journal handle is closed |
| +// and its context cancelled. Whatever it tries next fails at once, |
| +// whatever the client's own timeout: a write to the journal finds the |
| +// handle closed, and its console door forwards nothing more. |
| +func (x *process) await() (died bool, err error) { |
| + x.r.t.Helper() |
| + select { |
| + case err := <-x.done: |
| + return false, err |
| + case <-x.p.dead: |
| + x.db.Close() |
| + x.cancel() |
| + return true, nil |
| + case <-time.After(processLimit): |
| + x.r.t.Fatalf("a process neither finished nor died within %s", processLimit) |
| + return false, nil |
| } |
| } |
| @@ -986,16 +1028,12 @@ func TestRehearsalCrashAfterEveryAct(t *testing.T) { |
| a, _ := provision.AppBySlug("docs") |
| r.configure(a, noCrash) |
| r.crashed = map[string]bool{} |
| - p := r.newProc(beforePut) |
| - _, js := r.journal() |
| - ctx, cancel := context.WithCancel(context.Background()) |
| - r.cancels = append(r.cancels, cancel) |
| - r.zombies.Add(1) |
| - go func() { |
| - defer r.zombies.Done() |
| - _ = RollbackAgentKeys(ctx, p.c, r.h, js, a, true) |
| - }() |
| - <-p.dead |
| + dying := r.spawn(beforePut, func(ctx context.Context, c *carlosop.Client, js *Store) error { |
| + return RollbackAgentKeys(ctx, c, r.h, js, a, true) |
| + }) |
| + if died, err := dying.await(); !died { |
| + t.Fatalf("the rollback finished (%v) instead of dying before its unset", err) |
| + } |
| r.sawBaseline(a.Slug) |
| keys := AgentKeys(a) |
| r.carlos.SetVar("docs", "", keys[1], "tForeignTeam") |
| @@ -1018,6 +1056,41 @@ func TestRehearsalCrashAfterEveryAct(t *testing.T) { |
| }) |
| } |
| +// A process killed in its PUT stays dead: it is cut off at once, not when |
| +// its console client gives up (60 s), and what it tries afterwards, a |
| +// journal write here, lands nowhere. |
| +func TestRehearsalDeadProcessTouchesNothing(t *testing.T) { |
| + r := newRehearsal(t) |
| + _, version, _ := r.carlos.Layer("docs", "") |
| + keys := AgentKeys(appNamed(t, "docs")) |
| + x := r.spawn(beforePut, func(ctx context.Context, c *carlosop.Client, js *Store) error { |
| + _, err := c.Put(ctx, "docs", carlosop.PutRequest{Set: map[string]string{keys[0]: Issuer, keys[1]: fixtureSQID}, IfVersion: version}) |
| + if err == nil { |
| + return errors.New("the PUT was answered") |
| + } |
| + // Whatever a dead process would do next. |
| + return js.SaveCheck(context.Background(), RequiredLiveChecks[0], "passed") |
| + }) |
| + if died, err := x.await(); !died { |
| + t.Fatalf("the process finished (%v) instead of dying in its PUT", err) |
| + } |
| + select { |
| + case err := <-x.done: |
| + if err == nil { |
| + t.Fatal("the dead process wrote to the journal") |
| + } |
| + case <-time.After(10 * time.Second): |
| + t.Fatal("the dead process was not cut off") |
| + } |
| + var n int |
| + if err := r.ps.DB().QueryRow("SELECT count(*) FROM adopt_checks").Scan(&n); err != nil || n != 0 { |
| + t.Fatalf("journal checks %d (%v)", n, err) |
| + } |
| + if n := r.putsOf("docs"); n != 0 { |
| + t.Fatalf("%d PUTs reached the console", n) |
| + } |
| +} |
| + |
| func sortedCopy(s []string) []string { |
| c := slices.Clone(s) |
| slices.Sort(c) |