# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # ecs_service_assign_public_ip_disabled_check # # Description: # This control checks whether your Amazon ECS services are configured to assign public IP addresses automatically. # # Reports on: # AWS::ECS::Service # # Evaluates: # AWS CloudFormation, AWS CloudFormation hook # # Rule Parameters: # None # # Scenarios: # Scenario: 1 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document does not contain an ECS service resource # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECS service resource # And: 'NetworkConfiguration' property is not present # Then: SKIP # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECS service resource # And: 'NetworkConfiguration.AwsvpcConfiguration' property is not present # Then: SKIP # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECS service resource # And: 'NetworkConfiguration.AwsvpcConfiguration' property is present # And: 'AssignPublicIp' property is present and set to 'ENABLED' # Then: FAIL # Scenario: 5 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECS service resource # And: 'NetworkConfiguration.AwsvpcConfiguration' property is present # And: 'AssignPublicIp' property is not present # Then: PASS # Scenario: 6 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECS service resource # And: 'NetworkConfiguration.AwsvpcConfiguration' property is present # And: 'AssignPublicIp' property is present and set to 'DISABLED' # Then: PASS # # Constants # let ECS_SERVICE_TYPE = "AWS::ECS::Service" let INPUT_DOCUMENT = this # # Assignments # let ecs_services = Resources.*[ Type == %ECS_SERVICE_TYPE ] # # Primary Rules # rule ecs_service_assign_public_ip_disabled_check when is_cfn_template(%INPUT_DOCUMENT) %ecs_services not empty { check(%ecs_services.Properties) << [CT.ECS.PR.9]: Require Amazon ECS services not to assign public IP addresses automatically [FIX]: Set 'AssignPublicIp' in 'NetworkConfiguration.AwsvpcConfiguration' to 'DISABLED'. >> } rule ecs_service_assign_public_ip_disabled_check when is_cfn_hook(%INPUT_DOCUMENT, %ECS_SERVICE_TYPE) { check(%INPUT_DOCUMENT.%ECS_SERVICE_TYPE.resourceProperties) << [CT.ECS.PR.9]: Require Amazon ECS services not to assign public IP addresses automatically [FIX]: Set 'AssignPublicIp' in 'NetworkConfiguration.AwsvpcConfiguration' to 'DISABLED'. >> } # # Parameterized Rules # rule check(ecs_service) { %ecs_service [filter_ecs_service_with_vpc_configuration(this)] { NetworkConfiguration { AwsvpcConfiguration { # Scenario 5 AssignPublicIp not exists or # Scenario 6 check_assign_public_ip_property(AssignPublicIp) } } } } rule check_assign_public_ip_property(public_ip) { %public_ip { this is_string this == "DISABLED" } } rule filter_ecs_service_with_vpc_configuration(ecs_service) { %ecs_service { # Scenario 2 NetworkConfiguration exists NetworkConfiguration is_struct # Scenarion 3 and 4 NetworkConfiguration { AwsvpcConfiguration exists AwsvpcConfiguration is_struct } } } # # Utility Rules # rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }