-
Notifications
You must be signed in to change notification settings - Fork 349
feat(query): implements "Beta - SQL DB Instance With Unrecommended Logging Threshold" #7782
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cx-andre-pereira
wants to merge
15
commits into
master
Choose a base branch
from
AST-116626_13_6.2_PostgreSQL_Database_ensure_that_the_'log_min_messages'_database_flag_for_cloud_sql_postgresql_instance_is_set_at_minimum_to_warning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3e20267
template
cx-andre-pereira 88acaa1
implementation
cx-andre-pereira a4604da
query name fix and cwe updated
cx-andre-pereira 21e877a
minor metadata change
cx-andre-pereira fbbc385
adjusted tests and logic for default value of ERROR
cx-andre-pereira 4da793a
added single object support and typo fix
cx-andre-pereira 621ec91
logic simplification
cx-andre-pereira 3dfd204
typo fix in expected results
cx-andre-pereira 87bc64a
small negative test improvement
cx-andre-pereira c106052
Merge branch 'master' into AST-116626_13_6.2_PostgreSQL_Database_ensu…
cx-andre-pereira 6c2e2fc
fixed tests and typo
cx-andre-pereira 08bb8b2
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 183289e
simId transition update
cx-andre-pereira 45d88e7
adjusted negative test
cx-andre-pereira 3cf6077
fix simId file
cx-andre-pereira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
.../queries/terraform/gcp/sql_db_instance_with_unrecommended_logging_threshold/metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "id": "ecbbe763-95dc-47e6-8660-84ff751e5acf", | ||
| "queryName": "Beta - SQL DB Instance With Unrecommended Logging Threshold", | ||
| "severity": "LOW", | ||
| "category": "Observability", | ||
| "descriptionText": "All 'google_sql_database_instance' resources based on POSTGRES should have the 'log_min_messages' flag set to 'WARNING' or a higher severity to prevent excessively logging", | ||
| "descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance.html#settings-1", | ||
| "platform": "Terraform", | ||
| "descriptionID": "ecbbe763", | ||
| "cloudProvider": "gcp", | ||
| "cwe": "779", | ||
| "riskScore": "1.0", | ||
| "experimental": "true" | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
assets/queries/terraform/gcp/sql_db_instance_with_unrecommended_logging_threshold/query.rego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_messages' to 'WARNING' or a higher severity", [name]), | ||
| "keyActualValue" : sprintf("'google_sql_database_instance[%s].settings.database_flags' sets 'log_min_messages' to '%s'", [name, results.value]), | ||
| "searchLine": results.searchLine | ||
| } | ||
| } | ||
|
|
||
| get_results(resource, name) = results { # array | ||
| resource.settings.database_flags[x].name == "log_min_messages" | ||
| not common_lib.inArray(["WARNING", "ERROR", "LOG", "FATAL", "PANIC"], resource.settings.database_flags[x].value) | ||
|
|
||
| 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_messages" | ||
| not common_lib.inArray(["WARNING", "ERROR", "LOG", "FATAL", "PANIC"], resource.settings.database_flags.value) | ||
|
|
||
| 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 | ||
| } | ||
| } |
89 changes: 89 additions & 0 deletions
89
...eries/terraform/gcp/sql_db_instance_with_unrecommended_logging_threshold/test/negative.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| resource "google_sql_database_instance" "negative_1" { | ||
| name = "main-instance" | ||
| database_version = "MYSQL_8_0" # Is not a POSTGRES instance | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags = [ | ||
| { name = "log_min_messages", value = "DEBUG3" } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_2" { | ||
| name = "mysql-instance-without-flag" | ||
| database_version = "POSTGRES_17" | ||
| region = "us-central1" | ||
|
|
||
| # Defaults to "ERROR" | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_3" { | ||
| name = "postgres-instance-without-flag" | ||
| database_version = "POSTGRES_16" | ||
| region = "us-central1" | ||
|
|
||
| settings {} # Defaults to "ERROR" | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_4" { | ||
| name = "postgres-instance-without-flag" | ||
| database_version = "POSTGRES_15" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags = [ | ||
| # Defaults to "ERROR" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| 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 = "log_min_messages", value = "WARNING" }, # Has flag set to "WARNING" (minimum) | ||
| { name = "log_min_messages", value = "ERROR" }, # Has flag set to "ERROR" | ||
| { name = "log_min_messages", value = "LOG" }, # Has flag set to "LOG" | ||
| { name = "log_min_messages", value = "FATAL" }, # Has flag set to "FATAL" | ||
| { name = "log_min_messages", value = "PANIC" }, # Has flag set to "PANIC" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_6" { # Single object support test 1 | ||
| name = "mysql-instance-with-flag" | ||
| database_version = "POSTGRES_15" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags { | ||
| name = "log_min_messages" | ||
| value = "WARNING" | ||
| } # Has flag set to "WARNING" (minimum) | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_7" { # Single object support test 2 | ||
| name = "mysql-instance-with-flag" | ||
| database_version = "POSTGRES_15" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags { | ||
| name = "log_min_messages" | ||
| value = "PANIC" | ||
| } # Has flag set to "PANIC" | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
...eries/terraform/gcp/sql_db_instance_with_unrecommended_logging_threshold/test/positive.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| 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" }, | ||
| { name = "log_min_messages", value = "NOTICE" }, # Flag is set to "NOTICE" | ||
| { name = "sample_flag2", value = "off" } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "positive_2" { | ||
| name = "postgres-instance-with-flag" | ||
| database_version = "POSTGRES_13" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags = [ | ||
| { name = "log_min_messages", value = "DEBUG5" }, # Flag is set to "DEBUG5" | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "positive_3" { # Single object support test | ||
| name = "postgres-instance-with-flag" | ||
| database_version = "POSTGRES_13" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags { | ||
| name = "log_min_messages" | ||
| value = "INFO" | ||
| } # Flag is set to "INFO" | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
...p/sql_db_instance_with_unrecommended_logging_threshold/test/positive_expected_result.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [ | ||
| { | ||
| "queryName": "Beta - SQL DB Instance With Unrecommended Logging Threshold", | ||
| "severity": "LOW", | ||
| "line": 9 | ||
| }, | ||
| { | ||
| "queryName": "Beta - SQL DB Instance With Unrecommended Logging Threshold", | ||
| "severity": "LOW", | ||
| "line": 22 | ||
| }, | ||
| { | ||
| "queryName": "Beta - SQL DB Instance With Unrecommended Logging Threshold", | ||
| "severity": "LOW", | ||
| "line": 34 | ||
| } | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.