INC-3261 · P2 · Google Cloud · Compute Engine · OS Login · Cloud IAM · OpenSSH · gcloud CLI
Step-by-step fix: Monday morning, nobody on the operations team can SSH into the web server any more
A production incident replayed in a simulated terminal, with its complete resolution: the commands the on-call engineer ran, what they printed, the root cause and the fix. This is exactly the reasoning expected in a DevOps, SRE or Linux administrator job interview.
Try it yourself first in the terminal (free)
The ticket
The MasterLinux Denver office manages the web server ml-web-01 (Debian 12, Compute Engine,
europe-southwest1-a, public IP 34.175.88.21) that hosts the training website. It has always been the case that
the operations team connects with its SSH keys, stored in the instance metadata
(ssh-keys).
On Friday evening, the security team applied a new policy to the masterlinux-prod project.
This morning, it is impossible to connect: an urgent security fix must be applied to nginx before
noon, and the site must be restarted during the morning.
The site responds normally. You are on your workstation ml-poste-01, with the gcloud CLI signed in as
ops@masterlinux.lab (member of the grp-ops@masterlinux.lab group, with IAM administration rights delegated on
the project for on-call duty).
Step by step: the commands and their output
These are the commands the engineer typed, in order, with what the machine answered.
ops@ml-poste-01:~$ ssh -i ~/.ssh/id_ed25519 ops@34.175.88.21 ops@34.175.88.21: Permission denied (publickey).ops@ml-poste-01:~$ gcloud compute firewall-rules list --filter='network:vpc-ml-prod' NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED allow-health-checks vpc-ml-prod INGRESS 1000 tcp:80,tcp:443 False allow-https-public vpc-ml-prod INGRESS 1000 tcp:443 False allow-ssh-agence-denver vpc-ml-prod INGRESS 900 tcp:22 Falseops@ml-poste-01:~$ gcloud compute instances get-serial-port-output ml-web-01 --zone europe-southwest1-a | tail -20 [ OK ] Started google-guest-agent.service - Google Compute Engine Guest Agent. [ OK ] Started ssh.service - OpenBSD Secure Shell server. [ OK ] Started nginx.service - A high performance web server and a reverse proxy server. Oct 16 18:04:31 ml-web-01 google_guest_agent[612]: Enabling OS Login Oct 16 18:04:31 ml-web-01 google_guest_agent[612]: Updating OS Login configuration. Debian GNU/Linux 12 ml-web-01 ttyS0 ml-web-01 login:ops@ml-poste-01:~$ gcloud compute project-info describe --project masterlinux-prod --format='yaml(commonInstanceMetadata)' commonInstanceMetadata: fingerprint: 3kQ9xT1bW8o= items: - key: enable-oslogin value: 'TRUE' - key: google-compute-default-region value: europe-southwest1 - key: google-compute-default-zone value: europe-southwest1-a kind: compute#metadataops@ml-poste-01:~$ gcloud compute os-login describe-profile name: '104857362918475620193'ops@ml-poste-01:~$ gcloud projects get-iam-policy masterlinux-prod --flatten=bindings --filter=bindings.members:group:grp-ops@masterlinux.lab --format='table(bindings.role)' ROLE roles/compute.instanceAdmin.v1 roles/iam.serviceAccountUser roles/logging.viewerops@ml-poste-01:~$ gcloud projects add-iam-policy-binding masterlinux-prod --member=group:grp-ops@masterlinux.lab --role=roles/compute.osAdminLogin Updated IAM policy for project [masterlinux-prod]. bindings: - members: - group:grp-ops@masterlinux.lab role: roles/compute.instanceAdmin.v1 - members: - group:grp-ops@masterlinux.lab role: roles/compute.osAdminLogin - members: - group:grp-ops@masterlinux.lab role: roles/iam.serviceAccountUser etag: BwYk9xQ2rT4= version: 1ops@ml-poste-01:~$ gcloud compute os-login ssh-keys add --key-file=~/.ssh/id_ed25519.pub --ttl=180d loginProfile: name: '104857362918475620193' posixAccounts: - accountId: masterlinux-prod gid: '2738104562' homeDirectory: /home/ops_masterlinux_lab name: users/ops@masterlinux.lab/projects/masterlinux-prod operatingSystemType: LINUX primary: true uid: '2738104562' username: ops_masterlinux_lab sshPublicKeys: 7c1e9b4a2f6d08e35b91c4a7d2e6f0b8a3c5e7d9f1b2a4c6e8d0f2b4a6c8e0d2: fingerprint: 7c1e9b4a2f6d08e35b91c4a7d2e6f0b8a3c5e7d9f1b2a4c6e8d0f2b4a6c8e0d2 key: | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK7v3mQ9xT2bW8oR4cLp6fN1sY0aH5jE7uG3kD9wZ2qX ops@ml-poste-01 name: users/ops@masterlinux.lab/sshPublicKeys/7c1e9b4a2f6d08e35b91c4a7d2e6f0b8a3c5e7d9f1b2a4c6e8d0f2b4a6c8e0d2ops@ml-poste-01:~$ ssh -i ~/.ssh/id_ed25519 ops_masterlinux_lab@34.175.88.21 Linux ml-web-01 6.1.0-26-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.112-1 (2024-09-30) x86_64 Creating directory '/home/ops_masterlinux_lab'.ops_masterlinux_lab@ml-web-01:~$ id uid=2738104562(ops_masterlinux_lab) gid=2738104562(ops_masterlinux_lab) groups=2738104562(ops_masterlinux_lab),4(adm),30(dip),44(video),46(plugdev),1000(google-sudoers)ops_masterlinux_lab@ml-web-01:~$ sudo journalctl -u ssh --since today Oct 19 08:31:07 ml-web-01 sshd[48211]: AuthorizedKeysCommand /usr/bin/google_authorized_keys ops returned status 1 Oct 19 08:31:07 ml-web-01 sshd[48211]: Connection closed by authenticating user ops 196.74.18.33 port 51822 [preauth] Oct 19 08:39:44 ml-web-01 sshd[48390]: Connection closed by authenticating user ops_masterlinux_lab 196.74.18.33 port 51906 [preauth] Oct 19 08:58:12 ml-web-01 sshd[48702]: Accepted publickey for ops_masterlinux_lab from 196.74.18.33 port 52011 ssh2: ED25519 SHA256:fK3pQ8vN2mR7tL0wY5cH9jB4xD6sA1eG3uZ8kV2nT0oops_masterlinux_lab@ml-web-01:~$ exit logout Connection to ml-web-01 closed.
What the commands revealed
- The TCP connection succeeds, but the server rejects the key: “ops@34.175.88.21: Permission denied (publickey)”
- The allow-ssh-agence-denver firewall rule still allows port 22 from the Denver office
- ml-web-01 is RUNNING and its serial console shows ssh.service started normally
- Since Friday 18:02, the project metadata enable-oslogin is TRUE (set by secu@masterlinux.lab): sshd no longer uses the metadata keys
- The team's keys are still in the instance's ssh-keys metadata, but the OS Login profile of ops@masterlinux.lab contains no key
- The grp-ops group has instanceAdmin.v1 and serviceAccountUser, but neither roles/compute.osAdminLogin nor roles/compute.osLogin
- The grp-ops@masterlinux.lab group now has roles/compute.osAdminLogin on the project
- The public key is registered in the OS Login profile: POSIX user ops_masterlinux_lab
Root cause
OS Login is now enabled on the project: sshd ignores the metadata keys and only accepts keys from the OS Login profiles of accounts that have an osLogin or osAdminLogin role, which the ops group does not have
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.
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-01do 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.
In a job interview
This kind of outage often comes up in technical interviews ("the site returns an error, what do you do?"). What is assessed: start from the symptoms, check each layer with the right command, prove the cause before fixing it, then prevent it from happening again. MasterLinux trains you on 195 incidents like this one, from beginner to expert.
Try it yourself first in the terminal (free)
Unlock every production simulation
AWS, Azure, Google Cloud, on-premise and multi-cloud, from Beginner to Extreme: the real incidents of IT service companies and large IT organisations, available for a year.
Other free walkthroughs
- Since last night, the AWS applications can no longer reach headquarters, while Azure works · Multi-cloud & hybrid
- The East branch can no longer open the shared drive holding student files · Azure
- The MasterLinux store returns “502 Bad Gateway” in the middle of the night · On-premises
- Since last night's maintenance, every course image and PDF returns 404 · AWS