Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "00335e17-674c-442e-a64c-9436e60e6efb",
"queryName": "Beta - SQL DB Instance With Minimum Log Duration",
"severity": "MEDIUM",
"category": "Observability",
"descriptionText": "No 'google_sql_database_instance' resource based on POSTGRES should set the 'log_min_duration_statement' flag to a value that is not '-1'",
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance.html#settings-1",
"platform": "Terraform",
"descriptionID": "00335e17",
"cloudProvider": "gcp",
"cwe": "778",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the cwe https://cwe.mitre.org/data/definitions/532.html be more appropriate here?
Following the description provided "Logging SQL statements may include sensitive information that should not be recorded in logs." I would personally put 532 here.
Let me know what you think.

"riskScore": "3.0",
"experimental": "true"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Cx

import data.generic.common as common_lib
import data.generic.terraform as tf_lib

CxPolicy[result] {
resource := input.document[i].resource.google_sql_database_instance[name]

contains(resource.database_version, "POSTGRES")
results := get_results(resource, name)

result := {
"documentId": input.document[i].id,
"resourceType": "google_sql_database_instance",
"resourceName": tf_lib.get_resource_name(resource, name),
"searchKey": results.searchKey,
"issueType": "IncorrectValue",
"keyExpectedValue": sprintf("'google_sql_database_instance[%s].settings.database_flags' should set 'log_min_duration_statement' to '-1'", [name]),
"keyActualValue": sprintf("'google_sql_database_instance[%s].settings.database_flags' sets 'log_min_duration_statement' to '%s'", [name, results.value]),
"searchLine": results.searchLine
}
}

get_results(resource, name) = results { # array
resource.settings.database_flags[x].name == "log_min_duration_statement"
resource.settings.database_flags[x].value != "-1"

results := {
"searchKey" : sprintf("google_sql_database_instance[%s].settings.database_flags[%d].name", [name, x]),
"searchLine" : common_lib.build_search_line(["resource", "google_sql_database_instance", name, "settings", "database_flags", x, "name"], []),
"value" : resource.settings.database_flags[x].value
}
} else = results { # single object
resource.settings.database_flags.name == "log_min_duration_statement"
resource.settings.database_flags.value != "-1"

results := {
"searchKey" : sprintf("google_sql_database_instance[%s].settings.database_flags.name", [name]),
"searchLine" : common_lib.build_search_line(["resource", "google_sql_database_instance", name, "settings", "database_flags", "name"], []),
"value" : resource.settings.database_flags.value
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
resource "google_sql_database_instance" "negative_1" {
name = "main-instance"
database_version = "MYSQL_8_0" # Is not a POSTGRES instance
region = "us-central1"

settings {
database_flags {
name = "log_min_duration_statement"
value = "2"
} # Flag is not set to "-1"
}
}

resource "google_sql_database_instance" "negative_2" {
name = "mysql-instance-without-flag"
database_version = "POSTGRES_17"
region = "us-central1"

# Default value is -1
}

resource "google_sql_database_instance" "negative_3" {
name = "postgres-instance-without-flag"
database_version = "POSTGRES_16"
region = "us-central1"

settings {} # Default value is -1
}

resource "google_sql_database_instance" "negative_4" {
name = "postgres-instance-without-flag"
database_version = "POSTGRES_15"
region = "us-central1"

settings {
database_flags {
name = "sample_flag1"
value = "off"
}
# Default value is -1
}
}

resource "google_sql_database_instance" "negative_5" {
name = "mysql-instance-with-flag"
database_version = "POSTGRES_15"
region = "us-central1"

settings {
tier = "db-f1-micro"

database_flags {
name = "sample_flag1"
value = "off"
}

database_flags { # Has flag set to "-1"
name = "log_min_duration_statement"
value = "-1"
}

database_flags {
name = "sample_flag2"
value = "off"
}
}
}

resource "google_sql_database_instance" "negative_6" { # Single object support test
name = "mysql-instance-with-flag"
database_version = "POSTGRES_15"
region = "us-central1"

settings {
tier = "db-f1-micro"

database_flags {
name = "log_min_duration_statement"
value = "-1"
} # Has flag set to "-1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
resource "google_sql_database_instance" "positive_1" {
name = "postgres-instance-with-flag"
database_version = "POSTGRES_14"
region = "us-central1"

settings {
database_flags {
name = "sample_flag1"
value = "off"
}

database_flags { # Flag is not set to "-1"
name = "log_min_duration_statement"
value = "2"
}

database_flags {
name = "sample_flag2"
value = "off"
}
}
}

resource "google_sql_database_instance" "positive_2" { # Single object support test
name = "postgres-instance-with-flag"
database_version = "POSTGRES_14"
region = "us-central1"

settings {
database_flags {
name = "log_min_duration_statement"
value = "3"
} # Flag is not set to "-1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"queryName": "Beta - SQL DB Instance With Minimum Log Duration",
"severity": "MEDIUM",
"line": 13
},
{
"queryName": "Beta - SQL DB Instance With Minimum Log Duration",
"severity": "MEDIUM",
"line": 31
}
]
4 changes: 4 additions & 0 deletions assets/similarityID_transition/terraform_gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ similarityIDChangeList:
queryName: Beta - Google DNS Policy Logging Disabled
observations: ""
change: 2
- queryId: 00335e17-674c-442e-a64c-9436e60e6efb
queryName: Beta - SQL DB Instance With Minimum Log Duration
observations: ""
change: 2
Loading