Skip to content
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

feat(terraform): PC Policy Team Yaml Policies Check-in #3785

Merged
merged 4 commits into from
Nov 8, 2022
Merged
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,10 @@
metadata:
id: "CKV2_AWS_41"
name: "Ensure an IAM role is attached to EC2 instance"
category: "IAM"
definition:
cond_type: "attribute"
resource_types:
- "aws_instance"
attribute: "iam_instance_profile"
operator: "exists"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
metadata:
id: "CKV2_GCP_10"
name: "Ensure GCP Cloud Function HTTP trigger is secured"
category: "NETWORKING"
definition:
cond_type: "attribute"
resource_types:
- "google_cloudfunctions_function"
attribute: "https_trigger_security_level"
operator: "equals"
value: "SECURE_ALWAYS"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
metadata:
id: "CKV2_GCP_11"
name: "Ensure GCP GCR Container Vulnerability Scanning is enabled"
category: "GENERAL_SECURITY"
definition:
cond_type: "attribute"
resource_types:
- "google_project_services"
attribute: "services"
operator: "contains"
value: "containerscanning.googleapis.com"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pass:
- "google_cloudfunctions_function.pass"
fail:
- "google_cloudfunctions_function.fail_1"
- "google_cloudfunctions_function.fail_2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "google_cloudfunctions_function" "pass" {
name = "function-test"
description = "My function"
runtime = "nodejs16"

available_memory_mb = 128
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
trigger_http = true
https_trigger_security_level = "SECURE_ALWAYS"
timeout = 60
entry_point = "helloGET"
labels = {
my-label = "my-label-value"
}
}

resource "google_cloudfunctions_function" "fail_1" {
name = "function-test"
description = "My function"
runtime = "nodejs16"

available_memory_mb = 128
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
trigger_http = true
https_trigger_security_level = "SECURE_OPTIONAL"
timeout = 60
entry_point = "helloGET"
labels = {
my-label = "my-label-value"
}
}

resource "google_cloudfunctions_function" "fail_2" {
name = "function-test"
description = "My function"
runtime = "nodejs16"

available_memory_mb = 128
source_archive_bucket = google_storage_bucket.bucket.name
source_archive_object = google_storage_bucket_object.archive.name
trigger_http = true
timeout = 60
entry_point = "helloGET"
labels = {
my-label = "my-label-value"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pass:
- "aws_instance.pass"
fail:
- "aws_instance.fail"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "aws_instance" "pass" {
ami = "ami-005e54dee72cc1d00" # us-west-2
instance_type = "t2.micro"
iam_instance_profile = "test"

network_interface {
network_interface_id = aws_network_interface.foo.id
device_index = 0
}

credit_specification {
cpu_credits = "unlimited"
}
}

resource "aws_instance" "fail" {
ami = "ami-005e54dee72cc1d00"
instance_type = "t2.micro"

network_interface {
network_interface_id = aws_network_interface.foo.id
device_index = 0
}

credit_specification {
cpu_credits = "unlimited"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pass:
- "google_project_services.pass_1"
fail:
- "google_project_services.fail_1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "google_project_services" "pass_1" {
project = "your-project-id"
services = ["iam.googleapis.com", "cloudresourcemanager.googleapis.com", "containerscanning.googleapis.com"]
}

resource "google_project_services" "fail_1" {
project = "your-project-id"
services = ["iam.googleapis.com", "cloudresourcemanager.googleapis.com"]
}
9 changes: 9 additions & 0 deletions tests/terraform/graph/checks/test_yaml_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def test_GuardDutyIsEnabled(self):
def test_SGAttachedToResource(self):
self.go("SGAttachedToResource")

def test_EC2InstanceHasIAMRoleAttached(self):
self.go("EC2InstanceHasIAMRoleAttached")

def test_StorageContainerActivityLogsNotPublic(self):
self.go("StorageContainerActivityLogsNotPublic")

Expand Down Expand Up @@ -86,6 +89,9 @@ def test_DisableAccessToSqlDBInstanceForRootUsersWithoutPassword(self):
def test_GCPProjectHasNoLegacyNetworks(self):
self.go("GCPProjectHasNoLegacyNetworks")

def test_GCRContainerVulnerabilityScanningEnabled(self):
self.go("GCRContainerVulnerabilityScanningEnabled")

def test_AzureDataFactoriesEncryptedWithCustomerManagedKey(self):
self.go("AzureDataFactoriesEncryptedWithCustomerManagedKey")

Expand All @@ -104,6 +110,9 @@ def test_ALBRedirectsHTTPToHTTPS(self):
def test_GCPLogBucketsConfiguredUsingLock(self):
self.go("GCPLogBucketsConfiguredUsingLock")

def test_CloudFunctionSecureHTTPTrigger(self):
self.go("CloudFunctionSecureHTTPTrigger")

def test_GCPAuditLogsConfiguredForAllServicesAndUsers(self):
self.go("GCPAuditLogsConfiguredForAllServicesAndUsers")

Expand Down