Review fixes (oficina/alta #1): owner forgotten while apps park, serving names, owner correction, record tests
Fable's review of b1c508b, CHANGES REQUIRED (narrow), four blockers: 1. provision() deletes the owner's address before returning a park, so an app waiting on a certificate or on Docs' missing /api/team no longer keeps it at rest. The end-state check counts only credential plans that carried an owner (create-team's); the database canary scan stays. 2. Step 10 no longer requires rollout.serving == /api/version: the box's name is carlos ship's release version, the binary's stamp is git describe. It requires the instance awake, not transient, config applied, and both names present; records both (app_version for the evidence, serving for artifact_digest) and notes a difference. README Deploying says how to make them match. 3. The team page offers the owner form whenever the team is not yet at Home, and a plan Home refused can be resubmitted with the corrected address; a refused New team lands on the team page. 4. Record verification is tested: a record signed by another key, and one binding another audience, both fail record-unverified before any console write. Notes: ALTA_CALLS_ZONE checked with time.LoadLocation at start (tzdata embedded); everything Alta signs is back-dated 30 s (homeop.Skew); a request replayed after its window closed parks window-expired instead of failing; the team page shows only codes Alta produces; activation's 40-hex check is one variable (activationVersion) to drop when Home accepts an opaque token; the README records where Alta follows the merged code rather than the design text (account sqid, rollout.serving, mail prefix, app_version, Help).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 files changed,
+412
−52
README.md+38 −5cmd/alta/main.go+8 −0console/client.go+2 −0console/fakeconsole/fakeconsole.go+19 −3homeop/client.go+1 −1homeop/fakehome/fakehome.go+14 −1homeop/protocol.go+6 −0internal/web/app.go+23 −7internal/web/templates/run.html+3 −1internal/web/templates/team.html+4 −3internal/web/web_test.go+33 −0internal/web/words.go+37 −14provision/engine.go+12 −3provision/engine_test.go+4 −2provision/review_test.go+175 −0provision/steps.go+33 −12
CI passed — run details
diff --git a/README.md b/README.md| index fb9484a..0306f22 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -78,21 +78,54 @@ labels and retired hostnames are never reused. |
| reads — `DOCS_SMTP` for Docs — and the relay enabled for Calls, so the |
| CARLOS walks mint per-environment credentials. Alta is given no SMTP or |
| relay value. |
| -6. **DNS and certificates**: `*.<app>.oficina.works` → the deployment, per |
| +6. **Versions**: ship team apps with `carlos ship --version` equal to the |
| + app Makefile's `VERSION` (`git describe --tags --always`) if you want |
| + the box's serving name and `/api/version` to match. Step 10 does not |
| + require it: it records both, uses `/api/version` as the activation's |
| + `app_version` and the box's name for `artifact_digest`, and notes a |
| + difference in the audit. |
| +7. **DNS and certificates**: `*.<app>.oficina.works` → the deployment, per |
| app zone; Alta attaches explicit hosts. |
| -7. **Home**: add `"alta": "<ALTA_ORIGIN>"` as the 8th `HOME_CONSUMERS` |
| +8. **Home**: add `"alta": "<ALTA_ORIGIN>"` as the 8th `HOME_CONSUMERS` |
| entry (credential role); set `HOME_OPERATOR_HTTP` on both roles (from |
| `alta keygen`, with `operator_subject` and, on the credential role, |
| `directory_provisioning_public_key` filled in) beside each role's |
| `HOME_OPERATOR_MATERIAL`; enable the directory's roster endpoint. |
| -8. **The owner** (Till) signs in once at `https://oficina.works`. |
| -9. **Amendment §12 pre-flight**: Paul confirms the production directory has |
| +9. **The owner** (Till) signs in once at `https://oficina.works`. |
| +10. **Amendment §12 pre-flight**: Paul confirms the production directory has |
| never issued a roster generation or consumer record, by typing it on |
| Alta's Initialize page. Alta's first production run is `initialize`. |
| -10. **`lagged`**: per app, `carlos env fork --from lagged --to lagged-team |
| +11. **`lagged`**: per app, `carlos env fork --from lagged --to lagged-team |
| --scope alta`, then rebind each instance with `--scope alta`; create the |
| team in Alta with "Moving a stopgap" ticked. |
| +## Where Alta follows the merged code, not the design text |
| + |
| +Home's `team-provisioning-app.md` is a separate repository; these are |
| +recorded here instead (Fable's rulings on oficina/alta #1): |
| + |
| +- **§3, the console path**: a team credential's doors take the account's |
| + sqid, so the path is `/api/cli/apps/bds/<app>/…`, not |
| + `/api/cli/apps/oficina/<app>/…` (`teamInScope` compares the path to the |
| + credential's own account sqid). |
| +- **§6 step 10 and §7, the serving build**: there is no |
| + `update_report.serving`. The box's report is `status.HostRollout`; the |
| + team role reads it as `rollout` on the `GET /instances` list door |
| + (`?q=<host>`), and `GET /instances/{host}` carries neither. Step 10 |
| + requires the instance awake, not transient, `config_pending` false, and |
| + both `rollout.serving` and `/api/version` present; it does not require |
| + them to be equal. |
| +- **§6 step 0, the mail prefix**: a team credential cannot read an app's |
| + mail declaration. Alta checks a forked environment that already exists |
| + at step 0, and every environment when the walk delivers (step 7, and |
| + the audit), refusing a prefix the app does not read. Deploying step 5 is |
| + the human check. |
| +- **§7, `app_version`**: Home at `82d9388` admits only a 40-hex commit. |
| + Home is changing that to an opaque printable token; until it lands, Alta |
| + keeps the check (`provision/steps.go`, `activationVersion = commit40`), |
| + and dropping it is that one line. |
| +- **§11, Help**: the account menu has no Help items yet (no Colophon page). |
| + |
| ## Developing |
| make ci # vet, gofmt, tests, and the Home compatibility module |
diff --git a/cmd/alta/main.go b/cmd/alta/main.go| index df2a455..0342a00 100644 |
| --- a/cmd/alta/main.go |
| +++ b/cmd/alta/main.go |
| @@ -18,6 +18,7 @@ import ( |
| "os" |
| "strings" |
| "time" |
| + _ "time/tzdata" // ALTA_CALLS_ZONE is checked where the box may have no zoneinfo |
| "amadan.net/oficina/alta/console" |
| "amadan.net/oficina/alta/homeop" |
| @@ -114,6 +115,13 @@ func run(logger *slog.Logger) error { |
| } |
| } |
| + // Calls refuses an invalid IANA zone at boot; refuse it here first, |
| + // before it reaches a team's environment. |
| + if z := env("ALTA_CALLS_ZONE"); z != "" { |
| + if _, err := time.LoadLocation(z); err != nil { |
| + return errors.New("alta: ALTA_CALLS_ZONE is not an IANA zone") |
| + } |
| + } |
| opts, err := rastrillo.Resolve(rastrillo.Options{DBPath: "alta.db", Logger: logger}) |
| if err != nil { |
| return fmt.Errorf("alta: resolve activation: %w", err) |
diff --git a/console/client.go b/console/client.go| index 9b4b47e..3b22fd9 100644 |
| --- a/console/client.go |
| +++ b/console/client.go |
| @@ -268,6 +268,8 @@ type Rollout struct { |
| Serving string `json:"serving"` |
| Awake bool `json:"awake"` |
| ConfigPending bool `json:"config_pending"` |
| + // Transient: the process is starting or stopping. |
| + Transient bool `json:"transient"` |
| } |
| // ListedInstance is one row of GET /instances. |
diff --git a/console/fakeconsole/fakeconsole.go b/console/fakeconsole/fakeconsole.go| index 6372baf..c1e667f 100644 |
| --- a/console/fakeconsole/fakeconsole.go |
| +++ b/console/fakeconsole/fakeconsole.go |
| @@ -39,6 +39,7 @@ type bundle struct { |
| type inst struct { |
| env, app string |
| serving string |
| + asleep bool |
| pending bool |
| restarts int |
| } |
| @@ -73,6 +74,11 @@ type Console struct { |
| DomainPolls int |
| // Roster is GET /api/team's roster word for a roster-mode app. |
| Roster string |
| + // ServingName overrides the box's serving report per app. |
| + ServingName map[string]string |
| + // NoTeamProbe: the roster-mode app serves no /api/team (Docs' main |
| + // today). |
| + NoTeamProbe bool |
| // Requests is every request's method, door and app, for assertions. |
| Requests []string |
| @@ -88,7 +94,7 @@ type Console struct { |
| func New(account, scope string) *Console { |
| priv, _ := ecdh.P256().GenerateKey(rand.Reader) |
| c := &Console{Account: account, Scope: scope, tokens: map[string]string{}, priv: priv, envs: map[string]map[string]*bundle{}, instances: map[string]*inst{}, domains: map[string]*claim{}, |
| - MailPrefix: map[string]string{}, Relay: map[string]bool{}, Versions: map[string]string{}, DomainPolls: 1, Roster: "ok", SecretWrites: map[string]int{}} |
| + MailPrefix: map[string]string{}, Relay: map[string]bool{}, Versions: map[string]string{}, DomainPolls: 1, Roster: "ok", SecretWrites: map[string]int{}, ServingName: map[string]string{}} |
| c.srv = httptest.NewServer(http.HandlerFunc(c.serve)) |
| return c |
| } |
| @@ -248,6 +254,16 @@ func (c *Console) sealCanary(app string) string { |
| return e |
| } |
| +// ServingName, when set, is what a box reports serving for an app, |
| +// instead of the version /api/version answers (carlos ship's release |
| +// version need not be the binary's stamp). |
| +func (c *Console) servingName(i *inst) string { |
| + if n := c.ServingName[i.app]; n != "" { |
| + return n |
| + } |
| + return i.serving |
| +} |
| + |
| // SetDomainState moves a claim's state word. |
| func (c *Console) SetDomainState(host, state string) { |
| c.mu.Lock() |
| @@ -425,7 +441,7 @@ func (c *Console) serve(w http.ResponseWriter, r *http.Request) { |
| } |
| row := map[string]any{"host": h, "app": app, "account": c.Account, "environment": i.env, "health": "Running", "staged_version": i.serving} |
| if i.serving != "" { |
| - row["rollout"] = map[string]any{"installed": i.serving, "serving": i.serving, "awake": true, "config_pending": i.pending} |
| + row["rollout"] = map[string]any{"installed": i.serving, "serving": c.servingName(i), "awake": !i.asleep, "config_pending": i.pending} |
| } |
| rows = append(rows, row) |
| } |
| @@ -544,7 +560,7 @@ func (c *Console) Transport() http.RoundTripper { |
| return nil, fmt.Errorf("fakeconsole: %s does not resolve", r.URL.Host) |
| case r.URL.Path == "/api/version": |
| rec.WriteString(i.serving) |
| - case r.URL.Path == "/api/team" && i.app == "docs": |
| + case r.URL.Path == "/api/team" && i.app == "docs" && !c.NoTeamProbe: |
| b := c.envs[i.app][i.env] |
| _, token := b.vars["DOCS_TEAM_ROSTER_TOKEN"] |
| consumer := b.vars["DOCS_HOME_CONSUMER_ID"].Value |
diff --git a/homeop/client.go b/homeop/client.go| index e8ef761..f800caf 100644 |
| --- a/homeop/client.go |
| +++ b/homeop/client.go |
| @@ -150,7 +150,7 @@ func (c *Client) Inspect(ctx context.Context, role string) (Inspection, Outcome, |
| if err != nil { |
| return Inspection{}, Refused, err |
| } |
| - now := c.now().Unix() |
| + now := c.now().Unix() - Skew |
| ch := InspectChallenge{Role: role, Origin: r.Origin, Installation: r.Installation, Registry: r.Registry, Device: r.Device, Challenge: Token(), Issued: now, Expires: now + RequestLifetime} |
| raw, err := SignInspect(c.Key, ch) |
| if err != nil { |
diff --git a/homeop/fakehome/fakehome.go b/homeop/fakehome/fakehome.go| index 2d7bd22..622a808 100644 |
| --- a/homeop/fakehome/fakehome.go |
| +++ b/homeop/fakehome/fakehome.go |
| @@ -116,6 +116,12 @@ type Home struct { |
| // Calls counts operations by action (committed or not). |
| Calls map[string]int |
| + |
| + // RecordSigner, when set, signs provisioning records instead of the |
| + // directory's provisioning key; RecordAudience, when set, is the |
| + // audience records bind. Both make records Alta must refuse. |
| + RecordSigner *family.Keypair |
| + RecordAudience string |
| } |
| // Pins are what Alta needs to reach a role. |
| @@ -590,7 +596,14 @@ func (h *Home) mutate(x *role, w *plan, a homeop.Authorization, input []byte, he |
| } |
| b := roster.Bindings{Issuer: h.roles[homeop.Credential].origin, Directory: x.origin, Consumer: in.Consumer, App: in.App, Team: in.TeamSQID, Audience: in.Audience} |
| page := roster.Key{ID: "page1", Public: base64.RawURLEncoding.EncodeToString(h.rosterPage.SignPub())} |
| - record, err := roster.SignProvisioning(h.provisioning, homeop.KeyID(h.provisioning.SignPub()), roster.Provisioning{Version: 1, Operation: a.OperationID, Sequence: 1, Bindings: b, Generation: in.Generation, MinEpoch: t.epoch, Keys: []roster.Key{page}}) |
| + signer := h.provisioning |
| + if h.RecordSigner != nil { |
| + signer = h.RecordSigner |
| + } |
| + if h.RecordAudience != "" { |
| + b.Audience = h.RecordAudience |
| + } |
| + record, err := roster.SignProvisioning(signer, homeop.KeyID(signer.SignPub()), roster.Provisioning{Version: 1, Operation: a.OperationID, Sequence: 1, Bindings: b, Generation: in.Generation, MinEpoch: t.epoch, Keys: []roster.Key{page}}) |
| if err != nil { |
| return res, false |
| } |
diff --git a/homeop/protocol.go b/homeop/protocol.go| index 31322b3..acc9f52 100644 |
| --- a/homeop/protocol.go |
| +++ b/homeop/protocol.go |
| @@ -49,6 +49,12 @@ const ( |
| PlanLifetime = 900 |
| WindowLifetime = 900 |
| + // Skew is how far back Alta dates what it signs: Home refuses an |
| + // issued_at in its future, so a few seconds of clock skew must not |
| + // refuse every request. Lifetimes still count from the back-dated |
| + // issue. |
| + Skew = 30 |
| + |
| // Baseline is the only baseline_attestation directory.initialize |
| // accepts. Alta sends it only after Paul types it (§6 step 1). |
| Baseline = "operator-attests-never-provisioned" |
diff --git a/internal/web/app.go b/internal/web/app.go| index aee83c2..07079f1 100644 |
| --- a/internal/web/app.go |
| +++ b/internal/web/app.go |
| @@ -326,6 +326,13 @@ func (a *App) createTeam(w http.ResponseWriter, r *http.Request) { |
| in.Owner = addr.Address |
| } |
| id, err := a.cfg.Engine.CreateTeam(r.Context(), in) |
| + if err != nil && strings.HasPrefix(errorCode(err), "plan-refused-") { |
| + // The label is recorded (never reused) and Home refused the plan: |
| + // the team page is where the owner is corrected and a new plan |
| + // submitted. |
| + http.Redirect(w, r, "/teams/"+in.Label+"?audit="+url.QueryEscape(errorCode(err)), http.StatusSeeOther) |
| + return |
| + } |
| if err != nil { |
| checked := map[string]bool{} |
| for _, s := range in.Apps { |
| @@ -418,7 +425,16 @@ func (a *App) team(w http.ResponseWriter, r *http.Request) { |
| runs, _ := a.cfg.Store.Runs(ctx, t.Label) |
| audit, _ := a.cfg.Store.AuditLog(ctx, t.Label, 40) |
| _, holdsOwner, _ := a.cfg.Store.Owner(ctx, t.Label) |
| - a.render(w, r, http.StatusOK, "team", page{Title: t.Name, Context: t.Label, Notice: describe(r.URL.Query().Get("audit")), |
| + notice := "" |
| + if code := r.URL.Query().Get("audit"); knownCode(code) { |
| + notice = describe(code) |
| + if app := r.URL.Query().Get("app"); app != "" { |
| + if spec, ok := provision.AppBySlug(app); ok { |
| + notice += " (" + spec.Name + ")" |
| + } |
| + } |
| + } |
| + a.render(w, r, http.StatusOK, "team", page{Title: t.Name, Context: t.Label, Notice: notice, |
| Data: map[string]any{"Team": t, "Apps": a.appViews(ctx, t, apps), "Addable": addable, "Runs": runs, "Audit": audit, "HoldsOwner": holdsOwner, "Seeded": t.TeamSQID != ""}}) |
| } |
| @@ -469,19 +485,19 @@ func (a *App) audit(w http.ResponseWriter, r *http.Request) { |
| if !ok { |
| return |
| } |
| - code := "audit-ok" |
| - for app, st := range t.Apps { |
| - if st != "active" { |
| + code, failed := "audit-ok", "" |
| + for _, app := range provision.Slugs() { |
| + if t.Apps[app] != "active" { |
| continue |
| } |
| spec, _ := provision.AppBySlug(app) |
| if err := a.cfg.Engine.AuditEnvironment(r.Context(), t.Label, spec); err != nil { |
| - code = errorCode(err) + "-" + app |
| + code, failed = errorCode(err), app |
| break |
| } |
| } |
| - a.cfg.Store.Audit(r.Context(), 0, t.Label, "", "audit", code) |
| - http.Redirect(w, r, "/teams/"+t.Label+"?audit="+url.QueryEscape(code), http.StatusSeeOther) |
| + a.cfg.Store.Audit(r.Context(), 0, t.Label, failed, "audit", code) |
| + http.Redirect(w, r, "/teams/"+t.Label+"?audit="+url.QueryEscape(code)+"&app="+url.QueryEscape(failed), http.StatusSeeOther) |
| } |
| func (a *App) retireForm(w http.ResponseWriter, r *http.Request) { |
diff --git a/internal/web/templates/run.html b/internal/web/templates/run.html| index c740c7d..a4b2a9c 100644 |
| --- a/internal/web/templates/run.html |
| +++ b/internal/web/templates/run.html |
| @@ -32,7 +32,9 @@ |
| <section class="alta-actions"> |
| {{if .Data.Live}} |
| <form method="post" action="/runs/{{$run.ID}}/advance"><button type="submit" rst-btn="primary">Resume</button></form> |
| - {{if or (eq $run.Code "plan-expired") (eq $run.Code "plan-refused-credential")}}<form method="post" action="/runs/{{$run.ID}}/plan"><button type="submit" rst-btn>Submit a new plan</button></form>{{end}} |
| + {{end}} |
| + {{if or (eq $run.Code "plan-expired") (eq $run.Code "plan-refused-credential") (eq $run.Code "plan-refused-directory")}}<form method="post" action="/runs/{{$run.ID}}/plan"><button type="submit" rst-btn>Submit a new plan</button></form>{{end}} |
| + {{if .Data.Live}} |
| {{if and .Data.Team (or (eq $run.Code "window-expired") (eq $run.Code "window-closed"))}}<form method="post" action="/teams/{{$run.Label}}/apps"><button type="submit" rst-btn>Continue under a new plan</button></form>{{end}} |
| {{end}} |
| {{with .Data.Team}}<a rst-btn href="/teams/{{.Label}}">Team</a>{{end}} |
diff --git a/internal/web/templates/team.html b/internal/web/templates/team.html| index 3439004..9aefd7f 100644 |
| --- a/internal/web/templates/team.html |
| +++ b/internal/web/templates/team.html |
| @@ -27,13 +27,14 @@ |
| </form> |
| </section> |
| {{end}} |
| -{{if not .Data.HoldsOwner}} |
| +{{if or (not .Data.Seeded) (not .Data.HoldsOwner)}} |
| <section class="alta-box"> |
| <h2>Owner's address</h2> |
| - <p>Alta deleted the owner's address once every allowlist was written. An app that needs it again (a stopgap allowlist edit) asks for it here; Alta deletes it again once written.</p> |
| + {{if not .Data.Seeded}}<p>The team is not yet at Home. If Home refused the owner (a mistyped address, or someone who has not signed in at oficina.works), correct it here, then continue under a new plan. The label stays this team's.</p> |
| + {{else}}<p>Alta deleted the owner's address once every allowlist was written. An app that needs it again (a stopgap allowlist edit) asks for it here; Alta deletes it again once written.</p>{{end}} |
| <form method="post" action="/teams/{{$t.Label}}/owner"> |
| {{template "field" dict "ID" "owner" "Name" "owner" "Label" "Owner email" "Type" "email" "Required" true "Autocomplete" "off"}} |
| - <button type="submit" rst-btn>Hold it until written</button> |
| + <button type="submit" rst-btn>{{if .Data.Seeded}}Hold it until written{{else}}Use this address{{end}}</button> |
| </form> |
| </section> |
| {{end}} |
diff --git a/internal/web/web_test.go b/internal/web/web_test.go| index 6a19bea..7b5c254 100644 |
| --- a/internal/web/web_test.go |
| +++ b/internal/web/web_test.go |
| @@ -269,3 +269,36 @@ func mustInt(t *testing.T, s string) int64 { |
| } |
| return n |
| } |
| + |
| +// Fable's review, blocker 3: an owner Home refuses leaves the label |
| +// recorded; the team page offers the owner form while the team is not |
| +// yet at Home, even though Alta still holds the (wrong) address. |
| +func TestRefusedOwnerLeadsToTheOwnerForm(t *testing.T) { |
| + f := newFixture(t) |
| + f.signIn(operator) |
| + w := f.do("POST", "/initialize", url.Values{"attestation": {provision.InitializeAttestation}}, sameOrigin) |
| + _ = f.home.Confirm(homeop.Directory, "") |
| + _ = f.engine.Advance(context.Background(), mustInt(t, strings.TrimPrefix(w.Header().Get("Location"), "/runs/"))) |
| + f.now = f.now.Add(homeop.WindowLifetime * time.Second) |
| + w = f.do("POST", "/teams", url.Values{"label": {"lagged"}, "name": {"Lagged"}, "owner": {"typo@lagged.test"}, "app": {"sheets"}}, sameOrigin) |
| + if w.Code != 303 || !strings.HasPrefix(w.Header().Get("Location"), "/teams/lagged?audit=plan-refused-credential") { |
| + t.Fatalf("refused owner: %d %s", w.Code, w.Header().Get("Location")) |
| + } |
| + page := f.do("GET", w.Header().Get("Location"), nil, nil).Body.String() |
| + if !strings.Contains(page, `action="/teams/lagged/owner"`) || !strings.Contains(page, "Has the owner signed in") { |
| + t.Fatal("no owner form for an unseeded team") |
| + } |
| + if strings.Contains(page, "typo@lagged.test") { |
| + t.Fatal("the held address is shown") |
| + } |
| + if w := f.do("POST", "/teams/lagged/owner", url.Values{"owner": {owner}}, sameOrigin); w.Code != 303 { |
| + t.Fatalf("retype: %d", w.Code) |
| + } |
| + if got, _, _ := f.store.Owner(context.Background(), "lagged"); got != owner { |
| + t.Fatal("retyped owner not held") |
| + } |
| + // A code Alta never produced is not shown as if Alta said it. |
| + if page := f.do("GET", "/teams/lagged?audit=Your+account+is+suspended", nil, nil).Body.String(); strings.Contains(page, "suspended") { |
| + t.Fatal("an arbitrary audit code was reflected") |
| + } |
| +} |
diff --git a/internal/web/words.go b/internal/web/words.go| index e1847e0..6984aef 100644 |
| --- a/internal/web/words.go |
| +++ b/internal/web/words.go |
| @@ -1,11 +1,17 @@ |
| package web |
| -import "strings" |
| +import ( |
| + "strings" |
| + |
| + "amadan.net/oficina/alta/provision" |
| +) |
| // Every state the engine records is a fixed code; this is the one place |
| // they become words. An unknown code is shown as itself, which is honest |
| // and greppable. |
| var words = map[string]string{ |
| + "audit-ok": "Every environment holds exactly its recipe", |
| + "instance-waking": "The instance is starting", |
| "awaiting-confirm": "Waiting for you to confirm on Home", |
| "awaiting-confirm-directory": "Waiting for you to confirm on oficina.works", |
| "awaiting-confirm-credential": "Waiting for you to confirm on id.oficina.works", |
| @@ -60,7 +66,7 @@ var words = map[string]string{ |
| "attestation-mismatch": "Type the sentence exactly to confirm", |
| "already-initialized": "Home's directory is already initialized", |
| "initialized-elsewhere": "Home's directory was initialized by something other than Alta", |
| - "plan-refused-credential": "Home refused the plan. Has the owner signed in at oficina.works?", |
| + "plan-refused-credential": "Home refused the plan. Has the owner signed in at oficina.works? Correct the address on the team page; the directory keeps the refused plan pending for up to 15 minutes, so a new plan waits for that.", |
| "plan-refused-directory": "Home's directory refused the plan", |
| "stream-diverged": "Home's operator stream moved without Alta", |
| "use-add-apps": "The team exists: continue with a new plan instead", |
| @@ -77,6 +83,34 @@ var words = map[string]string{ |
| "no-secrets-pubkey": "The console gave no key to seal secrets to", |
| } |
| +var prefixes = map[string]string{ |
| + "mail-prefix-": "Mail is declared under a prefix this app does not read: ", |
| + "no-credential-": "No team credential for ", |
| + "environment-exists-": "An environment of that name already exists for ", |
| + "fork-missing-": "No forked environment for ", |
| + "instance-bound-elsewhere-": "The instance is bound to another environment: ", |
| + "console-": "The console did not answer for ", |
| + "home-": "Home: ", |
| + "domain-slow-": "Over 30 minutes and still ", |
| + "roster-": "The app's roster says ", |
| + "plan-": "Plan: ", |
| +} |
| + |
| +// knownCode admits only codes Alta itself produces, so a code typed into |
| +// a URL is never shown as if Alta had said it. |
| +func knownCode(code string) bool { |
| + if _, ok := words[code]; ok { |
| + return true |
| + } |
| + for _, p := range []string{"mail-prefix-", "no-credential-", "environment-exists-", "fork-missing-", "instance-bound-elsewhere-", "console-"} { |
| + if strings.HasPrefix(code, p) { |
| + _, ok := provision.AppBySlug(strings.TrimPrefix(code, p)) |
| + return ok |
| + } |
| + } |
| + return false |
| +} |
| + |
| func describe(code string) string { |
| if code == "" { |
| return "" |
| @@ -84,18 +118,7 @@ func describe(code string) string { |
| if w, ok := words[code]; ok { |
| return w |
| } |
| - for prefix, w := range map[string]string{ |
| - "mail-prefix-": "Mail is declared under a prefix this app does not read: ", |
| - "no-credential-": "No team credential for ", |
| - "environment-exists-": "An environment of that name already exists for ", |
| - "fork-missing-": "No forked environment for ", |
| - "instance-bound-elsewhere-": "The instance is bound to another environment: ", |
| - "console-": "The console did not answer for ", |
| - "home-": "Home: ", |
| - "domain-slow-": "Over 30 minutes and still ", |
| - "roster-": "The app's roster says ", |
| - "plan-": "Plan: ", |
| - } { |
| + for prefix, w := range prefixes { |
| if strings.HasPrefix(code, prefix) { |
| return w + strings.TrimPrefix(code, prefix) |
| } |
diff --git a/provision/engine.go b/provision/engine.go| index 33822d1..6e721dd 100644 |
| --- a/provision/engine.go |
| +++ b/provision/engine.go |
| @@ -294,7 +294,10 @@ func (e *Engine) Resubmit(ctx context.Context, runID int64) error { |
| if err != nil { |
| return err |
| } |
| - if r.State == "done" || r.State == "superseded" || r.State == "failed" { |
| + // A run Home refused at plan time (an owner who never signed in, say) |
| + // takes a new plan once Paul has corrected what Home refused. |
| + refused := r.State == "failed" && strings.HasPrefix(r.Code, "plan-refused-") |
| + if r.State == "done" || r.State == "superseded" || (r.State == "failed" && !refused) { |
| return fail("run-finished") |
| } |
| name, owner := "", "" |
| @@ -373,7 +376,7 @@ func (e *Engine) preflight(ctx context.Context, label, env string, forked bool, |
| // the owner; Home keeps its own copy and Paul confirms that copy. |
| func (e *Engine) submitPlans(ctx context.Context, runID int64, label, name, owner, kind string, apps []string) error { |
| planID := homeop.Token() |
| - issued := e.now() |
| + issued := e.now().Add(-homeop.Skew * time.Second) |
| roles := []string{homeop.Directory, homeop.Credential} |
| if kind == homeop.KindInitialize { |
| roles = roles[:1] |
| @@ -680,7 +683,7 @@ func (e *Engine) signAndSend(ctx context.Context, s opSpec) (homeop.Result, erro |
| if err != nil { |
| return homeop.Result{}, err |
| } |
| - now := e.now().Unix() |
| + now := e.now().Unix() - homeop.Skew |
| a.Sequence, a.Previous, a.JournalSequence = seq+1, head, journal |
| a.OperationID, a.Action = homeop.Token(), s.action |
| a.Issued, a.Expires = now, now+homeop.RequestLifetime |
| @@ -725,6 +728,12 @@ func (e *Engine) signAndSend(ctx context.Context, s opSpec) (homeop.Result, erro |
| return homeop.Result{}, errResync |
| } |
| st.Audit(ctx, 0, s.label, s.app, "home-refused", s.action) |
| + if ins.OpenPlan == "" || ins.WindowExpires <= e.now().Unix() { |
| + // No window: a request whose answer was lost, replayed after |
| + // the window closed, found never committed and re-signed. Not |
| + // Home refusing the operation, so not a failure. |
| + return homeop.Result{}, park("window-expired") |
| + } |
| return homeop.Result{}, errOpRefused |
| default: |
| // Unavailable or lost: the request may have committed. Only an |
diff --git a/provision/engine_test.go b/provision/engine_test.go| index 6da9812..51f3868 100644 |
| --- a/provision/engine_test.go |
| +++ b/provision/engine_test.go |
| @@ -76,9 +76,11 @@ func checkEndState(t *testing.T, h *harness) { |
| if n != 0 { |
| t.Fatal("owner-seed request survives step 13") |
| } |
| - _ = h.store.DB().QueryRow("SELECT count(*) FROM plan_submissions WHERE role='credential' AND sealed_plan IS NOT NULL").Scan(&n) |
| + // Only a create-team plan's credential half carries the owner; an |
| + // add-apps plan carries none and may stay until it expires. |
| + _ = h.store.DB().QueryRow("SELECT count(*) FROM plan_submissions WHERE role='credential' AND sealed_plan IS NOT NULL AND plan_id IN (SELECT plan_id FROM runs WHERE kind='create-team')").Scan(&n) |
| if n != 0 { |
| - t.Fatal("credential plan survives step 13") |
| + t.Fatal("a credential plan carrying the owner survives step 13") |
| } |
| _, _ = h.store.DB().Exec("PRAGMA wal_checkpoint(TRUNCATE)") |
| for _, needle := range []string{ownerCanary, "fakeconsole", "PLATFORM-VALUE-CANARY", "lagged.test"} { |
diff --git a/provision/review_test.go b/provision/review_test.go| new file mode 100644 |
| index 0000000..5c028cd |
| --- /dev/null |
| +++ b/provision/review_test.go |
| @@ -0,0 +1,175 @@ |
| +package provision |
| + |
| +import ( |
| + "errors" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/alta/homeop" |
| + family "amadan.net/rastrillo/rastrillo/crypto" |
| +) |
| + |
| +// Tests added for Fable's review of b1c508b (oficina/alta #1). |
| + |
| +// Blocker 1: the address goes once the seed has committed and every |
| +// allowlist is written, even while an app is still parked — here Docs, |
| +// waiting on a /api/team that Docs on main does not serve. |
| +func TestOwnerForgottenWhileAnAppIsParked(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + h.con.NoTeamProbe = true |
| + e := h.engine(nil) |
| + run := h.createLagged(e) |
| + r := h.drive(e, run, 40) |
| + if r.State != "parked" { |
| + t.Fatalf("run %s %s", r.State, r.Code) |
| + } |
| + if st, _, _ := h.store.Step(h.ctx(), "lagged", "docs", StepVerify); st.Code != "no-readiness-probe" { |
| + t.Fatalf("docs verify %s %s", st.State, st.Code) |
| + } |
| + var n int |
| + for q, what := range map[string]string{ |
| + "SELECT count(*) FROM owner_inputs": "owner input", |
| + "SELECT count(*) FROM operator_requests WHERE action='credential.owner-seed'": "owner-seed request", |
| + "SELECT count(*) FROM plan_submissions WHERE role='credential' AND sealed_plan IS NOT NULL AND plan_id IN (SELECT plan_id FROM runs WHERE kind='create-team')": "credential plan", |
| + } { |
| + if err := h.store.DB().QueryRow(q).Scan(&n); err != nil || n != 0 { |
| + t.Fatalf("%s kept while Docs is parked (%d, %v)", what, n, err) |
| + } |
| + } |
| + _, _ = h.store.DB().Exec("PRAGMA wal_checkpoint(TRUNCATE)") |
| + if h.scan(ownerCanary) { |
| + t.Fatal("owner address in Alta's database files") |
| + } |
| + // The other five finished: their allowlists hold the owner. |
| + vars, _, _ := h.con.Env("sheets", "lagged") |
| + if vars["SHEETS_OWNERS"].Value != ownerCanary { |
| + t.Fatal("sheets allowlist not written") |
| + } |
| +} |
| + |
| +// Blocker 2: the box's serving name (carlos ship's release version) and |
| +// /api/version (the binary's git describe) need not agree. Step 10 records |
| +// both and notes a difference; activation reads app_version from |
| +// /api/version and artifact_digest from the box's name. |
| +func TestServingNamesMayDiffer(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + for _, a := range allApps { |
| + h.con.ServingName[a] = "v7" |
| + } |
| + e := h.engine(nil) |
| + run := h.createLagged(e) |
| + if r := h.drive(e, run, 40); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + d, _, _ := h.store.Done(h.ctx(), "lagged", "docs", StepServing) |
| + if str(d, "serving") != "v7" || str(d, "app_version") != h.con.Versions["docs"] || d["names_differ"] != true { |
| + t.Fatalf("serving step %v", d) |
| + } |
| + if h.home.InstanceState(ConsumerID("lagged", "docs")) != "live" { |
| + t.Fatal("docs not activated") |
| + } |
| +} |
| + |
| +// Blocker 3: a mistyped owner burns the label, and the team page's owner |
| +// form and a new plan bring it back. |
| +func TestMistypedOwnerIsCorrectedUnderTheSameLabel(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + e := h.engine(nil) |
| + _, err := e.CreateTeam(h.ctx(), NewTeam{Label: "lagged", Name: "Lagged", Owner: "til-typo@lagged.test", Apps: []string{"sheets"}}) |
| + var fl *Fail |
| + if !errors.As(err, &fl) || fl.Code != "plan-refused-credential" { |
| + t.Fatalf("typo: %v", err) |
| + } |
| + runs, _ := h.store.Runs(h.ctx(), "lagged") |
| + if len(runs) != 1 || runs[0].State != "failed" { |
| + t.Fatalf("runs %+v", runs) |
| + } |
| + // Home's directory accepted the first plan's half and keeps it |
| + // pending until it expires; a new plan waits that out (Home answers |
| + // 409 meanwhile, and Alta retries the signed plan). |
| + h.tick(homeop.PlanLifetime * time.Second) |
| + if err := h.store.SetOwner(h.ctx(), "lagged", ownerCanary); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := e.Resubmit(h.ctx(), runs[0].ID); err != nil { |
| + t.Fatalf("resubmit: %v", err) |
| + } |
| + h.confirm(homeop.KindCreateTeam) |
| + if r := h.drive(e, runs[0].ID, 30); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + if _, _, ok := h.home.Team("lagged"); !ok { |
| + t.Fatal("no team at Home") |
| + } |
| +} |
| + |
| +// Blocker 4: a record that does not verify under the pinned provisioning |
| +// key, or binds anything but what Alta asked for, is refused before any |
| +// environment write. |
| +func TestRecordVerification(t *testing.T) { |
| + for name, spoil := range map[string]func(*harness){ |
| + "another signing key": func(h *harness) { h.home.RecordSigner, _ = family.Generate() }, |
| + "another audience": func(h *harness) { h.home.RecordAudience = "https://other.docs.oficina.works" }, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + spoil(h) |
| + e := h.engine(nil) |
| + run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "lagged", Name: "Lagged", Owner: ownerCanary, Apps: []string{"docs"}}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h.confirm(homeop.KindCreateTeam) |
| + r := h.drive(e, run, 10) |
| + if r.State != "failed" || r.Code != "record-unverified" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + if _, _, ok := h.con.Env("docs", "lagged"); ok { |
| + t.Fatal("an environment was written from an unverified record") |
| + } |
| + for _, req := range h.con.Requests { |
| + if strings.HasPrefix(req, "PUT ") { |
| + t.Fatalf("console write %q", req) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A request whose answer never came back, replayed after the window |
| +// closed and found never committed, parks for a new plan; it is not a |
| +// failure. |
| +func TestUnansweredRequestAfterTheWindowParks(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + down := true |
| + h.home.Outage = func(a string) bool { return down && a == homeop.CredentialRegister } |
| + e := h.engine(nil) |
| + run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "lagged", Name: "Lagged", Owner: ownerCanary, Apps: []string{"sheets"}}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h.confirm(homeop.KindCreateTeam) |
| + _ = e.Advance(h.ctx(), run) |
| + h.tick(homeop.WindowLifetime * time.Second) |
| + down = false |
| + _ = e.Advance(h.ctx(), run) |
| + r, _ := h.store.Run(h.ctx(), run) |
| + st, _, _ := h.store.Step(h.ctx(), "lagged", "sheets", StepRegister) |
| + if r.State != "parked" || st.Code != "window-expired" { |
| + t.Fatalf("run %s %s, register %s %s", r.State, r.Code, st.State, st.Code) |
| + } |
| + next, err := e.AddApps(h.ctx(), "lagged", []string{"sheets"}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h.confirm(homeop.KindAddApps) |
| + if r := h.drive(e, next, 30); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| +} |
diff --git a/provision/steps.go b/provision/steps.go| index c1f505c..843878b 100644 |
| --- a/provision/steps.go |
| +++ b/provision/steps.go |
| @@ -111,10 +111,13 @@ func (e *Engine) provision(ctx context.Context, p *pass) error { |
| } |
| } |
| } |
| - if first != nil { |
| - return first |
| + // The address goes once the seed has committed and every allowlist is |
| + // written, whatever else is still parked: an app waiting on a |
| + // certificate or a roster must not keep it at rest. |
| + if err := e.forgetOwnerWhenWritten(ctx, p); err != nil { |
| + return err |
| } |
| - return e.forgetOwnerWhenWritten(ctx, p) |
| + return first |
| } |
| func (e *Engine) appPipeline(ctx context.Context, p *pass, app App) error { |
| @@ -634,21 +637,32 @@ func (e *Engine) stepServing(ctx context.Context, p *pass, app App) error { |
| _ = e.cfg.Store.SetStep(ctx, p.run.Label, app.Slug, "restart", "done", "", map[string]any{"at": e.now().Unix()}) |
| return park("restarting") |
| } |
| + // The box's report: awake, not starting or stopping, its config |
| + // applied, and naming the build it runs. |
| + if row.Rollout == nil || row.Rollout.Serving == "" { |
| + return park("awaiting-box-report") |
| + } |
| + if !row.Rollout.Awake || row.Rollout.Transient { |
| + return park("instance-waking") |
| + } |
| status, body, err := e.get(ctx, PublicOrigin(p.run.Label, app.Slug)+"/api/version") |
| if err != nil || status != http.StatusOK { |
| return park("version-unreachable") |
| } |
| version := strings.TrimSpace(string(body)) |
| - if version == "" || version == "dev" { |
| + if version == "" { |
| return park("version-unstamped") |
| } |
| - if row.Rollout == nil || row.Rollout.Serving == "" { |
| - return park("awaiting-box-report") |
| - } |
| + // The two names need not agree: the box's is the release version |
| + // `carlos ship` recorded, /api/version is the binary's stamp (git |
| + // describe). Both are recorded — app_version for the evidence, |
| + // serving for artifact_digest — and a difference is only noted. |
| + data := map[string]any{"app_version": version, "serving": row.Rollout.Serving} |
| if row.Rollout.Serving != version { |
| - return park("serving-disagrees") |
| + data["names_differ"] = true |
| + e.cfg.Store.Audit(ctx, p.run.ID, p.run.Label, app.Slug, "serving-names-differ", "") |
| } |
| - return e.record(ctx, p, app.Slug, StepServing, map[string]any{"app_version": version, "serving": row.Rollout.Serving}) |
| + return e.record(ctx, p, app.Slug, StepServing, data) |
| } |
| // ---- steps 11 and 12: verify and activate (roster-mode apps) ---- |
| @@ -672,7 +686,7 @@ func (e *Engine) stepVerify(ctx context.Context, p *pass, app App) error { |
| if err != nil { |
| return err |
| } |
| - issued := now |
| + issued := now - homeop.Skew |
| // A new attempt each time: one whose expiry passed is replaced at |
| // Home by the next verify, never renewed. |
| res, err := e.op(ctx, opSpec{role: homeop.Directory, action: homeop.DirectoryVerify, label: p.run.Label, app: app.Slug, purpose: "verify", |
| @@ -715,6 +729,13 @@ func artifactDigest(serving string) string { |
| return base64.RawURLEncoding.EncodeToString(s[:]) |
| } |
| +// activationVersion is the app_version Home's directory.activate-consumer |
| +// admits. Home at 82d9388 takes only a 40-hex commit |
| +// (verification.go version()); once Home accepts an opaque observed |
| +// token, this line becomes `var activationVersion = func(s string) bool |
| +// { return s != "" }` and nothing else changes. |
| +var activationVersion = commit40 |
| + |
| func commit40(s string) bool { |
| if len(s) != 40 { |
| return false |
| @@ -750,13 +771,13 @@ func (e *Engine) stepActivate(ctx context.Context, p *pass, app App) error { |
| return park("attempt-expired") |
| } |
| version := str(sv, "app_version") |
| - if !commit40(version) { |
| + if !activationVersion(version) { |
| return park("version-not-commit") |
| } |
| ev := homeop.ActivationEvidence{Version: 1, Policy: homeop.ActivationPolicy, Attempt: str(v, "attempt"), Consumer: ConsumerID(label, app.Slug), TeamSQID: p.team.TeamSQID, App: app.Slug, |
| Audience: PublicOrigin(label, app.Slug), Generation: str(cd, "generation"), RecordSequence: 1, RecordDigest: str(cd, "record_digest"), Epoch: num(cd, "epoch"), Owner: p.team.OwnerRef, |
| AppVersion: version, ArtifactDigest: artifactDigest(str(sv, "serving")), EnvironmentBinding: str(envd, "binding"), ManifestDigest: str(reg, "manifest_digest"), |
| - AliasHost: PublicHost(label, app.Slug), Started: num(v, "issued_at"), Completed: now} |
| + AliasHost: PublicHost(label, app.Slug), Started: num(v, "issued_at"), Completed: now - homeop.Skew} |
| _, err = e.op(ctx, opSpec{role: homeop.Directory, action: homeop.DirectoryActivate, label: label, app: app.Slug, purpose: "activate", reuse: true, |
| build: func(b homeop.InputBase) any { return homeop.ActivationInput{InputBase: b, Evidence: ev} }}) |
| if errors.Is(err, errOpRefused) { |