-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add gcp sql rules for insecure ssl_mode * clean up message and references --------- Co-authored-by: Pieter De Cremer (Semgrep) <[email protected]> Co-authored-by: Lewis <[email protected]>
- Loading branch information
1 parent
32750f0
commit 7b4b6c5
Showing
7 changed files
with
670 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
138 changes: 138 additions & 0 deletions
138
terraform/gcp/security/gcp-sql-database-ssl-insecure-value-postgres-mysql.fixed.tf
This file contains 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,138 @@ | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
resource "google_sql_database_instance" "fail" { | ||
database_version = "MYSQL_8_0" | ||
name = "instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
} | ||
} | ||
|
||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
resource "google_sql_database_instance" "success" { | ||
database_version = "MYSQL_8_0" | ||
name = "instance" | ||
region = "us-central1" | ||
ip_configuration { | ||
ipv4_enabled = true | ||
require_ssl = true | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_fail" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_success" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "sqlserver_fail" { | ||
database_version = "SQLSERVER_2019_STANDARD" | ||
name = "sqlserver-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "sqlserver_success" { | ||
database_version = "SQLSERVER_2019_STANDARD" | ||
name = "sqlserver-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ENCRYPTED_ONLY" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_success_with_ssl_mode" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
138 changes: 138 additions & 0 deletions
138
terraform/gcp/security/gcp-sql-database-ssl-insecure-value-postgres-mysql.tf
This file contains 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,138 @@ | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
resource "google_sql_database_instance" "fail" { | ||
database_version = "MYSQL_8_0" | ||
name = "instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
} | ||
} | ||
|
||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
resource "google_sql_database_instance" "success" { | ||
database_version = "MYSQL_8_0" | ||
name = "instance" | ||
region = "us-central1" | ||
ip_configuration { | ||
ipv4_enabled = true | ||
require_ssl = true | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ENCRYPTED_ONLY" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "main" { | ||
name = "some-example-name" | ||
database_version = "POSTGRES_15" | ||
region = "europe-west3" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_fail" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ENCRYPTED_ONLY" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_success" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ruleid: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ENCRYPTED_ONLY" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "sqlserver_fail" { | ||
database_version = "SQLSERVER_2019_STANDARD" | ||
name = "sqlserver-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ALLOW_UNENCRYPTED_AND_ENCRYPTED" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "sqlserver_success" { | ||
database_version = "SQLSERVER_2019_STANDARD" | ||
name = "sqlserver-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "ENCRYPTED_ONLY" | ||
} | ||
} | ||
} | ||
|
||
resource "google_sql_database_instance" "mysql_success_with_ssl_mode" { | ||
database_version = "MYSQL_8_0" | ||
name = "mysql-instance" | ||
region = "us-central1" | ||
settings { | ||
tier = "db-f1-micro" | ||
ip_configuration { | ||
# ok: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
} | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
terraform/gcp/security/gcp-sql-database-ssl-insecure-value-postgres-mysql.yaml
This file contains 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,58 @@ | ||
rules: | ||
- id: gcp-sql-database-ssl-insecure-value-postgres-mysql | ||
patterns: | ||
- pattern-inside: | | ||
resource "google_sql_database_instance" "..." { | ||
... | ||
database_version = "$DB" | ||
... | ||
} | ||
- pattern-inside: | | ||
resource "google_sql_database_instance" "..." { | ||
... | ||
ip_configuration { | ||
... | ||
ssl_mode = $VALUE | ||
... | ||
} | ||
... | ||
} | ||
- pattern-not-inside: | | ||
resource "google_sql_database_instance" "..." { | ||
... | ||
ip_configuration { | ||
... | ||
ssl_mode = "TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
... | ||
} | ||
... | ||
} | ||
- metavariable-regex: | ||
metavariable: $DB | ||
regex: .*(MYSQL|POSTGRES).* | ||
- focus-metavariable: $VALUE | ||
fix: | | ||
"TRUSTED_CLIENT_CERTIFICATE_REQUIRED" | ||
message: >- | ||
Ensure all Cloud SQL database instance require incoming connections to use SSL. To enable this for PostgresSQL and MySQL, use `ssl_mode="TRUSTED_CLIENT_CERTIFICATE_REQUIRED"`. | ||
metadata: | ||
owasp: | ||
- A03:2017 - Sensitive Data Exposure | ||
- A02:2021 - Cryptographic Failures | ||
cwe: | ||
- 'CWE-326: Inadequate Encryption Strength' | ||
category: security | ||
technology: | ||
- terraform | ||
- gcp | ||
references: | ||
- "https://cloud.google.com/sql/docs/postgres/admin-api/rest/v1/instances#ipconfiguration" | ||
- "https://owasp.org/Top10/A02_2021-Cryptographic_Failures" | ||
subcategory: | ||
- vuln | ||
likelihood: LOW | ||
impact: MEDIUM | ||
confidence: MEDIUM | ||
languages: [hcl] | ||
severity: WARNING | ||
|
Oops, something went wrong.