oficina / alta Public

Alta: team runs accept a switched app's <stem>_MAIL_FROM in place of the five SMTP variables, and Alta never writes *_MAIL_FROM or CARLOS_MAIL

CARLOS platform mail submission, Task 9. Fable APPROVED.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from mail/from-carlos into main.
claude agent, operated by paul@keymail.dev 2e0a677d0e97deb7ffce85ff246e3335344915d2 parent b7e42eb
7 files changed, +194 −18
  • README.md +5 −1
  • console/client.go +9 −7
  • console/fakeconsole/fakeconsole.go +15 −4
  • console/seal_test.go +2 −2
  • provision/apps.go +48 −3
  • provision/guard_test.go +1 −1
  • provision/submission_test.go +114 −0

CI passed — run details

CI log
=== vet ===
go vet ./...
=== fmt ===
=== test ===
CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/alta/adopt	19.125s
ok  	amadan.net/oficina/alta/carlosop	(cached)
?   	amadan.net/oficina/alta/carlosop/fakecarlos	[no test files]
ok  	amadan.net/oficina/alta/cmd/alta	0.177s
ok  	amadan.net/oficina/alta/cmd/alta-adopt	16.874s
ok  	amadan.net/oficina/alta/console	0.005s
?   	amadan.net/oficina/alta/console/fakeconsole	[no test files]
ok  	amadan.net/oficina/alta/homeop	(cached)
ok  	amadan.net/oficina/alta/homeop/fakehome	(cached)
ok  	amadan.net/oficina/alta/internal/web	0.134s
ok  	amadan.net/oficina/alta/provision	12.110s
=== compat ===
cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./...
ok  	amadan.net/oficina/home/altacompat	0.597s
diff --git a/README.md b/README.md
index 1c4676b..162abeb 100644
--- a/README.md
+++ b/README.md
@@ -130,7 +130,11 @@ labels and retired hostnames are never reused.
/api/version`; Alta's own config from the table above.
5. **Mail and relay**: each app's mail declared under the prefix its binary
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
+ CARLOS walks mint per-environment credentials. An app switched to
+ 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
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/console/client.go b/console/client.go
index 70fc067..c7fdea9 100644
--- a/console/client.go
+++ b/console/client.go
@@ -59,13 +59,15 @@ type Guard interface {
Delete(ctx context.Context, app, host string) error
}
-// managedKey matches the keys only the platform's walks write into an
-// owned environment (team-scoped-credentials.md §3a): any prefix's SMTP
-// five, the relay identity, the mail-events key, scan callback secrets
-// and the object store's coordinates. CARLOS refuses a team write of
-// them too; Alta refuses first, for every prefix, without asking which
-// one the app declared.
-var managedKey = regexp.MustCompile(`^([A-Z][A-Z0-9_]*_SMTP_(HOST|PORT|USER|PASS|FROM)|CARLOS_RELAY|CARLOS_MAIL_EVENTS_KEY|[A-Z][A-Z0-9_]*_SCAN_CALLBACK_SECRET|CARLOS_STORE_[A-Z0-9_]+)$`)
+// managedKey matches the keys only the platform writes into an owned
+// environment (team-scoped-credentials.md §3a): any prefix's SMTP five,
+// the From variable a switched app gets in their place (<stem>_MAIL_FROM,
+// platform mail submission G3), the relay identity, the mail-events key,
+// scan callback secrets and the object store's coordinates; and
+// CARLOS_MAIL, which only the agent sets, at instance start. CARLOS
+// refuses a team write of most of them too; Alta refuses first, for every
+// prefix, without asking which one the app declared.
+var managedKey = regexp.MustCompile(`^([A-Z][A-Z0-9_]*_SMTP_(HOST|PORT|USER|PASS|FROM)|[A-Z][A-Z0-9_]*_MAIL_FROM|CARLOS_MAIL|CARLOS_RELAY|CARLOS_MAIL_EVENTS_KEY|[A-Z][A-Z0-9_]*_SCAN_CALLBACK_SECRET|CARLOS_STORE_[A-Z0-9_]+)$`)
// PlatformManaged reports whether key is the platform's alone.
func PlatformManaged(key string) bool { return managedKey.MatchString(key) }
diff --git a/console/fakeconsole/fakeconsole.go b/console/fakeconsole/fakeconsole.go
index df8995b..e4d9ff7 100644
--- a/console/fakeconsole/fakeconsole.go
+++ b/console/fakeconsole/fakeconsole.go
@@ -67,6 +67,10 @@ type Console struct {
// mail enabled. Relay lists the apps with the relay enabled.
MailPrefix map[string]string
Relay map[string]bool
+ // Submission lists the apps switched to CARLOS mail submission
+ // (`carlos email submission on`): their owned environments get the
+ // From variable alone, <stem>_MAIL_FROM, and no SMTP credential.
+ Submission map[string]bool
// PrivateStorage lists the apps with the private-storage policy on
// (`carlos instances enable --private-storage`): an instance create
// provisions its environment's own store and delivers CARLOS_STORE_*
@@ -103,7 +107,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{}, PrivateStorage: map[string]bool{}, Versions: map[string]string{}, DomainPolls: 1, Roster: "ok", SecretWrites: map[string]int{}, ServingName: map[string]string{}, VersionAnswer: map[string]string{}}
+ MailPrefix: map[string]string{}, Relay: map[string]bool{}, Submission: map[string]bool{}, PrivateStorage: map[string]bool{}, Versions: map[string]string{}, DomainPolls: 1, Roster: "ok", SecretWrites: map[string]int{}, ServingName: map[string]string{}, VersionAnswer: map[string]string{}}
c.srv = httptest.NewServer(http.HandlerFunc(c.serve))
return c
}
@@ -225,8 +229,10 @@ const PlatformCanary = "PLATFORM-VALUE-CANARY"
// Walk is one pass of the mail and relay walks: every owned environment
// of an app with mail declared gets its own SMTP credential under the
-// declared prefix, and Calls its own relay identity. Never shared with
-// the default bundle; never written by a team credential.
+// declared prefix, or, for an app switched to submission, only the From
+// variable for that prefix (CARLOS's DeliverMailFromIn); and Calls its
+// own relay identity. Never shared with the default bundle; never written
+// by a team credential.
func (c *Console) Walk() {
c.mu.Lock()
defer c.mu.Unlock()
@@ -235,7 +241,12 @@ func (c *Console) Walk() {
if b.owner == "" {
continue
}
- if p := c.MailPrefix[app]; p != "" {
+ if p := c.MailPrefix[app]; p != "" && c.Submission[app] {
+ stem := strings.TrimSuffix(p, "_SMTP")
+ if _, ok := b.vars[stem+"_MAIL_FROM"]; !ok {
+ b.vars[stem+"_MAIL_FROM"] = Var{Kind: "env", Value: "team@oficina.works"}
+ }
+ } else if p != "" {
if _, ok := b.vars[p+"_USER"]; !ok {
c.minted++
b.vars[p+"_HOST"] = Var{Kind: "env", Value: "email-smtp.eu-west-1.amazonaws.com"}
diff --git a/console/seal_test.go b/console/seal_test.go
index 8a45b5a..929ea23 100644
--- a/console/seal_test.go
+++ b/console/seal_test.go
@@ -42,12 +42,12 @@ func TestSealOpensForItsBindingOnly(t *testing.T) {
}
func TestPlatformManaged(t *testing.T) {
- for _, k := range []string{"CARLOS_SMTP_PASS", "DOCS_SMTP_FROM", "CARLOS_RELAY", "CARLOS_MAIL_EVENTS_KEY", "SLIDES_SCAN_CALLBACK_SECRET", "CARLOS_STORE_ACCESS_KEY"} {
+ for _, k := range []string{"CARLOS_SMTP_PASS", "DOCS_SMTP_FROM", "CARLOS_MAIL_FROM", "DOCS_MAIL_FROM", "CARLOS_MAIL", "CARLOS_RELAY", "CARLOS_MAIL_EVENTS_KEY", "SLIDES_SCAN_CALLBACK_SECRET", "CARLOS_STORE_ACCESS_KEY"} {
if !PlatformManaged(k) {
t.Errorf("%s not platform-managed", k)
}
}
- for _, k := range []string{"DOCS_ORIGIN", "SMTP_HOSTNAME", "CALLS_DEK", "DOCS_SMTP", "MEMORIA_OWNERS"} {
+ for _, k := range []string{"DOCS_ORIGIN", "SMTP_HOSTNAME", "CALLS_DEK", "DOCS_SMTP", "MEMORIA_OWNERS", "CARLOS_MAILER", "MAIL_FROM"} {
if PlatformManaged(k) {
t.Errorf("%s platform-managed", k)
}
diff --git a/provision/apps.go b/provision/apps.go
index 7875982..68e5777 100644
--- a/provision/apps.go
+++ b/provision/apps.go
@@ -70,6 +70,9 @@ 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
// Relay is true when CARLOS_RELAY is a PLATFORM key (Calls).
Relay bool
@@ -497,6 +500,23 @@ func SMTPKeys(prefix string) []string {
var smtpKey = regexp.MustCompile(`^([A-Z][A-Z0-9_]*_SMTP)_(HOST|PORT|USER|PASS|FROM)$`)
+// mailFromKey is the From variable CARLOS delivers for an app switched to
+// platform mail submission. Its stem is the declared prefix without
+// _SMTP: CARLOS_SMTP gives CARLOS_MAIL_FROM, DOCS_SMTP gives
+// DOCS_MAIL_FROM (carlos internal/mail MailFromName).
+var mailFromKey = regexp.MustCompile(`^([A-Z][A-Z0-9_]*)_MAIL_FROM$`)
+
+// MailFromKey is the From variable a switched app's environment holds for
+// prefix, in place of SMTPKeys(prefix). "" for a prefix that does not end
+// in _SMTP, which CARLOS refuses to switch.
+func MailFromKey(prefix string) string {
+ stem, ok := strings.CutSuffix(prefix, "_SMTP")
+ if !ok || stem == "" {
+ return ""
+ }
+ return stem + "_MAIL_FROM"
+}
+
// PlatformState is what the walks have delivered into one environment.
type PlatformState struct {
// Keys are the PLATFORM keys present that this app reads.
@@ -534,18 +554,32 @@ var StoreKeys = []StoreKey{
}
// PlatformKeys classifies an environment's present key names against
-// app's PLATFORM expectations.
+// what the app's binary reads.
+//
+// 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
+// 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.
func PlatformKeys(app App, present map[string]bool) PlatformState {
var st PlatformState
prefixes := map[string]int{}
+ submit := map[string]bool{}
for k := range present {
if m := smtpKey.FindStringSubmatch(k); m != nil {
prefixes[m[1]]++
+ } else if m := mailFromKey.FindStringSubmatch(k); m != nil {
+ submit[m[1]+"_SMTP"] = true
}
}
chosen := ""
for _, p := range app.MailPrefixes {
- if prefixes[p] > 0 {
+ if prefixes[p] > 0 || submit[p] {
chosen = p
break
}
@@ -555,10 +589,21 @@ func PlatformKeys(app App, present map[string]bool) PlatformState {
st.WrongPrefix = p
}
}
+ for p := range submit {
+ if !slices.Contains(app.MailPrefixes, p) {
+ st.WrongPrefix = p
+ }
+ }
if chosen == "" {
chosen = app.MailPrefixes[0]
}
- want := SMTPKeys(chosen)
+ var want []string
+ if submit[chosen] {
+ want = append(want, MailFromKey(chosen))
+ }
+ if !submit[chosen] || prefixes[chosen] > 0 {
+ want = append(want, SMTPKeys(chosen)...)
+ }
if app.Relay {
want = append(want, "CARLOS_RELAY")
}
diff --git a/provision/guard_test.go b/provision/guard_test.go
index 19b5883..b42a1ec 100644
--- a/provision/guard_test.go
+++ b/provision/guard_test.go
@@ -110,7 +110,7 @@ func TestGuardRefusesDeleteOutsideADeprovisionRun(t *testing.T) {
func TestGuardRefusesPlatformManagedKeys(t *testing.T) {
h, e := guardHarness(t)
before := len(h.con.Requests)
- for _, k := range []string{"CARLOS_SMTP_PASS", "DOCS_SMTP_USER", "SHEETS_SMTP_HOST", "CARLOS_RELAY", "CARLOS_MAIL_EVENTS_KEY", "SLIDES_SCAN_CALLBACK_SECRET", "CARLOS_STORE_BUCKET", "CARLOS_STORE_REGION", "CARLOS_STORE_ENDPOINT", "CARLOS_STORE_ACCESS_KEY", "CARLOS_STORE_SECRET_KEY"} {
+ for _, k := range []string{"CARLOS_SMTP_PASS", "DOCS_SMTP_USER", "SHEETS_SMTP_HOST", "CARLOS_MAIL_FROM", "DOCS_MAIL_FROM", "CARLOS_MAIL", "CARLOS_RELAY", "CARLOS_MAIL_EVENTS_KEY", "SLIDES_SCAN_CALLBACK_SECRET", "CARLOS_STORE_BUCKET", "CARLOS_STORE_REGION", "CARLOS_STORE_ENDPOINT", "CARLOS_STORE_ACCESS_KEY", "CARLOS_STORE_SECRET_KEY"} {
_, err := e.cfg.Console.PutConfig(h.ctx(), "sheets", "alpha", map[string]console.SetVar{k: {Kind: "env", Value: "x"}}, nil, "")
refusedLocally(t, h, "set "+k, err)
_, err = e.cfg.Console.PutConfig(h.ctx(), "sheets", "alpha", nil, []string{k}, "")
diff --git a/provision/submission_test.go b/provision/submission_test.go
new file mode 100644
index 0000000..d942f3a
--- /dev/null
+++ b/provision/submission_test.go
@@ -0,0 +1,114 @@
+package provision
+
+import (
+ "slices"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/alta/homeop"
+)
+
+// CARLOS platform mail submission (carlos/platform plan Task 9): a team
+// environment of a switched app holds <stem>_MAIL_FROM and no SMTP
+// credential, and its instances send through the box's mailer. Alta
+// takes that as the app's mail, never waits past it for the five, and
+// never writes it.
+
+func TestPlatformKeysAcceptEitherMailChannel(t *testing.T) {
+ calls, _ := AppBySlug("calls")
+ slides, _ := AppBySlug("slides")
+ docs, _ := AppBySlug("docs")
+ set := func(keys ...string) map[string]bool {
+ m := map[string]bool{}
+ for _, k := range keys {
+ m[k] = true
+ }
+ return m
+ }
+ five := SMTPKeys("CARLOS_SMTP")
+ cases := []struct {
+ name string
+ app App
+ present map[string]bool
+ keys, missing []string
+ wrong string
+ }{
+ {"nothing yet waits for the five", calls, set(), nil, append(SMTPKeys("CALLS_SMTP"), "CARLOS_RELAY"), ""},
+ {"the five", calls, set(append(slices.Clone(five), "CARLOS_RELAY")...), append(slices.Clone(five), "CARLOS_RELAY"), nil, ""},
+ {"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, ""},
+ {"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"},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ st := PlatformKeys(c.app, c.present)
+ if !slices.Equal(st.Keys, c.keys) || !slices.Equal(st.Missing, c.missing) || st.WrongPrefix != c.wrong {
+ t.Fatalf("got keys %v missing %v wrong %q; want %v %v %q", st.Keys, st.Missing, st.WrongPrefix, c.keys, c.missing, c.wrong)
+ }
+ })
+ }
+}
+
+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 {
+ t.Errorf("MailFromKey(%q) = %q, want %q", prefix, got, want)
+ }
+ }
+}
+
+func TestSwitchedAppRunsWithTheFromAndNoCredential(t *testing.T) {
+ h := newHarness(t)
+ h.initialized()
+ h.con.MailPrefix["calls"] = "CARLOS_SMTP" // as calls is declared live
+ h.con.Submission["calls"] = true
+ e := h.engine(nil)
+ run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "beta", Name: "Beta", Owner: ownerCanary, Apps: []string{"calls"}})
+ if err != nil {
+ t.Fatal(err)
+ }
+ h.confirm(homeop.KindCreateTeam)
+ _ = e.Advance(h.ctx(), run)
+ st, _, _ := h.store.Step(h.ctx(), "beta", "calls", StepEnv)
+ if st.Code != "awaiting-platform-keys" {
+ t.Fatalf("env step %s %s", st.State, st.Code)
+ }
+ h.con.Walk()
+ if r := h.drive(e, run, 20); r.State != "done" {
+ t.Fatalf("%s %s", r.State, r.Code)
+ }
+ vars, _, _ := h.con.Env("calls", "beta")
+ if _, ok := vars["CARLOS_MAIL_FROM"]; !ok {
+ t.Fatal("no From variable")
+ }
+ for k := range vars {
+ if strings.Contains(k, "_SMTP_") {
+ t.Fatalf("a switched app's team environment holds %s", k)
+ }
+ }
+ done, _, _ := h.store.Done(h.ctx(), "beta", "calls", StepEnv)
+ if platform, _ := done["platform"].([]any); !slices.ContainsFunc(platform, func(v any) bool { return v == "CARLOS_MAIL_FROM" }) {
+ t.Fatalf("env step's platform keys %v do not name the From", done["platform"])
+ }
+ calls, _ := AppBySlug("calls")
+ if err := e.AuditEnvironment(h.ctx(), "beta", calls); err != nil {
+ t.Fatalf("audit: %v", err)
+ }
+}
+
+func TestSwitchedDocsUnderTheWrongPrefixRefuses(t *testing.T) {
+ h := newHarness(t)
+ h.initialized()
+ h.con.MailPrefix["docs"] = "CARLOS_SMTP" // Docs reads DOCS_MAIL_FROM only
+ h.con.Submission["docs"] = true
+ e := h.engine(nil)
+ run := h.createLagged(e)
+ r := h.drive(e, run, 10)
+ if r.State != "failed" || r.Code != "mail-prefix-docs" {
+ t.Fatalf("%s %s", r.State, r.Code)
+ }
+}