svcrole: platform role, outside Admin, reachable only through Exactly
Add const Platform Role = "platform", placed in the catalogue just before Admin so All() keeps Admin last. Allow(Platform) panics and names Exactly(Platform), following Run's pattern, so no door that admits Admin can admit Platform. Admin's comment now reads "every role except Run, Team and Platform". Tests cover the catalogue, the Allow refusal and Exactly(Platform) admitting only Platform.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/svcrole/svcrole.go+23 −8internal/svcrole/svcrole_test.go+62 −4
Intent
<task-notification> <task-id>aab5a71d2f20dc45d</task-id> <tool-use-id>toolu_0181qWtFNPHA9APF1keuq9Mz</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9284fe97-c7c7-4e03-80f2-87c51eb0406d/tasks/aab5a71d2f20dc45d.output</output-file> <status>completed</status> <summary>Agent "Implement Task 2: manifest link" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status: DONE** **Commit:** fa833a50 domains: platform link fields in the account manifest **Tests:** The seven new tests from the brief failed first because the new code didn't exist yet, then passed, along with the existing mint, next-id, tombstone and reserved-sqid tests (18 pass). Run with `go test ./internal/domains/ -run '...' -count=1`; `gofmt` and `go vet` are clean. Go commands ran with the sandbox off because the sandbox makes the default Go cache read-only; the cache location was left at its default. **What was built:** Every name and signature in the brief's Interfaces block is used as written: - The three link fields, all omitempty. A test pins the exact JSON of a manifest with no link, so it stays byte-identical to today. - `MintLinkedAccount`, which can safely be called twice with the same mint id: it returns the account the first call made instead of minting another. - `RenameAccountManifest` and `ErrBadPlatformLink`. `NextAccountID` and `MintAccount` now share `scanManifests` and `mint`, and their exported signatures are unchanged. **Concerns:** 1. **Mint ids must be lowercase hex.** That matches what the console's `newCredentialID` produces; uppercase is refused and a test pins it. 2. **Task 5 can't reach the check.** Its brief says to apply "the same checks as `MintLinkedAccount`", but the 32-hex check is unexported, so `internal/console` can't call it. Task 5 will either copy it or need an exported `domains.ValidPlatformLink`. I didn't add that because it isn't in the contract. 3. **`ErrBadPlatformLink` text isn't copy.** "domains: bad platform link" is an internal error string and isn't in the copy table, so the console should map it to its own copy rather than show it to people. 4. **Git lock warning.** Git printed a `packed-refs.lock` warning after the commit, but the commit and branch ref both landed and the tree is clean. I left the lock alone. 5. **Report file not committed.** `task-2-report.md` is written but uncommitted; only the brief's two Go files went into the commit. Report: /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-platform-accounts/.superpowers/sdd/2026-11-19-platform-accounts-1-platform-layer/task-2-report.md</result> <usage><subagent_tokens>82125</subagent_tokens><tool_uses>18</tool_uses><duration_ms>208055</duration_ms></usage> </task-notification>
<task-notification> <task-id>bstaboter</task-id> <tool-use-id>toolu_011vGShSLK7ohWNuCvvVqAYf</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9284fe97-c7c7-4e03-80f2-87c51eb0406d/tasks/bstaboter.output</output-file> <status>completed</status> <summary>Background command "Ledger Task 2 and run its Astra review" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 13.8 g CO₂e (1,716,751 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-platform-accounts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/svcrole/svcrole.go b/internal/svcrole/svcrole.go| index b4af58747..0f8a27a45 100644 |
| --- a/internal/svcrole/svcrole.go |
| +++ b/internal/svcrole/svcrole.go |
| @@ -71,16 +71,25 @@ const ( |
| // plain registration can admit it and Admin's union never carries it |
| // (implementation/team-scoped-credentials.md §2). |
| Team Role = "team" |
| - // Admin is the union of every role except Run and Team, plus ledgers, |
| - // store and place. It is NOT "everything harmless": store grant mints a |
| - // path-scoped IAM user, which is a real handover. Run is reachable only |
| - // through Exactly, and Team only through Scoped, so an Admin principal |
| - // cannot start a run or act inside a team's scope by being Admin. |
| + // Platform is a platform account's credential: it creates customer |
| + // accounts linked to its platform account and mints short-lived |
| + // credentials for them. It is deliberately outside the union Admin |
| + // stands for: Admin service credentials do not reach platform doors. |
| + // Allow refuses it (it panics), because every Allow set carries Admin; |
| + // a door admits it only by being registered through Exactly(Platform) |
| + // (spec 2026-11-19-platform-accounts-design.md). |
| + Platform Role = "platform" |
| + // Admin is the union of every role except Run, Team and Platform, plus |
| + // ledgers, store and place. It is NOT "everything harmless": store grant |
| + // mints a path-scoped IAM user, which is a real handover. Run and |
| + // Platform are reachable only through Exactly, and Team only through |
| + // Scoped, so an Admin principal cannot start a run, act for a platform |
| + // account, or act inside a team's scope by being Admin. |
| Admin Role = "admin" |
| ) |
| // catalogue is the whole vocabulary, in the order All returns it. |
| -var catalogue = []Role{Publish, Deploy, Instance, Operate, Service, Run, Team, Admin} |
| +var catalogue = []Role{Publish, Deploy, Instance, Operate, Service, Run, Team, Platform, Admin} |
| // All returns the catalogue. The slice is copied so a caller cannot edit the |
| // vocabulary by writing through it. |
| @@ -145,6 +154,12 @@ func Allow(roles ...Role) Set { |
| // to prevent. Fail loud at registration, like a typo. |
| panic("svcrole: Allow called with the run role, which Admin must not reach; use Exactly(Run)") |
| } |
| + if r == Platform { |
| + // Same cut as Run's: Allow(Platform) would let an administrator |
| + // through a platform door, and Admin service credentials must |
| + // not reach those. |
| + panic("svcrole: Allow called with the platform role, which Admin must not reach; use Exactly(Platform)") |
| + } |
| if r == Team { |
| // A team door is a scoped door: the console's cliScopedRoute |
| // is the only registration that may admit Team, because it is |
| @@ -160,8 +175,8 @@ func Allow(roles ...Role) Set { |
| } |
| // Exactly builds the Set for a door that admits ONLY the roles listed. Unlike |
| -// Allow it does not add Admin: this is how a role outside Admin's union (Run) |
| -// is granted to a door, and how a door says "no administrator either". |
| +// Allow it does not add Admin: this is how a role outside Admin's union (Run, |
| +// Platform) is granted to a door, and how a door says "no administrator either". |
| // |
| // Like Allow, it panics on an unparseable role, for the same reason: a |
| // dropped role would be a door silently narrowed. Called with no arguments it |
diff --git a/internal/svcrole/svcrole_test.go b/internal/svcrole/svcrole_test.go| index 142d07542..041d6fe82 100644 |
| --- a/internal/svcrole/svcrole_test.go |
| +++ b/internal/svcrole/svcrole_test.go |
| @@ -2,6 +2,7 @@ package svcrole |
| import ( |
| "reflect" |
| + "slices" |
| "strings" |
| "testing" |
| ) |
| @@ -33,10 +34,12 @@ func TestAdminPermitsEveryNonEmptySet(t *testing.T) { |
| t.Errorf("Allow(%v).Permits(Admin) = false; want true", s.Roles()) |
| } |
| } |
| - // Admin is the union of every role EXCEPT Run, so an Allow set never |
| - // carries Run on Admin's account either. |
| - if Allow(Publish).Permits(Run) { |
| - t.Error("Allow(Publish).Permits(Run) = true; want false") |
| + // Admin is the union of every role EXCEPT Run, Team and Platform, so an |
| + // Allow set never carries them on Admin's account either. |
| + for _, r := range []Role{Run, Team, Platform} { |
| + if Allow(Publish).Permits(r) || Allow(Admin).Permits(r) { |
| + t.Errorf("an Allow set permits %q; want false", r) |
| + } |
| } |
| } |
| @@ -304,3 +307,58 @@ func TestScopedIsAllowPlusTeam(t *testing.T) { |
| t.Error("Scoped edited its argument") |
| } |
| } |
| + |
| +// The platform role (spec 2026-11-19-platform-accounts-design.md): in the |
| +// catalogue, outside Admin's union, refused by Allow, and admitted only by a |
| +// door registered through Exactly(Platform). |
| +func TestPlatformIsInTheCatalogueAndOutsideAdminsUnion(t *testing.T) { |
| + got, ok := Parse("platform") |
| + if !ok || got != Platform { |
| + t.Fatalf(`Parse("platform") = %q, %v; want %q, true`, got, ok, Platform) |
| + } |
| + if !slices.Contains(All(), Platform) { |
| + t.Errorf("All() = %v; want it to contain platform", All()) |
| + } |
| + if all := All(); all[len(all)-1] != Admin { |
| + t.Errorf("All() = %v; want admin last", all) |
| + } |
| + if Exactly(Platform).Permits(Admin) { |
| + t.Error("Exactly(Platform).Permits(Admin) = true; want false") |
| + } |
| + if Allow(Publish).Permits(Platform) { |
| + t.Error("Allow(Publish).Permits(Platform) = true; want false") |
| + } |
| +} |
| + |
| +func TestAllowRefusesPlatform(t *testing.T) { |
| + // Every Allow set carries Admin, so Allow(Platform) would hand Admin a |
| + // platform door. Both the bare and the mixed form must panic, and name |
| + // Exactly. |
| + for _, roles := range [][]Role{{Platform}, {Publish, Platform}, {Platform, Operate}} { |
| + func() { |
| + defer func() { |
| + got := recover() |
| + if got == nil { |
| + t.Errorf("Allow(%v) did not panic", roles) |
| + return |
| + } |
| + if msg, _ := got.(string); !strings.Contains(msg, "Exactly(Platform)") { |
| + t.Errorf("Allow(%v) panic = %v; want it to say to use Exactly(Platform)", roles, got) |
| + } |
| + }() |
| + Allow(roles...) |
| + }() |
| + } |
| +} |
| + |
| +func TestExactlyPlatformAdmitsOnlyPlatform(t *testing.T) { |
| + s := Exactly(Platform) |
| + for _, r := range All() { |
| + if got, want := s.Permits(r), r == Platform; got != want { |
| + t.Errorf("Exactly(Platform).Permits(%q) = %v; want %v", r, got, want) |
| + } |
| + } |
| + if got := s.Roles(); !reflect.DeepEqual(got, []Role{Platform}) { |
| + t.Errorf("Exactly(Platform).Roles() = %v; want [platform]", got) |
| + } |
| +} |