# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # codebuild_project_environment_privileged_check # # Description: # This control checks whether AWS CodeBuild projects have privileged mode turned off. # # 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: 'Environment' configuration is not provided # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Environment' configuration is provided # And: 'PrivilegedMode' within the 'Environment' configuration is provided and set to bool(true) # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Environment' configuration is provided # And: 'PrivilegedMode' within 'Environment' configuration is not provided # Then: PASS # Scenario: 5 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a CodeBuild project resource # And: 'Environment' configuration is provided # And: 'PrivilegedMode' within 'Environment' configuration is set to bool(false) # Then: PASS # # Constants # let CODEBUILD_PROJECT_TYPE = "AWS::CodeBuild::Project" let INPUT_DOCUMENT = this # # Assignments # let codebuild_projects = Resources.*[ Type == %CODEBUILD_PROJECT_TYPE ] # # Primary Rules # rule codebuild_project_environment_privileged_check when is_cfn_template(%INPUT_DOCUMENT) %codebuild_projects not empty { check(%codebuild_projects.Properties) << [CT.CODEBUILD.PR.4]: Require any AWS CodeBuild project to deactivate privileged mode when running [FIX]: Within 'Environment', set 'PrivilegedMode' to 'false' or omit the 'PrivilegedMode' property. >> } rule codebuild_project_environment_privileged_check when is_cfn_hook(%INPUT_DOCUMENT, %CODEBUILD_PROJECT_TYPE) { check(%INPUT_DOCUMENT.%CODEBUILD_PROJECT_TYPE.resourceProperties) << [CT.CODEBUILD.PR.4]: Require any AWS CodeBuild project to deactivate privileged mode when running [FIX]: Within 'Environment', set 'PrivilegedMode' to 'false' or omit the 'PrivilegedMode' property. >> } # # Parameterized Rules # rule check(codebuild_project) { %codebuild_project { # Scenario 2 Environment exists Environment is_struct Environment { # Scenario 4 PrivilegedMode not exists or # Scenario 3 and 5 PrivilegedMode == 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 }