-
Notifications
You must be signed in to change notification settings - Fork 349
feat(query): implements "Beta - SQL DB Instance With Ownership Chaining Enabled" #7787
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
7
commits into
master
Choose a base branch
from
AST-116631_18_6.3.2_ensure_'cross_db_ownership_chaining'_flag_is_set_to_off
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
083637b
initial implementation
cx-andre-pereira 2b2c361
implementation
cx-andre-pereira 55e790f
renamed query folder
cx-andre-pereira 0f97bbf
Merge branch 'master' into AST-116631_18_6.3.2_ensure_'cross_db_owner…
cx-andre-pereira 2f61a2e
fixed tests
cx-andre-pereira dfa3223
Merge branch 'master' of https://github.com/Checkmarx/kics into AST-1…
cx-andre-pereira 5c2b80d
simId transition update
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
assets/queries/terraform/gcp/sql_db_instance_with_ownership_chaining_enabled/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": "5a8c5d26-c592-4c98-afac-9762c54cc868", | ||
| "queryName": "Beta - SQL DB Instance With Ownership Chaining Enabled", | ||
| "severity": "MEDIUM", | ||
| "category": "Insecure Configurations", | ||
| "descriptionText": "No 'google_sql_database_instance' resource based on SQLSERVER should enable the deprecated 'cross db ownership chaining'", | ||
| "descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance.html#settings-1", | ||
| "platform": "Terraform", | ||
| "descriptionID": "5a8c5d26", | ||
| "cloudProvider": "gcp", | ||
| "cwe": "732", | ||
| "riskScore": "3.0", | ||
| "experimental": "true" | ||
| } |
42 changes: 42 additions & 0 deletions
42
assets/queries/terraform/gcp/sql_db_instance_with_ownership_chaining_enabled/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, "SQLSERVER") | ||
| 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 be defined and set 'cross db ownership chaining' to 'off'", [name]), | ||
| "keyActualValue": sprintf("'google_sql_database_instance[%s].settings.database_flags' sets 'cross db ownership chaining' to '%s'", [name, results.value]), | ||
| "searchLine": results.searchLine | ||
| } | ||
| } | ||
|
|
||
| get_results(resource, name) = results { # array | ||
| resource.settings.database_flags[x].name == "cross db ownership chaining" | ||
| resource.settings.database_flags[x].value != "off" | ||
|
|
||
| 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 == "cross db ownership chaining" | ||
| resource.settings.database_flags.value != "off" | ||
|
|
||
| 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 | ||
| } | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
...ts/queries/terraform/gcp/sql_db_instance_with_ownership_chaining_enabled/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,84 @@ | ||
| resource "google_sql_database_instance" "negative_1" { | ||
| name = "main-instance" | ||
| database_version = "MYSQL_8_0" # Is not a SQLSERVER instance | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags { | ||
| name = "cross db ownership chaining" | ||
| value = "on" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_2" { | ||
| name = "mysql-instance-without-flag" | ||
| database_version = "SQLSERVER_2017_STANDARD" | ||
| region = "us-central1" | ||
|
|
||
| # Defaults to "off" | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_3" { | ||
| name = "sqlserver-instance-without-flag" | ||
| database_version = "SQLSERVER_2017_STANDARD" | ||
| region = "us-central1" | ||
|
|
||
| settings {} # Defaults to "off" | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_4" { | ||
| name = "sqlserver-instance-without-flag" | ||
| database_version = "SQLSERVER_2017_STANDARD" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags { | ||
| name = "sample_flag1" | ||
| value = "off" | ||
| } | ||
| # Defaults to "off" | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "negative_5" { | ||
| name = "mysql-instance-with-flag" | ||
| database_version = "SQLSERVER_2019_STANDARD" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags { | ||
| name = "sample_flag1" | ||
| value = "off" | ||
| } | ||
|
|
||
| database_flags { # Has flag set to "off" | ||
| name = "cross db ownership chaining" | ||
| value = "off" | ||
| } | ||
|
|
||
| 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 = "SQLSERVER_2019_STANDARD" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| tier = "db-f1-micro" | ||
|
|
||
| database_flags { | ||
| name = "cross db ownership chaining" | ||
| value = "off" | ||
| } # Has flag set to "off" | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...ts/queries/terraform/gcp/sql_db_instance_with_ownership_chaining_enabled/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,35 @@ | ||
| resource "google_sql_database_instance" "positive_1" { | ||
| name = "sqlserver-instance-with-flag" | ||
| database_version = "SQLSERVER_2017_EXPRESS" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags { | ||
| name = "sample_flag1" | ||
| value = "off" | ||
| } | ||
|
|
||
| database_flags { # Flag is not set to "off" | ||
| name = "cross db ownership chaining" | ||
| value = "on" | ||
| } | ||
|
|
||
| database_flags { | ||
| name = "sample_flag2" | ||
| value = "off" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| resource "google_sql_database_instance" "positive_2" { # Single object support test | ||
| name = "sqlserver-instance-with-flag" | ||
| database_version = "SQLSERVER_2017_EXPRESS" | ||
| region = "us-central1" | ||
|
|
||
| settings { | ||
| database_flags { | ||
| name = "cross db ownership chaining" | ||
| value = "on" | ||
| } # Flag is not set to "off" | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
...rm/gcp/sql_db_instance_with_ownership_chaining_enabled/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,12 @@ | ||
| [ | ||
| { | ||
| "queryName": "Beta - SQL DB Instance With Ownership Chaining Enabled", | ||
| "severity": "MEDIUM", | ||
| "line": 13 | ||
| }, | ||
| { | ||
| "queryName": "Beta - SQL DB Instance With Ownership Chaining Enabled", | ||
| "severity": "MEDIUM", | ||
| "line": 31 | ||
| } | ||
| ] |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this
expectedValuemisleading?Following the documentation description: "This flag is deprecated for all SQL Server versions in CGP. Going forward, you can't set its value to on. However, if you have this flag enabled, we strongly recommend that you either remove the flag from your database or set it to off", the default value is off, I believe we should say that the expected value "should be defined and set"...
Maybe change the message to something similar to other related case queries: