# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # redshift_default_admin_check # # Description: # This control checks whether an Amazon Redshift cluster has changed the administrator username from its 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: 'MasterUsername' has not been specified # Then: FAIL # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a Redshift cluster resource # And: 'MasterUsername' has been specified # And: 'MasterUsername' has been set to 'awsuser' # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains a Redshift cluster resource # And: 'MasterUsername' has been specified # And: 'MasterUsername' has been set to a value not equal to 'awsuser' # Then: PASS # # Constants # let REDSHIFT_CLUSTER_TYPE = "AWS::Redshift::Cluster" let INPUT_DOCUMENT = this # # Assignments # let redshift_clusters = Resources.*[ Type == %REDSHIFT_CLUSTER_TYPE ] # # Primary Rules # rule redshift_default_admin_check when is_cfn_template(%INPUT_DOCUMENT) %redshift_clusters not empty { check(%redshift_clusters.Properties) << [CT.REDSHIFT.PR.6]: Require an Amazon Redshift cluster to have a unique administrator username [FIX]: Set 'MasterUsername' to a value other than 'awsuser'. >> } rule redshift_default_admin_check when is_cfn_hook(%INPUT_DOCUMENT, %REDSHIFT_CLUSTER_TYPE) { check(%INPUT_DOCUMENT.%REDSHIFT_CLUSTER_TYPE.resourceProperties) << [CT.REDSHIFT.PR.6]: Require an Amazon Redshift cluster to have a unique administrator username [FIX]: Set 'MasterUsername' to a value other than 'awsuser'. >> } # # Parameterized Rules # rule check(redshift_cluster) { %redshift_cluster { # Scenario 2 MasterUsername exists check_is_string_and_not_empty(MasterUsername) # Scenario 3 & 4 MasterUsername != "awsuser" } } # # Utility Rules # rule check_is_string_and_not_empty(value) { %value { this is_string this != /\A\s*\z/ } } rule is_cfn_template(doc) { %doc { AWSTemplateFormatVersion exists or Resources exists } } rule is_cfn_hook(doc, RESOURCE_TYPE) { %doc.%RESOURCE_TYPE.resourceProperties exists }