diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/metadata.json b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/metadata.json new file mode 100644 index 00000000000..78a1164bb36 --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/metadata.json @@ -0,0 +1,11 @@ +{ + "id": "abcefee4-a0c1-4245-9f82-a473f79a9e2f", + "queryName": "ECS Cluster with Container Insights Disabled", + "severity": "LOW", + "category": "Observability", + "descriptionText": "ECS Cluster should enable container insights", + "descriptionUrl": "https://www.pulumi.com/registry/packages/aws/api-docs/ecs/cluster/#settings_yaml", + "platform": "Pulumi", + "descriptionID": "6fd99865", + "cloudProvider": "aws" +} diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/query.rego b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/query.rego new file mode 100644 index 00000000000..89f03888651 --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/query.rego @@ -0,0 +1,45 @@ +package Cx + +import data.generic.common as common_lib +import data.generic.pulumi as plm_lib + +CxPolicy[result] { + resource := input.document[i].resources[name] + resource.type == "aws:ecs:Cluster" + + not common_lib.valid_key(resource.properties, "settings") + + result := { + "documentId": input.document[i].id, + "resourceType": resource.type, + "resourceName": plm_lib.getResourceName(resource, name), + "searchKey": sprintf("resources[%s].properties", [name]), + "issueType": "MissingAttribute", + "keyExpectedValue": "Attribute 'settings' should be defined and have a ClusterSetting named 'containerInsights' which value is 'enabled'", + "keyActualValue": "Attribute 'settings' is not defined", + "searchLine": common_lib.build_search_line(["resources", name, "properties"], []), + } +} + +CxPolicy[result] { + resource := input.document[i].resources[name] + resource.type == "aws:ecs:Cluster" + + not containerInsights(resource.properties.settings) + + result := { + "documentId": input.document[i].id, + "resourceType": resource.type, + "resourceName": plm_lib.getResourceName(resource, name), + "searchKey": sprintf("resources[%s].properties.settings", [name]), + "issueType": "IncorrectValue", + "keyExpectedValue": "Attribute 'settings' should have a ClusterSetting named 'containerInsights' which value is 'enabled'", + "keyActualValue": "Attribute 'settings' doesn't have a ClusterSetting named 'containerInsights' which value is 'enabled'", + "searchLine": common_lib.build_search_line(["resources", name, "properties","settings"], []), + } +} + +containerInsights(settings){ + settings[0].name == "containerInsights" + settings[0].value == "enabled" +} \ No newline at end of file diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/negative1.yaml b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/negative1.yaml new file mode 100644 index 00000000000..1577efb4f8a --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/negative1.yaml @@ -0,0 +1,10 @@ +name: aws-eks +runtime: yaml +description: An EKS cluster +resources: + foo: + type: aws:ecs:Cluster + properties: + settings: + - name: containerInsights + value: enabled \ No newline at end of file diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive1.yaml b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive1.yaml new file mode 100644 index 00000000000..862abcdd756 --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive1.yaml @@ -0,0 +1,10 @@ +name: aws-eks +runtime: yaml +description: An EKS cluster +resources: + foo: + type: aws:ecs:Cluster + properties: + settings: + - name: containerInsights + value: disabled \ No newline at end of file diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive2.yaml b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive2.yaml new file mode 100644 index 00000000000..453efd8085e --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive2.yaml @@ -0,0 +1,8 @@ +name: aws-eks +runtime: yaml +description: An EKS cluster +resources: + foo: + type: aws:ecs:Cluster + properties: + settings: [] \ No newline at end of file diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive3.yaml b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive3.yaml new file mode 100644 index 00000000000..c8978026faa --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive3.yaml @@ -0,0 +1,8 @@ +name: aws-eks +runtime: yaml +description: An EKS cluster +resources: + foo: + type: aws:ecs:Cluster + properties: + description: example diff --git a/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive_expected_result.json b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive_expected_result.json new file mode 100644 index 00000000000..601fa6515b7 --- /dev/null +++ b/assets/queries/pulumi/aws/ecs_cluster_container_insights_disabled/test/positive_expected_result.json @@ -0,0 +1,20 @@ +[ + { + "queryName": "ECS Cluster with Container Insights Disabled", + "severity": "LOW", + "line": 8, + "fileName": "positive1.yaml" + }, + { + "queryName": "ECS Cluster with Container Insights Disabled", + "severity": "LOW", + "line": 8, + "fileName": "positive2.yaml" + }, + { + "queryName": "ECS Cluster with Container Insights Disabled", + "severity": "LOW", + "line": 7, + "fileName": "positive3.yaml" + } +]