# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # codebuild_project_artifact_encryption_check # # Description: # This control checks whether AWS CodeBuild projects are configured to encrypt artifacts. # # Reports on: # AWS::CodeBuild::Project # # 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 CodeBuild project resources # Then: SKIP # Scenario 2: # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Artifacts' configuration is provided and is of 'Type' 'NO_ARTIFACTS' # And: 'SecondaryArtifacts' configuration is not provided or provided with an empty list # Then: SKIP # Scenario 3: # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Artifacts' configuration is provided and is of 'Type' 'NO_ARTIFACTS' # And: 'SecondaryArtifacts' configuration is provided as a non-empty list # And: All 'SecondaryArtifacts' entries have 'Type' set to 'NO_ARTIFACTS' # Then: SKIP # Scenario 4: # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Artifacts' configuration is provided and is not of 'Type' 'NO_ARTIFACTS' # And: 'EncryptionDisabled' within 'Artifacts' configuration is provided and set to bool(true) # Then: FAIL # Scenario 5: # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'SecondaryArtifacts' configuration is provided # And: There exists one or more items in 'SecondaryArtifacts' which have 'EncryptionDisabled' set to bool(true) # Then: FAIL # Scenario 6: # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Artifacts.EncryptionDisabled' is not provided, or is set to bool(false) # And: There exists no item in 'SecondaryArtifacts' which has 'EncryptionDisabled' set to bool(true) # Then: PASS # # Constants # let CODEBUILD_PROJECT_TYPE = "AWS::CodeBuild::Project" let INPUT_DOCUMENT = this # # Assignments # let codebuild_project = Resources.*[ Type == %CODEBUILD_PROJECT_TYPE ] # # Primary Rules # rule codebuild_project_artifact_encryption_check when is_cfn_template(%INPUT_DOCUMENT) %codebuild_project not empty { check(%codebuild_project.Properties) << [CT.CODEBUILD.PR.5]: Require encryption on all AWS CodeBuild project artifacts [FIX]: Set the 'EncryptionDisabled' property in 'Artifacts' and any 'SecondaryArtifacts' to 'false', or omit the 'EncryptionDisabled' property. >> } rule codebuild_project_artifact_encryption_check when is_cfn_hook(%INPUT_DOCUMENT, %CODEBUILD_PROJECT_TYPE) { check(%INPUT_DOCUMENT.%CODEBUILD_PROJECT_TYPE.resourceProperties) << [CT.CODEBUILD.PR.5]: Require encryption on all AWS CodeBuild project artifacts [FIX]: Set the 'EncryptionDisabled' property in 'Artifacts' and any 'SecondaryArtifacts' to 'false', or omit the 'EncryptionDisabled' property. >> } # # Parameterized Rules # rule check(codebuild_project) { %codebuild_project [ filter_codebuild_projects(this) ] { Artifacts { # Scenario 4 and 6 check_artifact(this) } # Scenario 5 SecondaryArtifacts not exists or check_secondary_artifacts(this) } } rule check_secondary_artifacts(codebuild_project) { %codebuild_project { SecondaryArtifacts is_list SecondaryArtifacts[*] { # Scenario 5 and 6 check_artifact(this) } } } rule check_artifact(artifact) { %artifact { EncryptionDisabled not exists or EncryptionDisabled == false } } rule filter_codebuild_projects(codebuild_project) { %codebuild_project { # Scenario 2 and 3 Artifacts exists Artifacts is_struct Artifacts { filter_artifact(this) } or filter_secondary_artifacts(this) } } rule filter_secondary_artifacts(codebuild_project) { %codebuild_project { # Scenario 2 SecondaryArtifacts exists SecondaryArtifacts is_list SecondaryArtifacts not empty SecondaryArtifacts[*] { # Scenario 3 filter_artifact(this) } } } rule filter_artifact(artifact) { %artifact { Type exists Type != "NO_ARTIFACTS" } } # # 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 }