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.

SeverityLow
CVSS 3.13.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.02.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
CWECWE-269: Improper Privilege Management
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1098.004 SSH Authorized Keys, T1021.004 SSH
CategorySecurity 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-oslogin to TRUE in project metadata, and enforce it with the constraints/compute.requireOsLogin organisation policy constraint so that individual instances cannot opt out.
  • Grant roles/compute.osLogin, or roles/compute.osAdminLogin only 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-2fa metadata 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.
gcloud compute project-info add-metadata --metadata enable-oslogin=TRUE

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 trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Google Cloud Findings

Every Google Cloud finding