# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # ecr_private_tag_immutability_enabled_check # # Description: # This control checks whether a private Amazon ECR repository has tag immutability enabled. # # Reports on: # AWS::ECR::Repository # # 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 ECR repository resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECR repository resource # And: 'ImageTagMutability' has not been provided # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECR repository resource # And: 'ImageTagMutability' has been provided with a value of 'MUTABLE' # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an ECR repository resource # And: 'ImageTagMutability' has been provided with a value of 'IMMUTABLE' # Then: PASS # # Constants # let ECR_REPOSITORY_TYPE = "AWS::ECR::Repository" let INPUT_DOCUMENT = this # # Assignments # let ecr_repositories = Resources.*[ Type == %ECR_REPOSITORY_TYPE ] # # Primary Rules # rule ecr_private_tag_immutability_enabled_check when is_cfn_template(%INPUT_DOCUMENT) %ecr_repositories not empty { check(%ecr_repositories.Properties) << [CT.ECR.PR.3]: Require Amazon ECR private repositories to have tag immutability enabled [FIX]: Set 'ImageTagMutability' to 'IMMUTABLE'. >> } rule ecr_private_tag_immutability_enabled_check when is_cfn_hook(%INPUT_DOCUMENT, %ECR_REPOSITORY_TYPE) { check(%INPUT_DOCUMENT.%ECR_REPOSITORY_TYPE.resourceProperties) << [CT.ECR.PR.3]: Require Amazon ECR private repositories to have tag immutability enabled [FIX]: Set 'ImageTagMutability' to 'IMMUTABLE'. >> } # # Parameterized Rules # rule check(ecr_repository) { %ecr_repository { # Scenario 2, 3 and 4 ImageTagMutability exists ImageTagMutability == "IMMUTABLE" } } # # 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 }