# ################################### ## Rule Specification ## ##################################### # # Rule Identifier: # rds_instance_enhanced_monitoring_enabled_check # # Description: # This control checks whether enhanced monitoring is activated for Amazon RDS instances. # # 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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', '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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', 'postgres', 'sqlserver-ee', # 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MonitoringInterval' has not been specified # 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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', 'postgres', 'sqlserver-ee', # 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MonitoringInterval' has been specified # And: 'MonitoringInterval' has been set to '0' # Then: FAIL # Scenario: 5 # 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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', 'postgres', 'sqlserver-ee', # 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MonitoringInterval' has been specified # And: 'MonitoringInterval' has not been set to a value from the list 1, 5, 10, 15, 30, 60 # Then: FAIL # Scenario: 6 # 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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', 'postgres', 'sqlserver-ee', # 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MonitoringInterval' has been specified # And: 'MonitoringInterval' has been set to a value from the list 1, 5, 10, 15, 30, 60 # And: 'MonitoringRoleArn' has not been specified or specified as an empty string # Then: FAIL # Scenario: 7 # 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 'aurora', 'aurora-mysql', 'aurora-postgresql', 'mariadb', 'mysql', # 'oracle-ee', 'oracle-se2', 'oracle-se1', 'oracle-se', 'postgres', 'sqlserver-ee', # 'sqlserver-se', 'sqlserver-ex', 'sqlserver-web' # And: 'MonitoringInterval' has been specified # And: 'MonitoringInterval' has been set to a value from the list 1, 5, 10, 15, 30, 60 # And: 'MonitoringRoleArn' has been specified with a non-empty string or valid local reference # Then: PASS # # Constants # let RDS_DB_INSTANCE_TYPE = "AWS::RDS::DBInstance" let INPUT_DOCUMENT = this let SUPPORTED_RDS_INSTANCE_ENGINES = [ "aurora", "aurora-mysql", "aurora-postgresql", "mariadb", "mysql", "oracle-ee", "oracle-ee-cdb", "oracle-se2", "oracle-se2-cdb", "postgres", "sqlserver-ee", "sqlserver-se", "sqlserver-ex", "sqlserver-web" ] let ALLOWED_EM_VALUES = [1, 5, 10, 15, 30, 60] # # Assignments # let rds_db_instances = Resources.*[ Type == %RDS_DB_INSTANCE_TYPE ] # # Primary Rules # rule rds_instance_enhanced_monitoring_enabled_check when is_cfn_template(%INPUT_DOCUMENT) %rds_db_instances not empty { check(%rds_db_instances.Properties) << [CT.RDS.PR.2]: Require an Amazon RDS database instance or cluster to have enhanced monitoring configured [FIX]: Set 'MonitoringInterval' to a supported value (1, 5, 10, 15, 30, 60), and set 'MonitoringRoleArn' to the ARN of an AWS IAM role. >> } rule rds_instance_enhanced_monitoring_enabled_check when is_cfn_hook(%INPUT_DOCUMENT, %RDS_DB_INSTANCE_TYPE) { check(%INPUT_DOCUMENT.%RDS_DB_INSTANCE_TYPE.resourceProperties) << [CT.RDS.PR.2]: Require an Amazon RDS database instance or cluster to have enhanced monitoring configured [FIX]: Set 'MonitoringInterval' to a supported value (1, 5, 10, 15, 30, 60), and set 'MonitoringRoleArn' to the ARN of an AWS IAM role. >> } # # Parameterized Rules # rule check(rds_db_instance) { %rds_db_instance [filter_engine(this)] { # Scenario: 3, 4, 5, 6 and 7 MonitoringInterval exists MonitoringInterval in %ALLOWED_EM_VALUES # Scenario: 6 and 7 MonitoringRoleArn exists check_for_valid_monitor_role_arn(MonitoringRoleArn) } } rule filter_engine(db_properties) { %db_properties { # Scenario: 2 Engine exists Engine is_string Engine in %SUPPORTED_RDS_INSTANCE_ENGINES } } rule check_for_valid_monitor_role_arn(iam_role_arn) { %iam_role_arn { check_is_string_and_not_empty(this) or check_local_references(%INPUT_DOCUMENT, this, "AWS::IAM::Role") } } # # 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/ } } rule check_local_references(doc, reference_properties, referenced_resource_type) { %reference_properties { 'Fn::GetAtt' { query_for_resource(%doc, this[0], %referenced_resource_type) <> } or Ref { query_for_resource(%doc, this, %referenced_resource_type) <> } } } rule query_for_resource(doc, resource_key, referenced_resource_type) { let referenced_resource = %doc.Resources[ keys == %resource_key ] %referenced_resource not empty %referenced_resource { Type == %referenced_resource_type } }