# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # rds_instance_default_admin_check # # Description: # This control checks whether an Amazon RDS database has changed the adminstrator username from its default value. # # Reports on: # AWS::RDS::DBInstance # # 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 RDS DB instance resources # Then: SKIP # Scenario: 2 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an RDS DB instance resource # And: 'Engine' is not one of 'mariadb', 'mysql', 'oracle-ee', 'oracle-ee-cdb', 'oracle-se2', # 'oracle-se2-cdb', 'postgres', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # Then: SKIP # Scenario: 3 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an RDS DB instance resource # And: 'Engine' is one of 'mariadb', 'mysql', 'oracle-ee', 'oracle-ee-cdb', 'oracle-se2', # 'oracle-se2-cdb', 'postgres', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MasterUsername' has been specified and is one of 'postgres' or 'admin' # Then: FAIL # Scenario: 4 # Given: The input document is an AWS CloudFormation or CloudFormation hook document # And: The input document contains an RDS DB instance resource # And: 'Engine' is one of 'mariadb', 'mysql', 'oracle-ee', 'oracle-ee-cdb', 'oracle-se2', # 'oracle-se2-cdb', 'postgres', 'sqlserver-ee', 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MasterUsername' has been specified and is not one of 'postgres' or 'admin' # Then: PASS # # Constants # let RDS_DB_INSTANCE_TYPE = "AWS::RDS::DBInstance" let INPUT_DOCUMENT = this let SUPPORTED_RDS_INSTANCE_ENGINES = [ "mariadb", "mysql", "oracle-ee", "oracle-ee-cdb", "oracle-se2", "oracle-se2-cdb", "postgres", "sqlserver-ee", "sqlserver-se", "sqlserver-ex", "sqlserver-web" ] let RDS_DEFAULT_USERNAMES = [ "postgres", "admin" ] # # Assignments # let rds_db_instances = Resources.*[ Type == %RDS_DB_INSTANCE_TYPE ] # # Primary Rules # rule rds_instance_default_admin_check when is_cfn_template(%INPUT_DOCUMENT) %rds_db_instances not empty { check(%rds_db_instances.Properties) << [CT.RDS.PR.22]: Require an Amazon RDS database instance to have a unique administrator username [FIX]: Set 'MasterUsername' to a value other than 'postgres' or 'admin'. >> } rule rds_instance_default_admin_check when is_cfn_hook(%INPUT_DOCUMENT, %RDS_DB_INSTANCE_TYPE) { check(%INPUT_DOCUMENT.%RDS_DB_INSTANCE_TYPE.resourceProperties) << [CT.RDS.PR.22]: Require an Amazon RDS database instance to have a unique administrator username [FIX]: Set 'MasterUsername' to a value other than 'postgres' or 'admin'. >> } # # Parameterized Rules # rule check(rds_db_instance) { %rds_db_instance [ filter_engine_and_master_username_provided(this) ] { # Scenario: 3 and 4 MasterUsername not in %RDS_DEFAULT_USERNAMES } } rule filter_engine_and_master_username_provided(db_properties) { %db_properties { # Scenario: 2 MasterUsername exists Engine exists Engine is_string Engine in %SUPPORTED_RDS_INSTANCE_ENGINES } } # # 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 }