-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from DataDog/bahar.shah/K9VULN-3698
[K9VULN-3698] Add GCP rules to match cloud security baseline
- Loading branch information
Showing
80 changed files
with
1,759 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
2 changes: 1 addition & 1 deletion
2
assets/queries/terraform/aws/team_tag_not_present/metadata.json
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
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
12 changes: 12 additions & 0 deletions
12
assets/queries/terraform/gcp/artifact_registry_repository_is_public/metadata.json
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,12 @@ | ||
{ | ||
"id": "a7b8c9d0-e1f2-3a4b-5c6d-7e8f90123456", | ||
"queryName": "Artifact Registry Repo Is Public", | ||
"severity": "HIGH", | ||
"category": "Access Control", | ||
"descriptionText": "Artifact Registry repositories must not be publicly accessible. IAM members or bindings should not use public principals such as 'allUsers' or 'allAuthenticatedUsers'.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/artifact_registry_repository_iam_member", | ||
"platform": "Terraform", | ||
"descriptionID": "a7b8c9d0", | ||
"cloudProvider": "gcp", | ||
"cwe": "284" | ||
} |
100 changes: 100 additions & 0 deletions
100
assets/queries/terraform/gcp/artifact_registry_repository_is_public/query.rego
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,100 @@ | ||
package Cx | ||
|
||
import data.generic.terraform as tf_lib | ||
import data.generic.common as common_lib | ||
|
||
# Check for google_artifact_registry_repository_iam_member | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_artifact_registry_repository_iam_member[name] | ||
common_lib.valid_key(resource, "member") | ||
member := resource.member | ||
member == "allAuthenticatedUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_artifact_registry_repository_iam_member", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_artifact_registry_repository_iam_member[{{%s}}].member", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_artifact_registry_repository_iam_member", name, "member"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM member should not be a public principal", | ||
"keyActualValue": sprintf("Found public principal: %s", [member]), | ||
"remediation": json.marshal({ | ||
"before": "member = \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Use a non-public principal" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# Check for google_artifact_registry_repository_iam_member | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_artifact_registry_repository_iam_member[name] | ||
common_lib.valid_key(resource, "member") | ||
member := resource.member | ||
member == "allUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_artifact_registry_repository_iam_member", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_artifact_registry_repository_iam_member[{{%s}}].member", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_artifact_registry_repository_iam_member", name, "member"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM member should not be a public principal", | ||
"keyActualValue": sprintf("Found public principal: %s", [member]), | ||
"remediation": json.marshal({ | ||
"before": "member = \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Use a non-public principal" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# Check for google_artifact_registry_repository_iam_binding | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_artifact_registry_repository_iam_binding[name] | ||
common_lib.valid_key(resource, "members") | ||
member := resource.members[_] | ||
member == "allAuthenticatedUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_artifact_registry_repository_iam_binding", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_artifact_registry_repository_iam_binding[{{%s}}].members", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_artifact_registry_repository_iam_binding", name, "members"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM binding should not include public principals", | ||
"keyActualValue": "Public principal found in members", | ||
"remediation": json.marshal({ | ||
"before": "members includes \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Remove public principals from members" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# Check for google_artifact_registry_repository_iam_binding | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_artifact_registry_repository_iam_binding[name] | ||
common_lib.valid_key(resource, "members") | ||
member := resource.members[_] | ||
member == "allUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_artifact_registry_repository_iam_binding", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_artifact_registry_repository_iam_binding[{{%s}}].members", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_artifact_registry_repository_iam_binding", name, "members"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM binding should not include public principals", | ||
"keyActualValue": "Public principal found in members", | ||
"remediation": json.marshal({ | ||
"before": "members includes \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Remove public principals from members" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
assets/queries/terraform/gcp/artifact_registry_repository_is_public/test/negative0.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,7 @@ | ||
|
||
# IAM Binding compliant | ||
resource "google_artifact_registry_repository_iam_binding" "good_example_binding" { | ||
repository = "example-repo" | ||
members = ["user:[email protected]", "group:[email protected]"] # ✅ No public principals | ||
role = "roles/artifactregistry.admin" | ||
} |
6 changes: 6 additions & 0 deletions
6
assets/queries/terraform/gcp/artifact_registry_repository_is_public/test/negative1.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,6 @@ | ||
# IAM Member compliant | ||
resource "google_artifact_registry_repository_iam_member" "good_example_member" { | ||
repository = "example-repo" | ||
member = "user:[email protected]" # ✅ Non-public principal | ||
role = "roles/artifactregistry.reader" | ||
} |
13 changes: 13 additions & 0 deletions
13
assets/queries/terraform/gcp/artifact_registry_repository_is_public/test/positive.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,13 @@ | ||
# IAM Member violation | ||
resource "google_artifact_registry_repository_iam_member" "bad_example_member" { | ||
repository = "example-repo" | ||
member = "allUsers" # ❌ Public principal | ||
role = "roles/artifactregistry.reader" | ||
} | ||
|
||
# IAM Binding violation | ||
resource "google_artifact_registry_repository_iam_binding" "bad_example_binding" { | ||
repository = "example-repo" | ||
members = ["allAuthenticatedUsers", "user:[email protected]"] # ❌ Contains public principal | ||
role = "roles/artifactregistry.admin" | ||
} |
12 changes: 12 additions & 0 deletions
12
...s/terraform/gcp/artifact_registry_repository_is_public/test/positive_expected_result.json
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,12 @@ | ||
[ | ||
{ | ||
"queryName": "Artifact Registry Repo Is Public", | ||
"severity": "MEDIUM", | ||
"line": 4 | ||
}, | ||
{ | ||
"queryName": "Artifact Registry Repo Is Public", | ||
"severity": "MEDIUM", | ||
"line": 11 | ||
} | ||
] |
12 changes: 12 additions & 0 deletions
12
assets/queries/terraform/gcp/bigquery_table_is_public/metadata.json
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,12 @@ | ||
{ | ||
"id": "a9b8c7d6-e5f4-3210-abcd-1234567890ab", | ||
"queryName": "BigQuery Table Is Public", | ||
"severity": "HIGH", | ||
"category": "General Security", | ||
"descriptionText": "BigQuery tables must not be publicly accessible. Public principals like 'allUsers' or 'allAuthenticatedUsers' should not be assigned as IAM members or bindings, as this may expose sensitive data.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/bigquery_table_iam_member", | ||
"platform": "Terraform", | ||
"descriptionID": "a9b8c7d6", | ||
"cloudProvider": "gcp", | ||
"cwe": "284" | ||
} |
101 changes: 101 additions & 0 deletions
101
assets/queries/terraform/gcp/bigquery_table_is_public/query.rego
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,101 @@ | ||
package Cx | ||
|
||
import data.generic.terraform as tf_lib | ||
import data.generic.common as common_lib | ||
|
||
# For google_bigquery_table_iam_member resources | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_bigquery_table_iam_member[name] | ||
common_lib.valid_key(resource, "member") | ||
member := resource.member | ||
member == "allUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_bigquery_table_iam_member", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_bigquery_table_iam_member[{{%s}}].member", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_bigquery_table_iam_member", name, "member"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM member should not be a public principal", | ||
"keyActualValue": sprintf("Found public principal: %s", [member]), | ||
"remediation": json.marshal({ | ||
"before": "member = \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Use a non-public principal" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# For google_bigquery_table_iam_member resources | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_bigquery_table_iam_member[name] | ||
common_lib.valid_key(resource, "member") | ||
common_lib.valid_key(resource, "member") | ||
member := resource.member | ||
member == "allAuthenticatedUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_bigquery_table_iam_member", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_bigquery_table_iam_member[{{%s}}].member", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_bigquery_table_iam_member", name, "member"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM member should not be a public principal", | ||
"keyActualValue": sprintf("Found public principal: %s", [member]), | ||
"remediation": json.marshal({ | ||
"before": "member = \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Use a non-public principal" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# For google_bigquery_table_iam_binding resources | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_bigquery_table_iam_binding[name] | ||
common_lib.valid_key(resource, "members") | ||
member := resource.members[_] | ||
member == "allUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_bigquery_table_iam_binding", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_bigquery_table_iam_binding[{{%s}}].members", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_bigquery_table_iam_binding", name, "members"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM binding should not include public principals", | ||
"keyActualValue": "Public principal found in members", | ||
"remediation": json.marshal({ | ||
"before": "members includes \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Remove public principals from members" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} | ||
|
||
# For google_bigquery_table_iam_binding resources | ||
CxPolicy[result] { | ||
resource := input.document[i].resource.google_bigquery_table_iam_binding[name] | ||
common_lib.valid_key(resource, "members") | ||
member := resource.members[_] | ||
member == "allAuthenticatedUsers" | ||
|
||
result := { | ||
"documentId": input.document[i].id, | ||
"resourceType": "google_bigquery_table_iam_binding", | ||
"resourceName": tf_lib.get_resource_name(resource, name), | ||
"searchKey": sprintf("google_bigquery_table_iam_binding[{{%s}}].members", [name]), | ||
"searchLine": common_lib.build_search_line(["resource", "google_bigquery_table_iam_binding", name, "members"], []), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "IAM binding should not include public principals", | ||
"keyActualValue": "Public principal found in members", | ||
"remediation": json.marshal({ | ||
"before": "members includes \"allUsers\" or \"allAuthenticatedUsers\"", | ||
"after": "Remove public principals from members" | ||
}), | ||
"remediationType": "replacement" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
assets/queries/terraform/gcp/bigquery_table_is_public/test/negative0.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,6 @@ | ||
# IAM Member compliant | ||
resource "google_bigquery_table_iam_member" "good_example_member" { | ||
table = "example_table" | ||
member = "user:[email protected]" # ✅ Non-public principal | ||
role = "roles/bigquery.dataViewer" | ||
} |
6 changes: 6 additions & 0 deletions
6
assets/queries/terraform/gcp/bigquery_table_is_public/test/negative1.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,6 @@ | ||
# IAM Binding compliant | ||
resource "google_bigquery_table_iam_binding" "good_example_binding" { | ||
table = "example_table" | ||
members = ["user:[email protected]", "group:[email protected]"] # ✅ No public principals | ||
role = "roles/bigquery.dataViewer" | ||
} |
13 changes: 13 additions & 0 deletions
13
assets/queries/terraform/gcp/bigquery_table_is_public/test/positive.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,13 @@ | ||
# IAM Member violation | ||
resource "google_bigquery_table_iam_member" "bad_example_member" { | ||
table = "example_table" | ||
member = "allUsers" # ❌ Public principal | ||
role = "roles/bigquery.dataViewer" | ||
} | ||
|
||
# IAM Binding violation | ||
resource "google_bigquery_table_iam_binding" "bad_example_binding" { | ||
table = "example_table" | ||
members = ["allAuthenticatedUsers", "user:[email protected]"] # ❌ Contains public principal | ||
role = "roles/bigquery.dataViewer" | ||
} |
12 changes: 12 additions & 0 deletions
12
assets/queries/terraform/gcp/bigquery_table_is_public/test/positive_expected_result.json
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,12 @@ | ||
[ | ||
{ | ||
"queryName": "BigQuery Table Is Public", | ||
"severity": "MEDIUM", | ||
"line": 4 | ||
}, | ||
{ | ||
"queryName": "BigQuery Table Is Public", | ||
"severity": "MEDIUM", | ||
"line": 11 | ||
} | ||
] |
12 changes: 12 additions & 0 deletions
12
assets/queries/terraform/gcp/cloud_kms_key_rings_are_public/metadata.json
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,12 @@ | ||
{ | ||
"id": "d4e5f6g7-h8i9-0jkl-mnop-qrstuvwx1234", | ||
"queryName": "Cloud KMS Key Ring is anonymously or publicly accessible", | ||
"severity": "HIGH", | ||
"category": "ENCRYPTION", | ||
"descriptionText": "Cloud KMS Key Rings must not be publicly accessible. Public principals like 'allUsers' or 'allAuthenticatedUsers' should not be assigned in IAM member or binding configurations for key rings.", | ||
"descriptionUrl": "https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/kms_key_ring", | ||
"platform": "Terraform", | ||
"descriptionID": "d4e5f6g7", | ||
"cloudProvider": "gcp", | ||
"cwe": "311" | ||
} |
Oops, something went wrong.