Report when the VM's service account cannot delete its own instance

Defect

A rig deletes itself after 30 idle minutes by calling the compute API with the VM's own service account. That needs compute.instances.delete on the project, which today means the default compute account's Editor role. Nothing checked it, so a project without the permission gave a rig whose idle timer did nothing and only the max run ended it.

Fix

The test is testIamPermissions for compute.instances.delete, made as the VM's service account, because a call by the operator would test the wrong identity. Nothing here changes IAM.

  • On the VM. The idle timer's first run (it fires two minutes after boot, busy or not) makes the call with the metadata-server token and writes granted, missing or unknown to the guest attribute idle/self-delete. An error or empty answer is unknown and is retried on the next run; granted and missing are remembered.
  • up. After startup it reads that attribute and logs the answer. A missing permission, an unknown answer or no report logs a conspicuous warning saying only the max run ends the rig, and that this tool never changes IAM. up still finishes.
  • just lab preflight. A new step 14 of 15, before the license, runs the same test as the default compute account through gcloud auth print-access-token --impersonate-service-account. A missing permission stops with the remedy. A login that cannot impersonate that account, an API error or a missing curl passes with a note that up tests it from the VM.
sequenceDiagram
    participant T as idle timer on the VM
    participant R as Resource Manager API
    participant A as guest attribute idle/self-delete
    participant U as just lab up
    T->>R: testIamPermissions(compute.instances.delete) as the VM account
    R-->>T: permissions list, empty, or error
    T->>A: granted, missing, or unknown
    U->>A: read after startup
    U->>U: log granted, or warn that only the max run ends the rig

Proof

  • Each new case fails with the previous idle-delete.sh, preflight.sh and simulation.sh (9 in idle-delete-selftest.sh, 30 in preflight-selftest.sh, 11 in engine-selftest.sh, the last two partly from unrelated files missing in the scratch copy) and passes with this change: idle-delete-selftest.sh, preflight-selftest.sh (35 passed), engine-selftest.sh, tests/run.sh (641 passed) and tests/recipe-arguments.sh (271 passed).
  • The preflight impersonation path is proven against stubs only. Minting a token for the default compute account was refused in the rig project this was built in, so it was not exercised live.
  • The word ceiling rises to 40393: the notify, reap and this note each fit under the old ceiling alone and together pass it by 16 words.

Merge request reports

Loading
Loading