Write the agent keys into every team environment
A team Alta provisioned could not be reached through oficina-connect, because its apps never received <P>_AGENT_ISSUER or <P>_AGENT_TEAM. Step 7 now writes both in one config write, with the connection service as issuer and Home's team SQID as the team. Every app refuses to start on one alone, so the recipe holds both or neither. Both values are public: Alta gains no credential and no call to connect. The exact-keys audit checks them. An environment step 7 finished before this release is never rewritten and is audited as holding neither. homecompat now checks Home's real agent directory lists the team's apps at their canonical origins, and stops listing an app once it is retired.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+465
−3
README.md+12 −0adopt/types_test.go+7 −0console/fakeconsole/fakeconsole.go+8 −0homecompat/compat_test.go+84 −0provision/agent_keys_test.go+322 −0provision/apps.go+23 −1provision/steps.go+9 −2
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 18.309s ok amadan.net/oficina/alta/carlosop 0.057s ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta 0.172s ok amadan.net/oficina/alta/cmd/alta-adopt 22.139s 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.048s ok amadan.net/oficina/alta/internal/web 0.119s ok amadan.net/oficina/alta/provision 13.595s === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/altacompat 0.759s
diff --git a/README.md b/README.md| index bca1bb2..300acbc 100644 |
| --- a/README.md |
| +++ b/README.md |
| @@ -81,6 +81,18 @@ exactly as Alta wrote it (`OFICINA_DASHBOARD_TEAM=<label>`, |
| `DOCS_SAMPLE_DOCUMENTS=1`); the console guard refuses any set of |
| `MEMORIA_AI` or `MEMORIA_TENSORX_KEY`. |
| +### Agent access |
| + |
| +Step 7 writes two public keys into every app's environment, in one write: |
| +`<P>_AGENT_ISSUER = https://connect.oficina.works` and `<P>_AGENT_TEAM = <the |
| +team's SQID>`. Every app refuses to start on one without the other, so the |
| +recipe holds both or neither and the audit checks them exactly. Alta holds no |
| +credential for this and makes no call to oficina-connect: connect reads each |
| +team's live apps from Home's directory, so activating an app opens its route |
| +and retiring it (`directory.disable-consumer`, the first retire step) closes |
| +it. An environment written before Alta wrote these keys is never rewritten and |
| +is audited as holding neither. |
| + |
| Labels: Alta's pattern, never `--` (`xn--` punycode), and never a reserved |
| name (`ReservedLabels`: `oficina`, every app's name, and the suite's and |
| platform's own names). |
diff --git a/adopt/types_test.go b/adopt/types_test.go| index 0d41098..d39f39e 100644 |
| --- a/adopt/types_test.go |
| +++ b/adopt/types_test.go |
| @@ -114,3 +114,10 @@ func TestSameIdentityFlagsEachField(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// Adoption and provisioning tell the apps to trust the same issuer. |
| +func TestIssuerIsProvisioningsIssuer(t *testing.T) { |
| + if Issuer != provision.AgentIssuer { |
| + t.Fatalf("adoption %q, provisioning %q", Issuer, provision.AgentIssuer) |
| + } |
| +} |
diff --git a/console/fakeconsole/fakeconsole.go b/console/fakeconsole/fakeconsole.go| index e4d9ff7..cfb83e5 100644 |
| --- a/console/fakeconsole/fakeconsole.go |
| +++ b/console/fakeconsole/fakeconsole.go |
| @@ -98,6 +98,9 @@ type Console struct { |
| // SecretWrites counts writes of each secret, app/env/key: a GENERATED |
| // key written twice was regenerated. |
| SecretWrites map[string]int |
| + // ConfigWrites records the keys each PUT /config set, in order, as |
| + // app/env followed by the key names. |
| + ConfigWrites [][]string |
| minted int |
| srv *httptest.Server |
| } |
| @@ -427,6 +430,11 @@ func (c *Console) serve(w http.ResponseWriter, r *http.Request) { |
| b = &bundle{owner: c.Scope, vars: map[string]Var{}} |
| c.envs[app][env] = b |
| } |
| + written := []string{app + "/" + env} |
| + for k := range set { |
| + written = append(written, k) |
| + } |
| + c.ConfigWrites = append(c.ConfigWrites, written) |
| for k, raw := range set { |
| v, _ := raw.(map[string]any) |
| kind, _ := v["kind"].(string) |
diff --git a/homecompat/compat_test.go b/homecompat/compat_test.go| index 1939646..1fec6c3 100644 |
| --- a/homecompat/compat_test.go |
| +++ b/homecompat/compat_test.go |
| @@ -467,6 +467,90 @@ func TestAltaAgainstHomesRealOperator(t *testing.T) { |
| } |
| } |
| +// TestHomesAgentDirectoryFollowsTheTeam is what oficina-connect routes on: |
| +// Home's own answer lists a provisioned team's apps at their canonical |
| +// origins, under the team id Alta wrote into each app, and stops listing an |
| +// app the moment Alta retires it. |
| +func TestHomesAgentDirectoryFollowsTheTeam(t *testing.T) { |
| + r := newRig(t) |
| + ctx := context.Background() |
| + run, err := r.engine.StartInitialize(ctx, provision.InitializeAttestation) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.home.confirm(t, "directory", "") |
| + if got := r.drive(t, run); got.State != "done" { |
| + t.Fatalf("initialize: %s %s", got.State, got.Code) |
| + } |
| + r.home.now = r.home.now.Add(homeop.WindowLifetime * time.Second) |
| + run, err = r.engine.CreateTeam(ctx, provision.NewTeam{Label: "lagged", Name: "Lagged", Owner: owner, Apps: apps}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.home.confirm(t, "directory", "") |
| + r.home.confirm(t, "credential", owner) |
| + if got := r.drive(t, run); got.State != "done" { |
| + t.Fatalf("create-team: %s %s", got.State, got.Code) |
| + } |
| + sealer, err := sharedseal.New(bytes.Repeat([]byte{6}, 32), "oficina/operator") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + store, err := directorydata.New(r.home.dirDB, sealer, directorydata.Config{Apps: apps, ValidateRoute: func(route directorydata.Route) bool { |
| + return route.Origin == "https://"+route.Label+"."+route.App+".oficina.works" |
| + }}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var subject string |
| + if err := r.home.dirDB.QueryRow("SELECT person_ref FROM memberships").Scan(&subject); err != nil { |
| + t.Fatal(err) |
| + } |
| + listed := func() map[string]directorydata.Choice { |
| + t.Helper() |
| + choices, err := store.AgentChoices(ctx, subject) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + out := map[string]directorydata.Choice{} |
| + for _, c := range choices { |
| + out[c.App] = c |
| + } |
| + return out |
| + } |
| + live := listed() |
| + if len(live) != len(apps) { |
| + t.Fatalf("Home lists %d apps", len(live)) |
| + } |
| + for _, slug := range apps { |
| + app, _ := provision.AppBySlug(slug) |
| + vars, _, _ := r.con.Env(slug, "lagged") |
| + if got := live[slug].Origin; got != provision.PublicOrigin("lagged", slug) { |
| + t.Fatalf("%s origin %q", slug, got) |
| + } |
| + if got := vars[app.Prefix+"_AGENT_TEAM"].Value; got == "" || got != live[slug].SQID { |
| + t.Fatalf("%s: Alta wrote team %q, Home lists %q", slug, got, live[slug].SQID) |
| + } |
| + if got := vars[app.Prefix+"_AGENT_ISSUER"].Value; got != provision.AgentIssuer { |
| + t.Fatalf("%s issuer %q", slug, got) |
| + } |
| + } |
| + r.home.now = r.home.now.Add(homeop.WindowLifetime * time.Second) |
| + run, err = r.engine.RetireApps(ctx, "lagged", []string{"calls"}, "lagged") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + r.home.confirm(t, "directory", "") |
| + r.home.confirm(t, "credential", "") |
| + if got := r.drive(t, run); got.State != "done" { |
| + t.Fatalf("retire: %s %s", got.State, got.Code) |
| + } |
| + after := listed() |
| + if _, ok := after["calls"]; ok || len(after) != len(apps)-1 { |
| + t.Fatalf("after retiring calls Home lists %d apps", len(after)) |
| + } |
| +} |
| + |
| // TestHomeRefusesWhatAltaMustNotDo checks the fences hold on Home's side |
| // for requests Alta signs correctly: no window, a label outside the |
| // window, an unknown owner. |
diff --git a/provision/agent_keys_test.go b/provision/agent_keys_test.go| new file mode 100644 |
| index 0000000..1e7a731 |
| --- /dev/null |
| +++ b/provision/agent_keys_test.go |
| @@ -0,0 +1,322 @@ |
| +package provision |
| + |
| +import ( |
| + "errors" |
| + "slices" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/alta/homeop" |
| +) |
| + |
| +func agentNames(app App) (string, string) { |
| + return app.Prefix + "_AGENT_ISSUER", app.Prefix + "_AGENT_TEAM" |
| +} |
| + |
| +func TestAgentIssuerIsTheConnectionService(t *testing.T) { |
| + if AgentIssuer != "https://connect.oficina.works" { |
| + t.Fatal(AgentIssuer) |
| + } |
| +} |
| + |
| +// Every app refuses to boot on one key alone (Memoria outright), so a recipe |
| +// holds both or neither, under every profile. |
| +func TestRecipeHoldsBothAgentKeysOrNeither(t *testing.T) { |
| + for _, app := range Apps { |
| + issuer, team := agentNames(app) |
| + for _, opt := range []RunOptions{{Profile: ProfileOutside}, {Profile: ProfileOwn}, {Profile: ProfileOutside, Samples: true}} { |
| + keys := map[string]Key{} |
| + for _, k := range Recipe(app, Inputs{Label: "acme", TeamSQID: "Tm1", AgentIssuer: AgentIssuer, RunOptions: opt}) { |
| + keys[k.Name] = k |
| + } |
| + if k := keys[issuer]; k.Class != Set || k.Secret || k.Value != AgentIssuer { |
| + t.Fatalf("%s: %+v", issuer, k) |
| + } |
| + if k := keys[team]; k.Class != Set || k.Secret || k.Value != "Tm1" { |
| + t.Fatalf("%s: %+v", team, k) |
| + } |
| + if keys[team].Value != keys[app.Prefix+"_TEAM_ID"].Value { |
| + t.Fatalf("%s: the agent team differs from the roster team", app.Slug) |
| + } |
| + } |
| + for name, in := range map[string]Inputs{ |
| + "no issuer": {Label: "acme", TeamSQID: "Tm1"}, |
| + "no team": {Label: "acme", AgentIssuer: AgentIssuer}, |
| + } { |
| + for _, k := range Recipe(app, in) { |
| + if k.Name == issuer || k.Name == team { |
| + t.Fatalf("%s %s: wrote %s", app.Slug, name, k.Name) |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| +func agentRun(t *testing.T) (*harness, *Engine) { |
| + t.Helper() |
| + h := newHarness(t) |
| + h.initialized() |
| + e := h.engine(nil) |
| + if r := h.drive(e, h.createLagged(e), 40); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + return h, e |
| +} |
| + |
| +func TestAProvisionedTeamHoldsBothAgentKeys(t *testing.T) { |
| + h, _ := agentRun(t) |
| + sqid := "" |
| + for _, app := range Apps { |
| + issuer, team := agentNames(app) |
| + vars, _, _ := h.con.Env(app.Slug, "lagged") |
| + if v := vars[issuer]; v.Kind != "env" || v.Value != AgentIssuer { |
| + t.Fatalf("%s: %+v", issuer, v) |
| + } |
| + v := vars[team] |
| + if v.Kind != "env" || v.Value == "" || v.Value != vars[app.Prefix+"_TEAM_ID"].Value { |
| + t.Fatalf("%s: %+v", team, v) |
| + } |
| + if sqid != "" && v.Value != sqid { |
| + t.Fatalf("%s: team %q, another app has %q", app.Slug, v.Value, sqid) |
| + } |
| + sqid = v.Value |
| + } |
| +} |
| + |
| +func TestBothAgentKeysGoInOneWrite(t *testing.T) { |
| + h, _ := agentRun(t) |
| + for _, app := range Apps { |
| + issuer, team := agentNames(app) |
| + writes := 0 |
| + for _, w := range h.con.ConfigWrites { |
| + hasIssuer, hasTeam := slices.Contains(w, issuer), slices.Contains(w, team) |
| + if hasIssuer != hasTeam { |
| + t.Fatalf("%s: one agent key written alone: %v", app.Slug, w) |
| + } |
| + if hasIssuer { |
| + writes++ |
| + } |
| + } |
| + if writes != 1 { |
| + t.Fatalf("%s: agent keys written %d times", app.Slug, writes) |
| + } |
| + } |
| +} |
| + |
| +func auditCode(t *testing.T, h *harness, e *Engine, app App) string { |
| + t.Helper() |
| + err := e.AuditEnvironment(h.ctx(), "lagged", app) |
| + if err == nil { |
| + return "" |
| + } |
| + var fl *Fail |
| + if !errors.As(err, &fl) { |
| + t.Fatalf("audit: %v", err) |
| + } |
| + return fl.Code |
| +} |
| + |
| +func TestAuditHoldsTheAgentKeysExactly(t *testing.T) { |
| + app, _ := AppBySlug("memoria") |
| + issuer, team := agentNames(app) |
| + for name, tc := range map[string]struct { |
| + change func(map[string]fakeVar) |
| + code string |
| + }{ |
| + "issuer missing": {func(v map[string]fakeVar) { delete(v, issuer) }, "audit-missing-key"}, |
| + "team missing": {func(v map[string]fakeVar) { delete(v, team) }, "audit-missing-key"}, |
| + "both missing": {func(v map[string]fakeVar) { delete(v, issuer); delete(v, team) }, "audit-missing-key"}, |
| + "wrong issuer": {func(v map[string]fakeVar) { v[issuer] = fakeVar{Kind: "env", Value: "https://elsewhere.example"} }, "audit-value"}, |
| + "wrong team": {func(v map[string]fakeVar) { v[team] = fakeVar{Kind: "env", Value: "Uk"} }, "audit-value"}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + h, e := agentRun(t) |
| + vars, owner, _ := h.con.Env(app.Slug, "lagged") |
| + tc.change(vars) |
| + h.con.SetEnv(app.Slug, "lagged", owner, vars) |
| + if got := auditCode(t, h, e, app); got != tc.code { |
| + t.Fatalf("audit %q, want %q", got, tc.code) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// writtenBeforeAgentKeys puts app's environment as the previous release left |
| +// it: step 7 done, neither key, nothing recorded about them. |
| +func writtenBeforeAgentKeys(t *testing.T, h *harness, app App) { |
| + t.Helper() |
| + issuer, team := agentNames(app) |
| + vars, owner, _ := h.con.Env(app.Slug, "lagged") |
| + delete(vars, issuer) |
| + delete(vars, team) |
| + h.con.SetEnv(app.Slug, "lagged", owner, vars) |
| + st, ok, err := h.store.Step(h.ctx(), "lagged", app.Slug, StepEnv) |
| + if err != nil || !ok { |
| + t.Fatalf("step 7: %v %v", ok, err) |
| + } |
| + delete(st.Data, "agent_access") |
| + if err := h.store.SetStep(h.ctx(), "lagged", app.Slug, StepEnv, "done", "", st.Data); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func TestAnEnvironmentWrittenBeforeTheKeysHoldsNeither(t *testing.T) { |
| + app, _ := AppBySlug("docs") |
| + issuer, team := agentNames(app) |
| + h, e := agentRun(t) |
| + writtenBeforeAgentKeys(t, h, app) |
| + if got := auditCode(t, h, e, app); got != "" { |
| + t.Fatalf("neither key: audit %q", got) |
| + } |
| + for name, extra := range map[string]map[string]fakeVar{ |
| + "issuer alone": {issuer: {Kind: "env", Value: AgentIssuer}}, |
| + "team alone": {team: {Kind: "env", Value: "Tm1"}}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + vars, owner, _ := h.con.Env(app.Slug, "lagged") |
| + for k, v := range extra { |
| + vars[k] = v |
| + } |
| + h.con.SetEnv(app.Slug, "lagged", owner, vars) |
| + if got := auditCode(t, h, e, app); got != "audit-extra-key" { |
| + t.Fatalf("audit %q", got) |
| + } |
| + for k := range extra { |
| + delete(vars, k) |
| + } |
| + h.con.SetEnv(app.Slug, "lagged", owner, vars) |
| + }) |
| + } |
| +} |
| + |
| +// crashAtAct runs a create-team until the named act, then stops the process. |
| +func crashAtAct(t *testing.T, h *harness, act string) int64 { |
| + t.Helper() |
| + crashed := false |
| + e := h.engine(func(k string) error { |
| + if k == act && !crashed { |
| + crashed = true |
| + return errors.New("kill -9") |
| + } |
| + return nil |
| + }) |
| + run := h.createLagged(e) |
| + for i := 0; i < 40 && !crashed; i++ { |
| + _ = e.Advance(h.ctx(), run) |
| + h.con.Walk() |
| + h.tick(5 * time.Second) |
| + } |
| + if !crashed { |
| + t.Fatalf("act %s never reached", act) |
| + } |
| + h.tick(11 * time.Minute) |
| + return run |
| +} |
| + |
| +// The old release wrote docs' environment and died before recording step 7: |
| +// the step is not done, so this release finishes it with the keys. |
| +func TestARunCaughtBeforeStep7GetsTheKeys(t *testing.T) { |
| + app, _ := AppBySlug("docs") |
| + issuer, team := agentNames(app) |
| + h := newHarness(t) |
| + h.initialized() |
| + run := crashAtAct(t, h, "env-generate/docs") |
| + vars, owner, _ := h.con.Env(app.Slug, "lagged") |
| + delete(vars, issuer) |
| + delete(vars, team) |
| + h.con.SetEnv(app.Slug, "lagged", owner, vars) |
| + e := h.engine(nil) |
| + if r := h.drive(e, run, 40); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + vars, _, _ = h.con.Env(app.Slug, "lagged") |
| + if vars[issuer].Value != AgentIssuer || vars[team].Value == "" { |
| + t.Fatalf("keys not written: %+v %+v", vars[issuer], vars[team]) |
| + } |
| + if got := auditCode(t, h, e, app); got != "" { |
| + t.Fatalf("audit %q", got) |
| + } |
| +} |
| + |
| +// Step 7 already done by the old release: the environment is never rewritten |
| +// and the run still finishes. |
| +func TestARunCaughtAfterStep7KeepsItsEnvironment(t *testing.T) { |
| + app, _ := AppBySlug("docs") |
| + issuer, team := agentNames(app) |
| + h := newHarness(t) |
| + h.initialized() |
| + run := crashAtAct(t, h, "instance/docs") |
| + writtenBeforeAgentKeys(t, h, app) |
| + e := h.engine(nil) |
| + if r := h.drive(e, run, 40); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + vars, _, _ := h.con.Env(app.Slug, "lagged") |
| + if _, ok := vars[issuer]; ok { |
| + t.Fatal("a written environment was rewritten") |
| + } |
| + if _, ok := vars[team]; ok { |
| + t.Fatal("a written environment was rewritten") |
| + } |
| +} |
| + |
| +// A fork of an adopted environment carries the source team's agent keys. The |
| +// new team's own values replace them. |
| +func TestAForkedEnvironmentTakesTheNewTeamsAgentKeys(t *testing.T) { |
| + h := newHarness(t) |
| + h.initialized() |
| + h.con.SetEnv("memoria", "lagged-team", "alta", map[string]fakeVar{ |
| + "MEMORIA_DEK": {Kind: "secret", Envelope: sealFor(t, h, "memoria", "till-data-key")}, |
| + "MEMORIA_INSTANCE_KEY": {Kind: "secret", Envelope: sealFor(t, h, "memoria", "instance")}, |
| + "MEMORIA_AGENT_ISSUER": {Kind: "env", Value: "https://elsewhere.example"}, |
| + "MEMORIA_AGENT_TEAM": {Kind: "env", Value: "Uk"}, |
| + }) |
| + h.con.AddInstance("memoria", RouteHost("lagged", "memoria", account), "lagged-team") |
| + h.con.AddClaim("memoria", PublicHost("lagged", "memoria"), RouteHost("lagged", "memoria", account), "live") |
| + e := h.engine(nil) |
| + run, err := e.CreateTeam(h.ctx(), NewTeam{Label: "lagged", Name: "Lagged", Owner: ownerCanary, Apps: []string{"memoria"}, Forked: true}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h.confirm(homeop.KindCreateTeam) |
| + if r := h.drive(e, run, 20); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + vars, _, _ := h.con.Env("memoria", "lagged-team") |
| + if vars["MEMORIA_AGENT_ISSUER"].Value != AgentIssuer || vars["MEMORIA_AGENT_TEAM"].Value != vars["MEMORIA_TEAM_ID"].Value || vars["MEMORIA_AGENT_TEAM"].Value == "Uk" { |
| + t.Fatalf("%+v %+v", vars["MEMORIA_AGENT_ISSUER"], vars["MEMORIA_AGENT_TEAM"]) |
| + } |
| +} |
| + |
| +// Access ends at Home, first: by the time the hostname or the instance is |
| +// touched, the directory no longer lists the app. |
| +func TestRetireEndsAccessAtHomeBeforeAnythingElse(t *testing.T) { |
| + h, _ := agentRun(t) |
| + h.tick(homeop.WindowLifetime * time.Second) |
| + seen := []string{} |
| + e := h.engine(func(k string) error { |
| + if strings.HasPrefix(k, "detach/") || strings.HasPrefix(k, "delete/") { |
| + slug := k[strings.Index(k, "/")+1:] |
| + seen = append(seen, k) |
| + if got := h.home.InstanceState(ConsumerID("lagged", slug)); got != "disabled" { |
| + t.Errorf("%s while the directory says %q", k, got) |
| + } |
| + } |
| + return nil |
| + }) |
| + ret, err := e.RetireApps(h.ctx(), "lagged", []string{"docs", "calls"}, "lagged") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + h.confirm(homeop.KindRetireApps) |
| + if r := h.drive(e, ret, 10); r.State != "done" { |
| + t.Fatalf("%s %s", r.State, r.Code) |
| + } |
| + if len(seen) != 4 { |
| + t.Fatalf("acts %v", seen) |
| + } |
| + if got := h.home.InstanceState(ConsumerID("lagged", "sheets")); got != "live" { |
| + t.Fatalf("sheets went with them: %q", got) |
| + } |
| +} |
diff --git a/provision/apps.go b/provision/apps.go| index b6b26da..f35271f 100644 |
| --- a/provision/apps.go |
| +++ b/provision/apps.go |
| @@ -56,6 +56,11 @@ func LabelRefusal(label string) string { |
| // team instance (internal/home directoryRouteAllowed). |
| const PublicDomain = "oficina.works" |
| +// AgentIssuer is the connection service a team's apps trust for delegated |
| +// agent access (oficina-connect). It is public, and the same issuer the |
| +// adoption runner writes for the suite's canonical apps (adopt.Issuer). |
| +const AgentIssuer = "https://connect." + PublicDomain |
| + |
| // App is one Oficina app as Alta provisions it: the env prefix it reads, |
| // whether it has roster mode, which SMTP prefixes its binary reads, and |
| // whether it needs the platform relay. |
| @@ -245,6 +250,10 @@ type Inputs struct { |
| Record []byte // step 5's signed record (Docs) |
| Home HomeConfig |
| CallsZone string |
| + // AgentIssuer is the connection issuer this environment is written |
| + // with. Empty for an environment written before Alta wrote the agent |
| + // keys: a written environment is never rewritten. |
| + AgentIssuer string |
| // RunOptions is the run's profile and samples choice. The zero value |
| // is the outside recipe without samples. |
| RunOptions |
| @@ -338,7 +347,20 @@ func Recipe(app App, in Inputs) []Key { |
| ) |
| keys = append(keys, teamKeys(p, in)...) |
| } |
| - return keys |
| + return append(keys, agentKeys(p, in)...) |
| +} |
| + |
| +// agentKeys is <P>_AGENT_ISSUER and <P>_AGENT_TEAM, both or neither: every |
| +// app refuses to start on one alone. The team is Home's sqid, the value the |
| +// roster-mode apps also require of <P>_TEAM_ID. Both are public. |
| +func agentKeys(p string, in Inputs) []Key { |
| + if in.AgentIssuer == "" || in.TeamSQID == "" { |
| + return nil |
| + } |
| + return []Key{ |
| + {Name: p + "_AGENT_ISSUER", Class: Set, Value: in.AgentIssuer}, |
| + {Name: p + "_AGENT_TEAM", Class: Set, Value: in.TeamSQID}, |
| + } |
| } |
| func qualityReports(own bool) string { |
diff --git a/provision/steps.go b/provision/steps.go| index 8e61a48..fa1c102 100644 |
| --- a/provision/steps.go |
| +++ b/provision/steps.go |
| @@ -413,7 +413,14 @@ func (e *Engine) stepRegister(ctx context.Context, p *pass, app App) error { |
| // ---- step 7: environment ---- |
| func (e *Engine) inputs(ctx context.Context, p *pass, app App) (Inputs, error) { |
| - in := Inputs{Label: p.run.Label, TeamSQID: p.team.TeamSQID, Home: e.cfg.HomeCfg, CallsZone: e.cfg.CallsZone, RunOptions: p.run.Options} |
| + in := Inputs{Label: p.run.Label, TeamSQID: p.team.TeamSQID, Home: e.cfg.HomeCfg, CallsZone: e.cfg.CallsZone, AgentIssuer: AgentIssuer, RunOptions: p.run.Options} |
| + // A written environment is never rewritten: one step 7 finished before |
| + // Alta wrote the agent keys stays without them, and is audited that way. |
| + if d, written, err := e.cfg.Store.Done(ctx, p.run.Label, app.Slug, StepEnv); err != nil { |
| + return in, err |
| + } else if held, _ := d["agent_access"].(bool); written && !held { |
| + in.AgentIssuer = "" |
| + } |
| if owner, ok, err := e.cfg.Store.Owner(ctx, p.run.Label); err != nil { |
| return in, err |
| } else if ok { |
| @@ -574,7 +581,7 @@ func (e *Engine) stepEnv(ctx context.Context, p *pass, app App) error { |
| return park("awaiting-platform-keys") |
| } |
| return e.record(ctx, p, app.Slug, StepEnv, map[string]any{"platform": ps.Keys, "binding": EnvironmentBinding(env, keys, ps.Keys), |
| - "profile": string(in.Profile), "samples": in.Samples}) |
| + "profile": string(in.Profile), "samples": in.Samples, "agent_access": len(agentKeys(app.Prefix, in)) > 0}) |
| } |
| // ---- step 8: instance ---- |