OS Login Not Enforced
Linux instances accept SSH keys stored in project or instance metadata instead of OS Login, so SSH access is not tied to IAM and is not removed when a user's access ends.
| Severity | Low |
| CVSS 3.1 | 3.3 CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:L/A:N Open in the calculator |
| CVSS 4.0 | 2.1 CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-269: Improper Privilege Management |
| OWASP Top 10 | A06:2025 Insecure Design |
| MITRE ATT&CK | T1098.004 SSH Authorized Keys, T1021.004 SSH |
| Category | Security Misconfiguration |
Description
Compute Engine Linux instances can control SSH access in two ways. With metadata-managed keys, public keys are added to the project or instance metadata and the guest environment creates matching local accounts, typically with sudo rights. With OS Login, enabled by setting the enable-oslogin metadata key to TRUE, access is granted through IAM roles such as roles/compute.osLogin and roles/compute.osAdminLogin, Linux accounts are tied to Google identities, and access ends when the role is removed or the user is suspended.
The finding applies where OS Login is not enabled, or is enabled at project level but switched off on individual instances, and the constraints/compute.requireOsLogin organisation policy constraint is not enforced. SSH access then cannot be reliably revoked or audited through IAM: metadata keys persist after the person who added them leaves and are not linked to an identity the organisation manages, so keys belonging to former staff, contractors or decommissioned systems remain valid on every instance that trusts them, and a stolen private key keeps working until someone finds and removes it from metadata. OS Login does not apply to Windows instances.
Anyone with permission to change instance or project metadata can also add their own key and gain administrative access to instances without holding any SSH-specific role, a technique attackers use for persistence. Exploitation requires either a valid private key or permission to change metadata, as well as network access to the instance's SSH port.
The finding is identified by reviewing project and instance metadata, for example with gcloud compute project-info describe and gcloud compute instances describe, for the enable-oslogin key and for ssh-keys entries, and by checking the organisation policies in force.
Remediation
- Enable OS Login across each project by setting
enable-oslogintoTRUEin project metadata, and enforce it with theconstraints/compute.requireOsLoginorganisation policy constraint so that individual instances cannot opt out. - Grant
roles/compute.osLogin, orroles/compute.osAdminLoginonly where administrative rights are needed, to groups rather than individuals, on the projects or instances they need. - Enable OS Login 2-step verification with the
enable-oslogin-2fametadata key for administrative access. - Once OS Login is in use, remove the keys held in project and instance metadata.
- Restrict who can change instance and project metadata, and combine OS Login with Identity-Aware Proxy TCP forwarding so that SSH is not exposed to the internet.
Confirm the fix by checking that the organisation policy is enforced and that metadata keys are no longer accepted, and by signing in with an account that holds an OS Login role and with one that does not, expecting only the first to succeed.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.