For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-gcp-project-wide-ssh-keys-are-enabled-in-vm-instances.md.
A documentation index is available at /llms.txt.
This check ensures that Google Compute Engine VM instances have project-wide SSH keys blocked by setting the metadata attribute block-project-ssh-keys to "TRUE". Without this setting, anyone with project-level SSH key access can connect to the VM, increasing the risk of unauthorized access and making it harder to manage individual SSH permissions. For a secure configuration, define the attribute in your Terraform configuration as follows:
metadata = {
block-project-ssh-keys = "TRUE"
}
Compliant Code Examples
resource"google_compute_instance""negative1"{name="test"machine_type="e2-medium"zone="us-central1-a"tags=["foo","bar"]boot_disk{initialize_params{image="debian-cloud/debian-9"}} // Local SSD disk
scratch_disk{interface="SCSI"}network_interface{network="default"access_config{ // Ephemeral IP
}}metadata={ #... some other metadata
block-project-ssh-keys="TRUE"}metadata_startup_script="echo hi > /test.txt"service_account{scopes=["userinfo-email","compute-ro","storage-ro"]}}
Non-Compliant Code Examples
resource"google_compute_instance""positive1"{name="test"machine_type="e2-medium"zone="us-central1-a"tags=["foo","bar"]boot_disk{initialize_params{image="debian-cloud/debian-9"}} // Local SSD disk
scratch_disk{interface="SCSI"}network_interface{network="default"access_config{ // Ephemeral IP
}}metadata={ #... some other metadata
block-project-ssh-keys=false}metadata_startup_script="echo hi > /test.txt"service_account{scopes=["userinfo-email","compute-ro","storage-ro"]}}resource"google_compute_instance""positive2"{name="test"machine_type="e2-medium"zone="us-central1-a"tags=["foo","bar"]boot_disk{initialize_params{image="debian-cloud/debian-9"}} // Local SSD disk
scratch_disk{interface="SCSI"}network_interface{network="default"access_config{ // Ephemeral IP
}}metadata_startup_script="echo hi > /test.txt"service_account{scopes=["userinfo-email","compute-ro","storage-ro"]}}
1
2
rulesets:- Terraform / GCP # Rules to enforce / GCP.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.