Review OS Login disabling overrides on GCP VMs

Check that VM SSH policies follow the project’s IAM access-management requirements.

Description

VM metadata enable-oslogin = false disables OS Login on that VM even if the project enables it. SSH then depends on the VM’s other configured authentication methods.

Potential impact

An overlooked instance override can leave separately managed SSH keys active after IAM access is revoked.

Remediation

On a supported Linux VM, first grant the needed OS Login roles and, if the VM has a service account, permission to use that account. Set enable-oslogin = true on the VM, or remove its false override after confirming that the project enables OS Login. Test a new administrator connection because metadata SSH keys no longer apply.

Examples

The examples change only the login setting on the same VM. Replace Debian 9 with a supported image and use an approved network and access path in place of the sample default network.

Before

hcl
resource "google_compute_instance" "vm" {
  name         = "test"
  machine_type = "e2-medium"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = "default"

    access_config {}
  }

  metadata = {
    enable-oslogin = "FALSE"
  }
}

After

hcl
resource "google_compute_instance" "vm" {
  name         = "test"
  machine_type = "e2-medium"
  zone         = "us-central1-a"

  boot_disk {
    initialize_params {
      image = "debian-cloud/debian-9"
    }
  }

  network_interface {
    network = "default"

    access_config {}
  }

  metadata = {
    enable-oslogin = true
  }
}

References