# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # redshift_default_db_name_check # # Description: # This control checks whether an Amazon Redshift cluster has changed its database name from the default value. # # Reports on: # AWS::Redshift::Cluster # # 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 Redshift cluster resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a Redshift cluster resource # And: The 'DBName' property 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 Redshift cluster resource # And: The 'DBName' property has been provided with a value of 'dev' or an empty string # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains Redshift cluster resource # And: The 'DBName' property has been provided with a non-empty string that is not equal to 'dev' # Then: PASS # # Constants # let RESOURCE_TYPE = "AWS::Redshift::Cluster" let INPUT_DOCUMENT = this let INVALID_DB_NAME_STRING = "dev" # # Assignments # let redshift_clusters = Resources.*[ Type == %RESOURCE_TYPE ] # # Primary Rules # rule redshift_default_db_name_check when is_cfn_template(%INPUT_DOCUMENT) %redshift_clusters not empty { check_db_name(%redshift_clusters.Properties) << [CT.REDSHIFT.PR.7]: Require an Amazon Redshift cluster to have a unique database name [FIX]: Set 'DBName' to a database name that is different from the default value of 'dev'. >> } rule redshift_default_db_name_check when is_cfn_hook(%INPUT_DOCUMENT, %RESOURCE_TYPE) { check_db_name(%INPUT_DOCUMENT.%RESOURCE_TYPE.resourceProperties) << [CT.REDSHIFT.PR.7]: Require an Amazon Redshift cluster to have a unique database name [FIX]: Set 'DBName' to a database name that is different from the default value of 'dev'. >> } # # Parameterized Rules # rule check_db_name(redshift_cluster) { %redshift_cluster { # Scenario 2 DBName exists # Scenario 3 and 4 check_is_string_and_not_empty(DBName) DBName != %INVALID_DB_NAME_STRING } } # # 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 } rule check_is_string_and_not_empty(value) { %value { this is_string this != /\A\s*\z/ } }