Notes
open one at a time
1.What it can cause
A key added for a contractor still opens every VM after the contract ends, until someone remembers to delete it.
- A key added for a contractor still opens every VM after the contract ends, until someone remembers to delete it.
- The logs show that a key was used, not who used it, so an incident cannot be traced to a person.
- Anyone who can edit project metadata can add a key of their own and log in everywhere.
2.Why it is wrong
OS Login ties login to IAM, so revocation is central and instant. Metadata keys tie it to nothing - a key outlives the person who owned it.
A key in metadata is just a key. Nothing links it to whether the person still works here, so access survives someone leaving until a human notices and deletes it. OS Login ties login to Google identities and IAM instead: grant roles/compute.osLogin and they can log in, revoke it and access to every VM disappears at once. Logs also show which identity logged in, rather than that a key was used. Deliberately sequenced after D2 - change the access path first and prove it, then change the login mechanism, so a failure has only one possible cause.
The idea
OS Login ties login to IAM, so revocation is central and instant. Metadata keys tie it to nothing - a key outlives the person who owned it.
Learn it
- The better way: OS Login · GCP 6.2
- Switching to OS Login safely · GCP 6.2
3.How you would find it
gcloud compute project-info describe --format="value(commonInstanceMetadata.items.filter(key:enable-oslogin))"
gcloud compute project-info describe \ --format="value(commonInstanceMetadata.items.filter(key:enable-oslogin))" # the keys this would replacegcloud compute project-info describe \ --format="value(commonInstanceMetadata.items.filter(key:sshKeys))"4.The change that closes it
OS Login on. Access by roles/compute.osLogin or osAdminLogin, revoked centrally and instantly.
- As found
- Keys in project metadata. One key grants every VM. Cleanup is manual.
- Fixed
- OS Login on. Access by roles/compute.osLogin or osAdminLogin, revoked centrally and instantly.
gcloud compute project-info add-metadata \ --metadata enable-oslogin=TRUE gcloud projects add-iam-policy-binding harbour-app-prod \ --member="user:someone@harbour.example" \ --role="roles/compute.osLogin" # find the keys this replaces, so they can be removedgcloud compute project-info describe \ --format="value(commonInstanceMetadata.items.filter(key:sshKeys))"