# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # ec2_transit_gateway_auto_vpc_attach_disabled_check # # Description: # This control checks whether Amazon EC2 transit gateways are configured to accept Amazon VPC attachment requests automatically. # # Reports on: # AWS::EC2::TransitGateway # # 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 transit gateway resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 transit gateway resource # And: 'AutoAcceptSharedAttachments' configuration has been provided and is set to a value other than 'disable' # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 transit gateway resource # And: 'AutoAcceptSharedAttachments' configuration has not been provided # Then: PASS # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an EC2 transit gateway resource # And: 'AutoAcceptSharedAttachments' configuration has been provided and set to 'disable' # Then: PASS # # Constants # let EC2_TRANSIT_GATEWAY_TYPE = "AWS::EC2::TransitGateway" let INPUT_DOCUMENT = this # # Assignments # let ec2_transit_gateway = Resources.*[ Type == %EC2_TRANSIT_GATEWAY_TYPE ] # # Primary Rules # rule ec2_transit_gateway_auto_vpc_attach_disabled_check when is_cfn_template(%INPUT_DOCUMENT) %ec2_transit_gateway not empty { check(%ec2_transit_gateway.Properties) << [CT.EC2.PR.6]: Require that Amazon EC2 transit gateways refuse automatic Amazon VPC attachment requests [FIX]: Omit the 'AutoAcceptSharedAttachments' property or set the property to 'disable'. >> } rule ec2_transit_gateway_auto_vpc_attach_disabled_check when is_cfn_hook(%INPUT_DOCUMENT, %EC2_TRANSIT_GATEWAY_TYPE) { check(%INPUT_DOCUMENT.%EC2_TRANSIT_GATEWAY_TYPE.resourceProperties) << [CT.EC2.PR.6]: Require that Amazon EC2 transit gateways refuse automatic Amazon VPC attachment requests [FIX]: Omit the 'AutoAcceptSharedAttachments' property or set the property to 'disable'. >> } # # Parameterized Rules # rule check(ec2_transit_gateway) { %ec2_transit_gateway { # Scenario 3 AutoAcceptSharedAttachments not exists or # Scenario 2 and 4 AutoAcceptSharedAttachments == "disable" } } # # 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 }