oficina / alta Public

Alta: accept a switched app's From only under the stem its binary reads

The switched binaries call mail.FromCarlos("CARLOS"), or "DOCS" for Docs,
so they read exactly one <stem>_MAIL_FROM. Step 7 and the audit took a
From under any stem in MailPrefixes, including SLIDES_MAIL_FROM,
CALENDAR_MAIL_FROM and CALLS_MAIL_FROM, which CARLOS delivers for an app
declared under its own prefix and which the switched binary never reads.

Each registry app now names its SubmitPrefix (CARLOS_SMTP, Docs
DOCS_SMTP). A From under any other stem is a wrong prefix and fails the
run with mail-prefix-<app>. The five SMTP variables are still read under
MailPrefixes, the mid-flip environment holding both is still admitted,
and Alta still never writes *_MAIL_FROM or CARLOS_MAIL.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev a66b6a98089131bd671440dc408e0f81abcab1f9 parent 4337944
4 files changed, +152 −35
  • README.md +5 −1
  • provision/apps.go +44 −32
  • provision/submission_test.go +77 −2
  • provision/submitprefix_test.go +26 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/alta/adopt	17.142s
ok  	amadan.net/oficina/alta/carlosop	0.038s
?   	amadan.net/oficina/alta/carlosop/fakecarlos	[no test files]
ok  	amadan.net/oficina/alta/cmd/alta	0.211s
ok  	amadan.net/oficina/alta/cmd/alta-adopt	26.696s
ok  	amadan.net/oficina/alta/console	0.003s
?   	amadan.net/oficina/alta/console/fakeconsole	[no test files]
ok  	amadan.net/oficina/alta/homeop	0.003s
ok  	amadan.net/oficina/alta/homeop/fakehome	0.048s
ok  	amadan.net/oficina/alta/internal/web	0.116s
ok  	amadan.net/oficina/alta/provision	11.818s
=== compat ===
cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/altacompat	0.559s
diff --git a/README.md b/README.md
index cc713fb..450747e 100644
--- a/README.md
+++ b/README.md
@@ -134,7 +134,11 @@ labels and retired hostnames are never reused.
CARLOS mail submission (`carlos email submission on --app <a>`, Paul)
gets no credential at all: each team environment receives only
`<stem>_MAIL_FROM` (`CARLOS_MAIL_FROM`, or `DOCS_MAIL_FROM` for Docs),
- and step 7 takes that as the app's mail. Alta is given no SMTP, From or
+ and step 7 takes that as the app's mail. The switched binaries read
+ only that one From, so a switched app must be declared under
+ `CARLOS_SMTP` (Docs: `DOCS_SMTP`), even one whose SMTP also reads its
+ own prefix (Slides, Calendar, Calls); a From under any other stem fails
+ step 7 with `mail-prefix-<app>`. Alta is given no SMTP, From or
relay value. Slides' private-storage policy on (`carlos instances
enable --app slides --private-storage`, Paul), so each team Slides gets
its own bucket; Alta is given no store value either.
diff --git a/provision/apps.go b/provision/apps.go
index 68e5777..589c0fd 100644
--- a/provision/apps.go
+++ b/provision/apps.go
@@ -70,10 +70,16 @@ type App struct {
// MailPrefixes are the <PREFIX>_SMTP_* sets the binary reads, in its
// own order. The mail walk writes the set the app declared; a set the
// binary does not read leaves it without mail, which step 7 refuses.
- // For an app switched to CARLOS mail submission the walk writes, in
- // place of the five, the one From variable rastrillo's submit
- // transport reads for the same prefix (MailFromKey).
MailPrefixes []string
+ // SubmitPrefix is the one prefix whose From the binary reads when it
+ // is switched to CARLOS mail submission: it calls rastrillo's
+ // mail.FromCarlos with this prefix's stem, so it reads only
+ // MailFromKey(SubmitPrefix). CARLOS delivers the From under the stem
+ // of the app's declared prefix, so a switched app declared under any
+ // other prefix (Slides under SLIDES_SMTP, say) gets a From its binary
+ // never reads, and step 7 refuses it. CARLOS_SMTP for every app but
+ // Docs, which is declared and read as DOCS_SMTP.
+ SubmitPrefix string
// Relay is true when CARLOS_RELAY is a PLATFORM key (Calls).
Relay bool
// Store is true for an app whose instances may carry an object store
@@ -88,12 +94,12 @@ 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"}, Dashboard: true},
- {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}, Dashboard: true},
- {Slug: "slides", Name: "Slides", Prefix: "SLIDES", Roster: true, MailPrefixes: []string{"SLIDES_SMTP", "CARLOS_SMTP"}, Dashboard: true, Store: true},
- {Slug: "calendar", Name: "Calendar", Prefix: "CALENDAR", Roster: true, MailPrefixes: []string{"CALENDAR_SMTP", "CARLOS_SMTP"}, Dashboard: true},
- {Slug: "calls", Name: "Calls", Prefix: "CALLS", Roster: true, MailPrefixes: []string{"CALLS_SMTP", "CARLOS_SMTP"}, Relay: true},
- {Slug: "memoria", Name: "Memoria", Prefix: "MEMORIA", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}},
+ {Slug: "docs", Name: "Docs", Prefix: "DOCS", Roster: true, MailPrefixes: []string{"DOCS_SMTP"}, SubmitPrefix: "DOCS_SMTP", Dashboard: true},
+ {Slug: "sheets", Name: "Sheets", Prefix: "SHEETS", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}, SubmitPrefix: "CARLOS_SMTP", Dashboard: true},
+ {Slug: "slides", Name: "Slides", Prefix: "SLIDES", Roster: true, MailPrefixes: []string{"SLIDES_SMTP", "CARLOS_SMTP"}, SubmitPrefix: "CARLOS_SMTP", Dashboard: true, Store: true},
+ {Slug: "calendar", Name: "Calendar", Prefix: "CALENDAR", Roster: true, MailPrefixes: []string{"CALENDAR_SMTP", "CARLOS_SMTP"}, SubmitPrefix: "CARLOS_SMTP", Dashboard: true},
+ {Slug: "calls", Name: "Calls", Prefix: "CALLS", Roster: true, MailPrefixes: []string{"CALLS_SMTP", "CARLOS_SMTP"}, SubmitPrefix: "CARLOS_SMTP", Relay: true},
+ {Slug: "memoria", Name: "Memoria", Prefix: "MEMORIA", Roster: true, MailPrefixes: []string{"CARLOS_SMTP"}, SubmitPrefix: "CARLOS_SMTP"},
}
// AppBySlug finds a registry app.
@@ -523,8 +529,10 @@ type PlatformState struct {
Keys []string
// Missing is the PLATFORM keys still to arrive.
Missing []string
- // WrongPrefix names an SMTP prefix delivered that the binary does not
- // read: a declaration under the wrong prefix (§5, §6 step 0).
+ // WrongPrefix names a prefix delivered that the binary does not read:
+ // five SMTP variables outside MailPrefixes, or a From whose stem is
+ // not SubmitPrefix's. Either is a declaration under the wrong prefix
+ // (§5, §6 step 0).
WrongPrefix string
// Store is the object-store keys present, for an app with a Store.
// Kept apart from Keys: the store arrives at step 8, after step 7
@@ -558,14 +566,17 @@ var StoreKeys = []StoreKey{
//
// Mail arrives one of two ways. An app on SMTP gets the five
// <PREFIX>_SMTP_* of its declared prefix. An app switched to CARLOS mail
-// submission gets only <stem>_MAIL_FROM (MailFromKey), and its instances
-// send through the box's mailer with no credential at all: the agent adds
+// submission gets only <stem>_MAIL_FROM, and its instances send through
+// the box's mailer with no credential at all: the agent adds
// CARLOS_MAIL=submit and the control socket at start, never the bundle.
-// Either is mail; the From variable alone is not waited past for the
-// five. During a switch-on CARLOS delivers the From before it takes the
-// five out, and during a switch-off the five before it takes the From
-// out, so an environment caught between holds both and every one present
-// is admitted.
+// The binary reads exactly one From, MailFromKey(app.SubmitPrefix); a
+// From under any other stem is a declaration under the wrong prefix,
+// refused like a wrong SMTP prefix, because the switched binary would
+// find no From and refuse to start. Either channel is mail; the From
+// alone is not waited past for the five. During a switch-on CARLOS
+// delivers the From before it takes the five out, and during a
+// switch-off the five before it takes the From out, so an environment
+// caught between holds both and every one present is admitted.
func PlatformKeys(app App, present map[string]bool) PlatformState {
var st PlatformState
prefixes := map[string]int{}
@@ -577,32 +588,33 @@ func PlatformKeys(app App, present map[string]bool) PlatformState {
submit[m[1]+"_SMTP"] = true
}
}
- chosen := ""
- for _, p := range app.MailPrefixes {
- if prefixes[p] > 0 || submit[p] {
- chosen = p
- break
- }
- }
for p := range prefixes {
if !slices.Contains(app.MailPrefixes, p) {
st.WrongPrefix = p
}
}
for p := range submit {
- if !slices.Contains(app.MailPrefixes, p) {
+ if p != app.SubmitPrefix {
st.WrongPrefix = p
}
}
- if chosen == "" {
- chosen = app.MailPrefixes[0]
+ smtp := ""
+ for _, p := range app.MailPrefixes {
+ if prefixes[p] > 0 {
+ smtp = p
+ break
+ }
}
+ switched := submit[app.SubmitPrefix]
var want []string
- if submit[chosen] {
- want = append(want, MailFromKey(chosen))
+ if switched {
+ want = append(want, MailFromKey(app.SubmitPrefix))
}
- if !submit[chosen] || prefixes[chosen] > 0 {
- want = append(want, SMTPKeys(chosen)...)
+ switch {
+ case smtp != "":
+ want = append(want, SMTPKeys(smtp)...)
+ case !switched:
+ want = append(want, SMTPKeys(app.MailPrefixes[0])...)
}
if app.Relay {
want = append(want, "CARLOS_RELAY")
diff --git a/provision/submission_test.go b/provision/submission_test.go
index d942f3a..2f9747b 100644
--- a/provision/submission_test.go
+++ b/provision/submission_test.go
@@ -38,8 +38,8 @@ func TestPlatformKeysAcceptEitherMailChannel(t *testing.T) {
{"switched: the From alone", calls, set("CARLOS_MAIL_FROM", "CARLOS_RELAY"), []string{"CARLOS_MAIL_FROM", "CARLOS_RELAY"}, nil, ""},
{"between a flip: both", calls, set(append(slices.Clone(five), "CARLOS_MAIL_FROM", "CARLOS_RELAY")...), append(append([]string{"CARLOS_MAIL_FROM"}, five...), "CARLOS_RELAY"), nil, ""},
{"switched still waits for the relay", calls, set("CARLOS_MAIL_FROM"), []string{"CARLOS_MAIL_FROM"}, []string{"CARLOS_RELAY"}, ""},
- {"the app's own prefix first", slides, set("SLIDES_MAIL_FROM"), []string{"SLIDES_MAIL_FROM"}, nil, ""},
- {"the fallback prefix", slides, set("CARLOS_MAIL_FROM"), []string{"CARLOS_MAIL_FROM"}, nil, ""},
+ {"slides reads the CARLOS From", slides, set("CARLOS_MAIL_FROM"), []string{"CARLOS_MAIL_FROM"}, nil, ""},
+ {"slides' own SMTP prefix mid-flip", slides, set(append(SMTPKeys("SLIDES_SMTP"), "CARLOS_MAIL_FROM")...), append([]string{"CARLOS_MAIL_FROM"}, SMTPKeys("SLIDES_SMTP")...), nil, ""},
{"docs reads DOCS only", docs, set("DOCS_MAIL_FROM"), []string{"DOCS_MAIL_FROM"}, nil, ""},
{"a From under a prefix the binary does not read", docs, set("CARLOS_MAIL_FROM"), nil, SMTPKeys("DOCS_SMTP"), "CARLOS_SMTP"},
}
@@ -53,6 +53,81 @@ func TestPlatformKeysAcceptEitherMailChannel(t *testing.T) {
}
}
+// The switched binaries read one From only: mail.FromCarlos("CARLOS"),
+// or "DOCS" for Docs (each app's main, "Mail through rastrillo's
+// FromCarlos"). A From under any other stem, which CARLOS delivers for an
+// app declared under that prefix, leaves the switched binary with no From
+// at all, so it is refused, never taken as mail. The five under the same
+// prefix are still admitted, and the From never stands in for them.
+func TestPlatformKeysRefuseAFromTheBinaryDoesNotRead(t *testing.T) {
+ set := func(keys ...string) map[string]bool {
+ m := map[string]bool{}
+ for _, k := range keys {
+ m[k] = true
+ }
+ return m
+ }
+ cases := []struct {
+ slug, from, wrong string
+ }{
+ {"slides", "SLIDES_MAIL_FROM", "SLIDES_SMTP"},
+ {"calendar", "CALENDAR_MAIL_FROM", "CALENDAR_SMTP"},
+ {"calls", "CALLS_MAIL_FROM", "CALLS_SMTP"},
+ {"sheets", "SHEETS_MAIL_FROM", "SHEETS_SMTP"},
+ {"memoria", "MEMORIA_MAIL_FROM", "MEMORIA_SMTP"},
+ {"docs", "CARLOS_MAIL_FROM", "CARLOS_SMTP"},
+ }
+ for _, c := range cases {
+ t.Run(c.slug+" "+c.from, func(t *testing.T) {
+ app, _ := AppBySlug(c.slug)
+ present := set(c.from, "CARLOS_RELAY")
+ st := PlatformKeys(app, present)
+ if st.WrongPrefix != c.wrong {
+ t.Fatalf("wrong prefix %q, want %q", st.WrongPrefix, c.wrong)
+ }
+ if slices.Contains(st.Keys, c.from) {
+ t.Fatalf("%s taken as mail: keys %v", c.from, st.Keys)
+ }
+ // Mid-flip under the same wrong prefix: the five do not make
+ // the From readable.
+ if c.slug == "docs" {
+ return
+ }
+ for _, k := range SMTPKeys(c.wrong) {
+ present[k] = true
+ }
+ if st := PlatformKeys(app, present); st.WrongPrefix != c.wrong {
+ t.Fatalf("mid-flip: wrong prefix %q, want %q", st.WrongPrefix, c.wrong)
+ }
+ })
+ }
+}
+
+// A team run of an app switched while declared under a prefix whose From
+// its binary does not read fails at step 7 with mail-prefix-<app>, as
+// Docs under CARLOS_SMTP does, rather than finishing a team that can
+// never send a sign-in link.
+func TestSwitchedAppUnderItsOwnPrefixRefuses(t *testing.T) {
+ for _, c := range []struct{ slug, prefix string }{
+ {"slides", "SLIDES_SMTP"},
+ {"calendar", "CALENDAR_SMTP"},
+ {"calls", "CALLS_SMTP"},
+ } {
+ t.Run(c.slug, func(t *testing.T) {
+ h := newHarness(t)
+ h.initialized()
+ h.con.MailPrefix[c.slug] = c.prefix // SMTP reads it; the switched binary does not
+ h.con.Submission[c.slug] = true
+ e := h.engine(nil)
+ run := h.createLagged(e)
+ r := h.drive(e, run, 10)
+ if r.State != "failed" || r.Code != "mail-prefix-"+c.slug {
+ t.Fatalf("%s %s", r.State, r.Code)
+ }
+ })
+ }
+}
+
func TestMailFromKey(t *testing.T) {
for prefix, want := range map[string]string{"CARLOS_SMTP": "CARLOS_MAIL_FROM", "DOCS_SMTP": "DOCS_MAIL_FROM", "_SMTP": "", "CARLOS": ""} {
if got := MailFromKey(prefix); got != want {
diff --git a/provision/submitprefix_test.go b/provision/submitprefix_test.go
new file mode 100644
index 0000000..6b991e8
--- /dev/null
+++ b/provision/submitprefix_test.go
@@ -0,0 +1,26 @@
+package provision
+
+import (
+ "slices"
+ "testing"
+)
+
+// Every registry app names the one prefix whose From its switched binary
+// reads: CARLOS_SMTP (mail.FromCarlos("CARLOS")) for all but Docs, which
+// reads DOCS_SMTP's. The prefix is one the binary also reads on SMTP, so
+// a declaration that works on SMTP keeps working when switched.
+func TestEveryAppNamesTheFromItsBinaryReads(t *testing.T) {
+ want := map[string]string{"docs": "DOCS_SMTP"}
+ for _, a := range Apps {
+ w := want[a.Slug]
+ if w == "" {
+ w = "CARLOS_SMTP"
+ }
+ if a.SubmitPrefix != w {
+ t.Errorf("%s: SubmitPrefix %q, want %q", a.Slug, a.SubmitPrefix, w)
+ }
+ if !slices.Contains(a.MailPrefixes, a.SubmitPrefix) {
+ t.Errorf("%s: SubmitPrefix %q is not one of its SMTP prefixes %v", a.Slug, a.SubmitPrefix, a.MailPrefixes)
+ }
+ }
+}