terraform.gcp.security.gcp-compute-boot-disk-encryption.gcp-compute-boot-disk-encryption

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Ensure VM disks for critical VMs are encrypted with Customer Supplied Encryption Keys (CSEK)

Run Locally

Run in CI

Defintion

rules:
  - id: gcp-compute-boot-disk-encryption
    patterns:
      - pattern: |
          resource "google_compute_instance" $ANYTHING {
            ...
          }
      - pattern-not-inside: |
          resource "google_compute_instance" $ANYTHING {
            ...
            boot_disk {
              disk_encryption_key_raw = ...
            }
            ...
          }
      - pattern-not-inside: |
          resource "google_compute_instance" $ANYTHING {
            ...
            boot_disk {
              kms_key_self_link = ...
            }
            ...
          }
    message: Ensure VM disks for critical VMs are encrypted with Customer Supplied
      Encryption Keys (CSEK)
    languages:
      - hcl
    severity: WARNING
    metadata:
      owasp:
        - A03:2017 - Sensitive Data Exposure
        - A04:2021 - Insecure Design
      cwe:
        - "CWE-311: Missing Encryption of Sensitive Data"
      technology:
        - terraform
        - gcp
      category: security
      references:
        - https://docs.bridgecrew.io/docs/google-cloud-policy-index
      subcategory:
        - audit
      likelihood: LOW
      impact: LOW
      confidence: LOW
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
      vulnerability_class:
        - Cryptographic Issues

Examples

gcp-compute-boot-disk-encryption.tf

# fail
# ruleid: gcp-compute-boot-disk-encryption
resource "google_compute_instance" "fail" {
    name         = "test"
    machine_type = "n1-standard-1"
    zone         = "us-central1-a"
    boot_disk {}
}

# ok: gcp-compute-boot-disk-encryption
resource "google_compute_instance" "success" {
    name         = "test"
    machine_type = "n1-standard-1"
    zone         = "us-central1-a"
    boot_disk {
        disk_encryption_key_raw = "acXTX3rxrKAFTF0tYVLvydU1riRZTvUNC4g5I11NY-c="
    }
}

# ok: gcp-compute-boot-disk-encryption
resource "google_compute_instance" "success" {
    name         = "test"
    machine_type = "n1-standard-1"
    zone         = "us-central1-a"
    boot_disk {
        kms_key_self_link = google_kms_crypto_key.example-key.id
    }
}