The coach guides you without giving the cause away (in full versions, each hint costs 5 points).
With the enable-oslogin=TRUE metadata, the guest agent configures sshd to ask OS Login for the authorized
keys (AuthorizedKeysCommand /usr/bin/google_authorized_keys): the keys in the ssh-keys metadata
are ignored. To be accepted, an account must both have its key in its OS Login profile and
hold the roles/compute.osLogin role (or roles/compute.osAdminLogin for sudo) on the project or
the instance. The grp-ops group only has instanceAdmin.v1, which does not grant this right, and the profile of
ops@masterlinux.lab is empty.
The firewall is healthy (the connection succeeds and the server presents its OpenSSH banner), the ssh service has started, and an SSH key does not expire on its own.
Incident resolved
Analysis and fix
Fix:
- grant the role to the group (not to people one by one):
gcloud projects add-iam-policy-binding masterlinux-prod --member=group:grp-ops@masterlinux.lab --role=roles/compute.osAdminLogin(roles/compute.osLoginis enough for those who do not need sudo; since the VM runs with a service account,roles/iam.serviceAccountUser, already present, is also required); - each member adds their key to their profile:
gcloud compute os-login ssh-keys add --key-file=~/.ssh/id_ed25519.pub --ttl=180d(or letsgcloud compute ssh ml-web-25do it automatically); - connect with the OS Login POSIX user:
ssh ops_masterlinux_lab@34.175.88.21.
Verification: the connection succeeds, id shows the google-sudoers group, the sshd log shows
Accepted publickey for ops_masterlinux_lab.
Prevention:
- pair every security policy with a migration plan: OS Login roles granted to groups and keys registered before activation, with an announcement to the teams;
- then remove the old
ssh-keysfrom the metadata, now useless; - keep a documented emergency access (IAP TCP forwarding, serial console) for on-call duty;
- consider OS Login with two-factor authentication (
enable-oslogin-2fa) for administration accounts.