Design review, round 1: implementation/team-scoped-credentials.md @ ce9cb27
Reviewer: Claude Fable 5.1 (claude-fable-5-1), reviewing the document against the code on main 57aec0a (the branch adds no code). Read: internal/svcrole/svcrole.go, internal/console/{authcli.go,svcprincipal.go,deployscope.go,apicli.go,apiconfig.go,apiinstances.go,apidomains.go,apirestartscope.go,apiservices.go,controlplane.go}, internal/appconfig/{environments.go,materialize.go,sync.go,syncexec.go,agentvars.go,appconfig.go,store.go}, internal/host/units/carlos-app@.service, svcroutes_test.go. Round budget per AGENTS.md stopping rule 1: this is round 1; it has P1s, so one more round is owed after the fixes.
Verdict: CHANGES REQUIRED (template: NOT READY)
The shape is right: a scope on the credential, one deciding function, a separate registration path that plain cliRoute cannot admit, 404 parity. The direction should be kept. But the document's central promise, "it never reaches the default bundle", is true at the API and false at runtime, and the scope model can be captured through an environment name. Both are P1 and both have concrete fixes.
BLOCKERS (P1)
1. §3/§4 — A tenant instance receives the whole default bundle, secrets included, at runtime. loadMergedETags (internal/appconfig/environments.go:200-247) renders a bound route as default overlaid by the environment; sync.go:159 and syncexec.go:375 call LoadMerged for every route, and RenderEnv (materialize.go) decrypts every secret in the merged manifest onto the box as /etc/carlos/apps/<host>.env. So every instance Alta creates runs with Paul's email allowlists, SMTP/API/OIDC secrets and anything else in config.json, minus only the keys the environment happens to override. The document concedes this ("key names only... so the caller can audit what an instance inherits") and then treats it as an audit problem. It is not: the tenant controls the other variables of the same process. No code ship is needed to exfiltrate: set SMTP_HOST, an S3/OIDC/API endpoint, HTTP_PROXY/HTTPS_PROXY, NODE_OPTIONS, GODEBUG, etc. in the tenant environment, restart (an in-scope verb), and the app hands the inherited credential to a host the tenant chose. ValidVarName (appconfig.go:138) and agentOwned (agentvars.go, only CARLOS_PURGE/CARLOS_CONTROL_SOCKET) stop none of that. This is exactly the hole Paul's ruling closes ("never touch... any instance bound to the default bundle" was meant to protect his secrets, not the bundle object).
Fix. A bundle carrying owner_scope is standalone: loadMergedETags must not fold the default bundle into it (if env.OwnerScope != "" { skip def }), so a tenant-owned environment renders from itself alone, and AwaitingRestart / checkOptedIn follow the same rule (no inherited exec_delivery either). internal/appconfig is in the root binary, so this is a census card (§8.10 already says so). Because an older box still overlays, the console must refuse to create or rebind a tenant instance unless every box of the placement runs the floor version (the rootfs precedent, RFS-4-C139/C140 in apimode_rootfs.go), and the doc must say which version is the floor. Add to §8: a render-layer test, not a GET-body one: a canary secret in the default bundle, a tenant environment bound to a route, RenderEnv(LoadMerged(...)) must not contain the canary; and a mutation test that removing the standalone branch fails it. With this, open question 3 answers itself: there is nothing to audit, and names need not be exposed (names alone are not harmless either; they are the var list the attack above starts from). If a team genuinely needs a shared value (a keymail client id, say), the owner copies it into the environment, or a later slice adds an explicit per-key "inheritable" mark on the default bundle; do not ship inheritance-by-default.
2. §3 — Scope can be captured through an environment name that is referenced before it exists. "In scope iff the bundle carries owner_scope" plus "a tenant's first PUT /config on a name that does not exist creates it with owner_scope" leaves two ways for a tenant to own an environment Paul's instance reads:
- A record may be bound to an environment that has never been created: the API's only rail is shape (
provision.ValidateShape,provision.go:721; PATCH atapiinstances.go:2297setsrec.Environmentwith no existence check), andLoadMergedhas a dedicated error for the state ("bound but never created",environments.go:230). Ifslice3is bound to Paul's instance before anyone runscarlos env set --environment slice3, the tenant createsslice3, owns it, and Paul's instance is now in scope: config, restart,DELETE. - Under the private-storage policy, a create with no environment derives one from the host slug (
apiinstances.go:1757-1776); a tenant that pre-creates the environment named for a host the owner is about to create owns the owner's instance.
Fix. The tenant create path must take the app record lock (withRecordLock) and refuse any name that any record of the app references (listRecords) or that any bundle already holds, then do the conditional create; and the person-side doors must make binding into a tenant-owned environment an explicit act. POST /instances and PATCH with environment naming an owned environment should refuse for a person unless a scope field (or --scope) names it, so "only adoption puts things in scope" becomes true (today a person's PATCH silently hands an instance to the scope). State both in §3 and add them to §8.7 (races) and §8.8.
Required changes (P2; fixed without reopening the review)
3. §4 refusal shape — the narrowed restart door lists the whole app. resolveRestartScope (apirestartscope.go) answers a miss with every host or environment the app has on this box ("no route X on this app — this console's box serves a, b, c"; "no route of this app reads environment E — this console's box has ..."), as a 400. For a tenant the candidate set mine must be filtered to in-scope routes before resolution, and the refusal must be the same bytes as an unknown target. Likewise GET /config always returns environments (every name of the app, apiconfig.go:206-213); filter to owned names. POST /instances refusals name sibling apps and host holders (hostHeldSentence, the apex 409s); say in §4 that these are the instance role's existing oracle and are accepted, or pin them.
4. §4 door table is not the whole surface. Default-deny (cliRoute panics on a Set permitting Tenant) makes the omissions closed, which is correct, but the table is also what TestEveryTenantDoorIsScoped pins against, and it should be exhaustive like TestInstanceRoleMatchesTodaysAppTokenReach. Not listed: PUT /domains/{host}/paths, GET /regions, POST /regions/guess, GET /assets, GET /edge-refs/{code}, GET /availability, GET /geo, PUT /telemetry (an app-wide write Operate holds today), GET/POST /schedules and /schedules/{name}/run|delete (app-wide, Operate), POST /instances/{host}/gate-pass, GET /instances/{host}/rate-limit, GET /apps. Add a TestTenantRoleReach with the exact set (the table) and say "closed" per row. Also say which PATCH fields a tenant may send: environment (owned, never ""), probe, gate, rate_limit, assets, addrs, steering; addrs repoints the proxy upstream of a hostname under the app's domain, which the threat model in §7 should name alongside hostname squatting (consider limiting tenant creates to socket-backed kinds: DerivesPaths() true, no addrs, no static).
5. §2/§4 — how a tenant door's Set is built. Allow panics on Tenant and Exactly is "not used", so cliScopedRoute(pattern, allow svcrole.Set, ...) cannot receive a Set that permits Tenant. Specify the constructor (allow is the non-tenant set; the wrapper records allow ∪ {Tenant} in s.cliRoles so doorsFor (apiservices.go:145) and the source scan in svcroutes_test.go see it) and that the scope check runs after the role gate and after apiAccountApp's app binding (so 403/404 ordering stays constant). Also state that a claim with Route == "" (first-route/static claim) is out of scope by definition, so DELETE /domains/{host} cannot retire a record through the alias door.
6. §3/§9 — ownership has no release. There is no environment delete verb in appconfig (no DeleteEnvironment), so an owner_scope once written is permanent, and the scope string is the authority: any later credential minted with --scope alta inherits every environment. Add carlos env release (person-only, clears owner_scope) beside adopt, and say in §5/§7 that revoking a credential does not release its environments and that scope names are owner-chosen capabilities. Note too that adoption of a hand-made lagged environment under fix 1 changes its runtime config (it stops inheriting the default bundle), so adopt must either copy the inherited keys in explicitly or refuse while the environment relies on inherited keys; recreating under Alta is cleaner (open question 2).
7. §8.5 lists — GET /instances returns total, counts and next_cursor (apiinstances.go:983-1031); the filter must run before all three are computed, which §8.5 should say.
Non-blocking notes (P3)
- §6 audit: today's actor string is
service:<sqid>/<name>(auditActor,apicli.go);RecordActivitycarries no role or scope. Either add them toDetailor state that name →services list→ scope is the audit path. - An older CLI in bucket mode (
CARLOS_DEPLOYMENT_BUCKET) rewriting a bundle dropsowner_scope(json.Unmarshaldrops unknown fields,store.go:77). Fail-closed direction (the tenant loses access), but it silently un-adopts; worth a line. - §5 "the CLI needs no new mode": verify
carlos secrets set --environment Eunder a service token fetchessecrets_pubkeyfromGET /config?environment=E(apimode.go:489 does send the parameter), not from the default-bundle GET the tenant will 404 on. - Open question 1: "tenant" already means "an app on a box" throughout the host code (
carlos-app@.service"the tenant template",agentvars.go"tenant-supplied");teamorscopedavoids two meanings for one word in the same binary. Rotation keeps it(§3): sayscopeis stored likerungsand thatCLIPrincipalrefuses a tenant row with an unreadable or empty scope and a scope on any other role, mirroringsvcprincipal.go:146-167.
Open questions, my answers
- Prefer
team; see the note above. - Keep
adoptbut pair it withrelease, and under fix 1 make Alta recreatelaggedrather than adopt it. - No. With standalone rendering there is nothing inherited to audit; without it, names are not a mitigation.