bridgecrewio / checkov

Prevent cloud misconfigurations and find vulnerabilities during build-time in infrastructure as code, container images and open source packages with Checkov by Bridgecrew.
https://www.checkov.io/
Apache License 2.0
7.1k stars 1.12k forks source link

CKV_GCP_33 reports a false positive `true` vs `"TRUE"` #790

Closed TheMacStack closed 3 years ago

TheMacStack commented 3 years ago

Bug/False Positive: CKV_GCP_33 reports a false positive depending on the syntax used in the metadata block specifically true vs "TRUE"

Steps to reproduce the behavior:

resource "google_compute_project_metadata" "general" {
  metadata = {
    "enable-oslogin" = "TRUE"
    "google-compute-default-region" = "europe-west4"
    "google-compute-default-zone"   = "europe-west4-a"
  }
}

or

resource "google_compute_project_metadata" "general" {
  metadata = {
    enable-oslogin    = "TRUE"
    google-compute-default-region = "europe-west4"
    google-compute-default-zone   = "europe-west4-a"
  }
}

Expected behavior: The above examples should be valid and not flagged as failed for Check: CKV_GCP_33: "Ensure oslogin is enabled for a Project"

schosterbarak commented 3 years ago

@arielkru is that something that can be handled at hcl2 parser?

schosterbarak commented 3 years ago

@TheMacStack should "TRUE" always be evaluated like true? from the HCL specification looks like capital letters "TRUE" is not necessarily a boolean value.

TheMacStack commented 3 years ago

@TheMacStack should "TRUE" always be evaluated like true? from the HCL specification looks like capital letters "TRUE" is not necessarily a boolean value.

No, typically not, but in this particular field it is a set of arbitrary key/value pairs, basically as plain text, not actual defined terraform params that expect a true boolean value.

So in general true != "TRUE" but for this metadata block "TRUE" is a valid value

schosterbarak commented 3 years ago

@TheMacStack I've just applied a fix to checkov latest version. Can you confirm it's working?

TheMacStack commented 3 years ago

@TheMacStack I've just applied a fix to checkov latest version. Can you confirm it's working?

Tested and confirm it now works as expected.

Many thanks for the rapid response time.

schosterbarak commented 3 years ago

sweet. thanks for reporting on it @TheMacStack