Project: KICS (Provisioning / Security & Compliance)
File: 4beaf898-9f8b-4237-89e2-5ffdc7ee6006.md

title: Cloudwatch Security Group Changes Alarm Missing hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 4beaf898-9f8b-4237-89e2-5ffdc7ee6006 Query name: Cloudwatch Security Group Changes Alarm Missing Platform: Terraform Severity: <span style="color:#ff7213">Medium</span> Category: Observability URL: Ensure a log metric filter and alarm exist for security group changes<br> ```tf title="Positive test num. 1 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "CISSecurityGroupChangesMetric_Filter" { name = "CIS-SecurityGroupChanges" pattern = "{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupEgress) || ($.eventName = CreateSecurityGroup) || ($.eventName = DeleteSecurityGroup)}" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-SecurityGroupChanges" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "CISSecurityGroupChangesCWAlarm" { alarm_name = "CIS-3.10-SecurityGroupChanges" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metric_name = "XXXX NOT YOUR FILTER XXXX" namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring changes to security group will help ensure that resources and services are not unintentionally exposed." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ``` ```tf title="Positive test num. 2 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "cisunauthorizedapicallsmetric_filter" { name = "CIS-UnauthorizedAPICalls" pattern = "{ ($.errorCode = \"UnauthorizedOperation\") || ($.errorCode = \"AccessDenied\") }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-UnauthorizedAPICalls" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisunauthorizedapicallscwalarm" { alarm_name = "CIS-3.1-UnauthorizedAPICalls" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisunauthorizedapicallsmetricfilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring unauthorized API calls will help reveal application errors and may reduce time to detect malicious activity." alarmactions = [awssnstopic.cisalertssnstopic.arn] insufficientdataactions = [] } ``` ```tf title="Positive test num. 3 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "CISSecurityGroupChangesMetric_Filter" { name = "CIS-SecurityGroupChanges" pattern = "{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = CreateSecurityGroup) || ($.eventName = DeleteSecurityGroup)}" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-SecurityGroupChanges" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "CISSecurityGroupChangesCWAlarm" { alarm_name = "CIS-3.10-SecurityGroupChanges" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.CISSecurityGroupChangesMetricFilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring changes to security group will help ensure that resources and services are not unintentionally exposed." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ``` ```tf title="Negative test num. 1 - tf file" resource "awscloudwatchlogmetricfilter" "CISSecurityGroupChangesMetric_Filter" { name = "CIS-SecurityGroupChanges" pattern = "{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupEgress) || ($.eventName = CreateSecurityGroup) || ($.eventName = DeleteSecurityGroup)}" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-SecurityGroupChanges" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "CISSecurityGroupChangesCWAlarm" { alarm_name = "CIS-3.10-SecurityGroupChanges" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.CISSecurityGroupChangesMetricFilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring changes to security group will help ensure that resources and services are not unintentionally exposed." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ```