Labs run with no service account, so one lab cannot reach another
Closes #48 (closed)
Every lab VM ran as the shared sim-lab-vm account with cloud-platform scope. From inside any lab, that account could delete and read every other lab in the project. This change removes that reach and keeps automatic cleanup.
Design
- A single lab has no service account, no scopes and no metadata token. When idle for 30 minutes it powers itself off. GCE deletes it at its max run (
--max-run-durationwith--instance-termination-action=DELETE). - A rig of two or more members (
--rigwith--rig-members, set by geo) gets one account per rig,sim-rig-<hash of owner and rig id>. It holds a custom role (instances.delete, getGuestAttributes) bound on each member instance, with no project-level role and no list permission. Members find peers through thesim-rig-membersinstance metadata attribute. SIM_LAB_SERVICE_ACCOUNT=sharedopts in to the old project-wide account. It stays only for the Bedrock federation (thesubpin and identity token) and the Vertex arm.SIM_LAB_SERVICE_ACCOUNT=nonegives no lab an account, a rig included. Its members then never power off alone, and only the max run ends them. A rig account is refused for Vertex and Bedrock.- The rig account is released by
down,down --keep-snapshotand reap once no node of the rig is left; reap does so only for the records the operator holds. Its description records the owner and a creation time for a person reading the console. There is no project-wide sweep: an account a killed run left behind is released by the nextdown, and one left over holds no permissions and no keys, so it costs only quota. Restore re-ensures it, and the phase stayssuspendeduntil the VM exists. - Create records the instance id, a harmless record of which VM the lab made. Reap does not delete a powered-off lab: a TERMINATED VM is left alone and logged as such, and GCE's max run deletes it, as measured below. An earlier round of this MR had reap delete a TERMINATED lab past its
expires_at; each hardening of that path found another way for a name-keyeddownto delete another owner's VM or a suspended rig's snapshot, so it is removed anddowntakes no--vm-id. - Preflight with
--rigchecksiam.roles.create,iam.serviceAccounts.create,compute.instances.setIamPolicyandiam.serviceAccounts.actAs. A--rig-memberslist of one name is a single lab. - ADR 0006 carries the decision in its existing amendment (new Identity section).
Measured: a guest-initiated poweroff leaves the VM TERMINATED, and GCE still deleted it about 2 seconds after the max-run deadline, although the docs say a stop clears the deadline. An API start resets the timer, so the TTL holds for guest stops only.
flowchart TB
up["up creates a lab"] --> single{"rig of two or more?"}
single -- "no, the default" --> none["no service account, no scope, no token"]
single -- "yes" --> mode{"SIM_LAB_SERVICE_ACCOUNT=none?"}
mode -- "no" --> rigacct["one account per owner and rig, instance-level delete and guest read on its members only"]
mode -- "yes" --> rignone["no account: members stay up when idle, max run ends them"]
rignone --> ttl
up -. "SIM_LAB_SERVICE_ACCOUNT=shared" .-> shared["project-wide sim-lab-vm, kept for Bedrock and Vertex"]
none --> ttl["GCE max-run-duration, termination action DELETE"]
none --> idle["idle 30 min: guest powers off, compute billing stops"]
idle --> ttl
rigacct --> ttl
rigacct --> rigidle["every member idle: members delete each other through the account"]
ttl --> gone["instance and disk deleted by GCE"]
rigidle --> gone
down["down, down --keep-snapshot, reap"] --> release["rig account released when no member is left, for the records this operator holds"]
reap["reap leaves a powered-off lab alone"] -.-> ttlThreat matrix
| # | Cell | Proof | Result |
|---|---|---|---|
| 1 | A default VM has no account, or only its scoped one | lab-identity-selftest.sh, engine-selftest.sh, preflight-selftest.sh fail without the control |
pass |
| 2 | From lab A, describe or delete of lab B fails | Live: default lab has no token and gets 401 on describe and delete of another lab. Rig account gets 403 on describe, guest read, list and delete of non-members, and 200 on its own member only | pass |
| 3 | A lab deletes itself at its TTL | Live: guest-stopped VM still deleted by GCE about 2 s after the deadline | pass |
| 4 | The idle path ends compute cost | Live: guest poweroff leaves TERMINATED, billing stops. idle-delete-selftest.sh covers the script path with a poweroff stub. A live run of the timer was blocked by lingering ssh sessions, which the idle check treats as busy by design |
pass, script path by selftest |
| 5 | Restore, geo, two-plane, praefect and openshift creators get the same treatment | provider-selftest.sh, engine-selftest.sh (every creator passes identity=none or the rig account) |
pass |
| 6 | Nothing printed contains a token | idle-delete-selftest.sh no-token check, probe scripts print only the HTTP code |
pass |
| 7 | none means no account for a rig either, and an owner never shares another's rig account |
engine-selftest.sh, idle-delete-selftest.sh, lab-identity-selftest.sh, preflight-selftest.sh; live: up under none left a VM with no service account |
pass |
| 8 | Reap never deletes a powered-off lab, so no name-keyed delete can reach another owner's VM or a suspended rig's snapshot | engine-selftest.sh: a TERMINATED lab past its expires_at makes no delete call in the cloud and keeps its record; red when reap deletes it again. down has no --vm-id. Removal, so no live arm |
pass |
| 9 | Reap never deletes a rig account it holds no record for | There is no sweep to test: lab-identity.sh has no sweep, and engine-selftest.sh checks that reap lists no service account and releases only the account of a record it holds (a node left keeps it; a lab outside a rig touches none); red when a listing returns. Live: the rig account's description read sim-rig owner=lid-fix2 created=<epoch>, and reap as another owner left it in place |
pass |
Two defects found by the live run and fixed here: concurrent rig members raced on creating the rig account (the loser now polls and retries), and a rig account cannot call testIamPermissions without project list, so the idle check falls back to reading its own guest attributes.
Teardown: no instance, disk, snapshot, service account or IAM binding matching sim-lid or sim-rig remains. The shared sim-lab-vm account is untouched.
Not merged: this changes a trust boundary and waits for the review.
AI-Assisted: yes