Sheets is a roster-mode app: its team recipe, and verify reuses a live attempt
Sheets' team mode (oficina/sheets #52, team-mode @ b0264ff, internal/sheets/team_config.go and auth.go): Roster true, the five SHEETS_TEAM_* keys built as Docs' are (one teamKeys helper for both): _ID, _DIRECTORY_ORIGIN, _PROVISIONING_BASE64 and _OPERATOR_KEYS_BASE64 SET, and _ROSTER_TOKEN Home's bearer, sealed and fetched by exact replay (GENERATED, as DOCS_TEAM_ROSTER_TOKEN). SHEETS_OWNERS is gone: Sheets needs it only without team configuration. SHEETS_DEK stays GENERATED. Step 11 verifies Sheets through its GET /api/team, Docs' shape. TestRosterRecipes pins both recipes' exact names; the fake console serves /api/team for both; the end-to-end run, the crash suite and homecompat (Home's real engine) now activate Sheets too. Two roster apps in one pass exposed a bug the lost-answer test now catches: Docs' verify answer lost, Sheets' request resyncing the stream and so committing Docs' verify, then Docs signing a second verify that Home refuses while the first attempt lives (verify-refused). Step 11 now replays a held verify and uses its attempt while it lives; only an expired one is replaced by a new verify.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+106
−26
console/fakeconsole/fakeconsole.go+5 −3homecompat/compat_test.go+4 −1provision/apps.go+21 −8provision/apps_test.go+46 −0provision/review_test.go+9 −6provision/steps.go+21 −8
CI passed — run details
diff --git a/console/fakeconsole/fakeconsole.go b/console/fakeconsole/fakeconsole.go| index 502d6a5..9760e88 100644 |
| --- a/console/fakeconsole/fakeconsole.go |
| +++ b/console/fakeconsole/fakeconsole.go |
| @@ -576,10 +576,12 @@ func (c *Console) Transport() http.RoundTripper { |
| } else { |
| rec.WriteString(i.serving) |
| } |
| - case r.URL.Path == "/api/team" && i.app == "docs" && !c.NoTeamProbe: |
| + case r.URL.Path == "/api/team" && (i.app == "docs" || i.app == "sheets") && !c.NoTeamProbe: |
| + // The roster-mode apps: Docs, and Sheets since its team mode. |
| + p := strings.ToUpper(i.app) |
| b := c.envs[i.app][i.env] |
| - _, token := b.vars["DOCS_TEAM_ROSTER_TOKEN"] |
| - consumer := b.vars["DOCS_HOME_CONSUMER_ID"].Value |
| + _, token := b.vars[p+"_TEAM_ROSTER_TOKEN"] |
| + consumer := b.vars[p+"_HOME_CONSUMER_ID"].Value |
| roster := c.Roster |
| if !token { |
| roster = "unknown" |
diff --git a/homecompat/compat_test.go b/homecompat/compat_test.go| index 03b1533..d522fad 100644 |
| --- a/homecompat/compat_test.go |
| +++ b/homecompat/compat_test.go |
| @@ -373,9 +373,12 @@ func TestAltaAgainstHomesRealOperator(t *testing.T) { |
| if err := r.home.dirDB.QueryRow("SELECT state FROM team_instances WHERE consumer_id='lagged-docs'").Scan(&state); err != nil || state != "live" { |
| t.Fatalf("docs at the directory: %q %v", state, err) |
| } |
| - if err := r.home.dirDB.QueryRow("SELECT state FROM team_instances WHERE consumer_id='lagged-sheets'").Scan(&state); err != nil || state != "pending" { |
| + if err := r.home.dirDB.QueryRow("SELECT state FROM team_instances WHERE consumer_id='lagged-sheets'").Scan(&state); err != nil || state != "live" { |
| t.Fatalf("sheets at the directory: %q %v", state, err) |
| } |
| + if err := r.home.dirDB.QueryRow("SELECT state FROM team_instances WHERE consumer_id='lagged-slides'").Scan(&state); err != nil || state != "pending" { |
| + t.Fatalf("slides at the directory: %q %v", state, err) |
| + } |
| var n int |
| _ = r.home.credDB.QueryRow("SELECT count(*) FROM consumers WHERE state='active'").Scan(&n) |
| if n != 6 { |
diff --git a/provision/apps.go b/provision/apps.go| index 2c3ae6e..74175ec 100644 |
| --- a/provision/apps.go |
| +++ b/provision/apps.go |
| @@ -44,7 +44,7 @@ type App struct { |
| // Apps is the compiled registry, in Home's order (directory_runtime.go). |
| var Apps = []App{ |
| {Slug: "docs", Name: "Docs", Prefix: "DOCS", Roster: true, MailPrefixes: []string{"DOCS_SMTP"}}, |
| - {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", MailPrefixes: []string{"CARLOS_SMTP"}}, |
| + {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}}, |
| {Slug: "slides", Name: "Slides", Prefix: "SLIDES", MailPrefixes: []string{"SLIDES_SMTP", "CARLOS_SMTP"}}, |
| {Slug: "calendar", Name: "Calendar", Prefix: "CALENDAR", MailPrefixes: []string{"CALENDAR_SMTP", "CARLOS_SMTP"}}, |
| {Slug: "calls", Name: "Calls", Prefix: "CALLS", MailPrefixes: []string{"CALLS_SMTP", "CARLOS_SMTP"}, Relay: true}, |
| @@ -152,15 +152,14 @@ func Recipe(app App, in Inputs) []Key { |
| case "docs": |
| keys = append(keys, |
| Key{Name: "DOCS_CONTENT_KEY", Class: Generated, Secret: true}, |
| - Key{Name: "DOCS_TEAM_ROSTER_TOKEN", Class: Generated, Secret: true, FromHome: true}, |
| Key{Name: "DOCS_ALLOWED_ADDRESSES", Class: Set, Value: ""}, |
| - Key{Name: "DOCS_TEAM_ID", Class: Set, Value: in.TeamSQID}, |
| - Key{Name: "DOCS_TEAM_DIRECTORY_ORIGIN", Class: Set, Value: in.Home.Directory}, |
| - Key{Name: "DOCS_TEAM_PROVISIONING_BASE64", Class: Set, Value: base64.StdEncoding.EncodeToString(in.Record)}, |
| - Key{Name: "DOCS_TEAM_OPERATOR_KEYS_BASE64", Class: Set, Value: operatorKeys(in.Home.Provisioner)}, |
| ) |
| + keys = append(keys, teamKeys(p, in)...) |
| case "sheets": |
| - keys = append(keys, Key{Name: "SHEETS_DEK", Class: Generated, Secret: true}, owner("SHEETS_OWNERS")) |
| + // Team mode (oficina/sheets team-mode @ b0264ff): SHEETS_OWNERS is |
| + // not needed beside SHEETS_TEAM_*, so the owner is not written. |
| + keys = append(keys, Key{Name: "SHEETS_DEK", Class: Generated, Secret: true}) |
| + keys = append(keys, teamKeys(p, in)...) |
| case "slides": |
| // No uploads (Paul): no CARLOS_STORE_*, so uploads answer 503. |
| keys = append(keys, owner("SLIDES_ALLOWED_ADDRESSES")) |
| @@ -187,7 +186,21 @@ func Recipe(app App, in Inputs) []Key { |
| return keys |
| } |
| -// operatorKeys is DOCS_TEAM_OPERATOR_KEYS_BASE64: the directory's |
| +// teamKeys is a roster-mode app's <P>_TEAM_* five, as Docs and Sheets read |
| +// them: the team sqid, the directory, the signed provisioning record and |
| +// the directory's provisioning key (SET), and Home's roster bearer |
| +// (GENERATED by Home, sealed, fetched by exact replay of step 5). |
| +func teamKeys(p string, in Inputs) []Key { |
| + return []Key{ |
| + {Name: p + "_TEAM_ROSTER_TOKEN", Class: Generated, Secret: true, FromHome: true}, |
| + {Name: p + "_TEAM_ID", Class: Set, Value: in.TeamSQID}, |
| + {Name: p + "_TEAM_DIRECTORY_ORIGIN", Class: Set, Value: in.Home.Directory}, |
| + {Name: p + "_TEAM_PROVISIONING_BASE64", Class: Set, Value: base64.StdEncoding.EncodeToString(in.Record)}, |
| + {Name: p + "_TEAM_OPERATOR_KEYS_BASE64", Class: Set, Value: operatorKeys(in.Home.Provisioner)}, |
| + } |
| +} |
| + |
| +// operatorKeys is <P>_TEAM_OPERATOR_KEYS_BASE64: the directory's |
| // provisioning key as a one-entry []roster.Key, JSON, standard base64. |
| func operatorKeys(public string) string { |
| if public == "" { |
diff --git a/provision/apps_test.go b/provision/apps_test.go| new file mode 100644 |
| index 0000000..60682c7 |
| --- /dev/null |
| +++ b/provision/apps_test.go |
| @@ -0,0 +1,46 @@ |
| +package provision |
| + |
| +import ( |
| + "slices" |
| + "testing" |
| +) |
| + |
| +// The recipes against each app's own config readers. Sheets follows |
| +// oficina/sheets team-mode @ b0264ff (internal/sheets/team_config.go, |
| +// auth.go): SHEETS_TEAM_* all or none, SHEETS_OWNERS not needed beside |
| +// them. |
| +func TestRosterRecipes(t *testing.T) { |
| + in := Inputs{Label: "lagged", Owner: "o@x.test", TeamSQID: "Uk", Record: []byte("{}"), Home: HomeConfig{Issuer: "https://id.oficina.works", Directory: "https://oficina.works", Provisioner: "AQ"}} |
| + want := map[string][]string{ |
| + "docs": {"DOCS_ALLOWED_ADDRESSES", "DOCS_CONTENT_KEY", "DOCS_HOME_CONSUMER_ID", "DOCS_HOME_DEK_BASE64", "DOCS_HOME_ISSUER", "DOCS_HOME_KEYS_BASE64", "DOCS_INSTANCE_KEY", "DOCS_ORIGIN", "DOCS_TEAM_DIRECTORY_ORIGIN", "DOCS_TEAM_ID", "DOCS_TEAM_OPERATOR_KEYS_BASE64", "DOCS_TEAM_PROVISIONING_BASE64", "DOCS_TEAM_ROSTER_TOKEN", "HOME_DIRECTORY_ORIGIN"}, |
| + "sheets": {"HOME_DIRECTORY_ORIGIN", "SHEETS_DEK", "SHEETS_HOME_CONSUMER_ID", "SHEETS_HOME_DEK_BASE64", "SHEETS_HOME_ISSUER", "SHEETS_HOME_KEYS_BASE64", "SHEETS_INSTANCE_KEY", "SHEETS_ORIGIN", "SHEETS_TEAM_DIRECTORY_ORIGIN", "SHEETS_TEAM_ID", "SHEETS_TEAM_OPERATOR_KEYS_BASE64", "SHEETS_TEAM_PROVISIONING_BASE64", "SHEETS_TEAM_ROSTER_TOKEN"}, |
| + } |
| + for slug, names := range want { |
| + app, _ := AppBySlug(slug) |
| + if !app.Roster { |
| + t.Fatalf("%s is not roster-mode", slug) |
| + } |
| + var got []string |
| + for _, k := range Recipe(app, in) { |
| + got = append(got, k.Name) |
| + if k.OwnerAddress { |
| + t.Fatalf("%s writes the owner's address (%s) in team mode", slug, k.Name) |
| + } |
| + if k.Name == app.Prefix+"_TEAM_ROSTER_TOKEN" && (k.Class != Generated || !k.Secret || !k.FromHome) { |
| + t.Fatalf("%s roster token is not Home's sealed bearer", slug) |
| + } |
| + if k.Name == app.Prefix+"_TEAM_ID" && k.Value != "Uk" { |
| + t.Fatalf("%s team id %q", slug, k.Value) |
| + } |
| + } |
| + slices.Sort(got) |
| + if !slices.Equal(got, names) { |
| + t.Fatalf("%s recipe\n got %v\nwant %v", slug, got, names) |
| + } |
| + } |
| + for _, a := range Apps { |
| + if a.Roster != (a.Slug == "docs" || a.Slug == "sheets") { |
| + t.Fatalf("%s roster mode %v", a.Slug, a.Roster) |
| + } |
| + } |
| +} |
diff --git a/provision/review_test.go b/provision/review_test.go| index 696397f..2eaae07 100644 |
| --- a/provision/review_test.go |
| +++ b/provision/review_test.go |
| @@ -25,8 +25,10 @@ func TestOwnerForgottenWhileAnAppIsParked(t *testing.T) { |
| 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) |
| + for _, app := range []string{"docs", "sheets"} { |
| + if st, _, _ := h.store.Step(h.ctx(), "lagged", app, StepVerify); st.Code != "no-readiness-probe" { |
| + t.Fatalf("%s verify %s %s", app, st.State, st.Code) |
| + } |
| } |
| var n int |
| for q, what := range map[string]string{ |
| @@ -42,10 +44,11 @@ func TestOwnerForgottenWhileAnAppIsParked(t *testing.T) { |
| 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") |
| + // The apps without roster mode finished: their allowlists hold the |
| + // owner. |
| + vars, _, _ := h.con.Env("calendar", "lagged") |
| + if vars["CALENDAR_ALLOWED_ADDRESSES"].Value != ownerCanary { |
| + t.Fatal("calendar allowlist not written") |
| } |
| } |
diff --git a/provision/steps.go b/provision/steps.go| index 128a713..4081a25 100644 |
| --- a/provision/steps.go |
| +++ b/provision/steps.go |
| @@ -694,19 +694,32 @@ func (e *Engine) stepVerify(ctx context.Context, p *pass, app App) error { |
| return err |
| } |
| 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", |
| + spec := opSpec{role: homeop.Directory, action: homeop.DirectoryVerify, label: p.run.Label, app: app.Slug, purpose: "verify", reuse: true, |
| build: func(b homeop.InputBase) any { |
| return homeop.VerificationInput{InputBase: b, Consumer: ConsumerID(p.run.Label, app.Slug), TeamSQID: p.team.TeamSQID, App: app.Slug, Audience: PublicOrigin(p.run.Label, app.Slug), |
| Generation: str(cd, "generation"), RecordSequence: 1, RecordDigest: str(cd, "record_digest"), Epoch: num(cd, "epoch"), Owner: p.team.OwnerRef, Issued: issued, Expires: issued + 600} |
| - }}) |
| - if errors.Is(err, errOpRefused) { |
| - return fail("verify-refused") |
| - } |
| - if err != nil { |
| + }} |
| + // An attempt Home already holds is used while it lives: Home |
| + // refuses a second verify for the consumer until the first |
| + // expires, and its answer may have been lost (then recovered by |
| + // replay, or committed by a stream resync). One whose expiry has |
| + // passed is replaced by a new verify, never renewed. Its own |
| + // issued_at is not in the result, so a later one is recorded, |
| + // which activation's started_at ≥ issued_at still admits. |
| + res, held, err := e.replayHeld(ctx, spec) |
| + if held && err != nil { |
| return err |
| } |
| + if !held || res.Expires <= now+60 { |
| + spec.reuse = false |
| + res, err = e.op(ctx, spec) |
| + if errors.Is(err, errOpRefused) { |
| + return fail("verify-refused") |
| + } |
| + if err != nil { |
| + return err |
| + } |
| + } |
| attempt, expires = res.Attempt, res.Expires |
| _ = e.cfg.Store.SetStep(ctx, p.run.Label, app.Slug, StepVerify, "parked", "awaiting-roster", map[string]any{"attempt": attempt, "issued_at": issued, "expires_at": expires}) |
| prev.Data = map[string]any{"attempt": attempt, "issued_at": issued, "expires_at": expires} |