# ################################### ## Rule Specification ## ##################################### # # # Rule Identifier: # subnet_auto_assign_public_ip_disabled_check # # Description: # This control checks whether your Amazon VPC subnets automatically assign public IP addresses. # # Reports on: # AWS::EC2::Subnet # # 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 any EC2 subnet resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 subnet resource # And: 'MapPublicIpOnLaunch' is present and set to bool(true) # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 subnet resource # And: 'MapPublicIpOnLaunch' is not present # Then: PASS # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 subnet resource # And: 'MapPublicIpOnLaunch' is present and set to bool(false) # Then: PASS # # Constants # let EC2_SUBNET_TYPE = "AWS::EC2::Subnet" let INPUT_DOCUMENT = this # # Assignments # let ec2_subnets = Resources.*[ Type == %EC2_SUBNET_TYPE ] # # Primary Rules # rule subnet_auto_assign_public_ip_disabled_check when is_cfn_template(%INPUT_DOCUMENT) %ec2_subnets not empty { check(%ec2_subnets.Properties) << [CT.EC2.PR.11]: Require that an Amazon EC2 subnet does not automatically assign public IP addresses [FIX]: Omit the 'MapPublicIpOnLaunch' property to use the default configuration, or set the 'MapPublicIpOnLaunch' property to 'false'. >> } rule subnet_auto_assign_public_ip_disabled_check when is_cfn_hook(%INPUT_DOCUMENT, %EC2_SUBNET_TYPE) { check(%INPUT_DOCUMENT.%EC2_SUBNET_TYPE.resourceProperties) << [CT.EC2.PR.11]: Require that an Amazon EC2 subnet does not automatically assign public IP addresses [FIX]: Omit the 'MapPublicIpOnLaunch' property to use the default configuration, or set the 'MapPublicIpOnLaunch' property to 'false'. >> } # # Parameterized Rules # rule check(ec2_subnet) { %ec2_subnet { # Scenario 3 MapPublicIpOnLaunch not exists or # Scenarios 2 and 4 MapPublicIpOnLaunch == false } } # # 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 }