This rule ensures the presence of a log metric filter and alarm for any security group changes in the system.
Rule | Ensure a log metric filter and alarm exist for security group changes |
Framework | cis_v140 |
Severity | ✔ Medium |
Ensure a Log Metric Filter and Alarm Exist for Security Group Changes (CIS v1.4.0)
Security groups act as virtual firewalls for your EC2 instances to control inbound and outbound traffic. Monitoring changes to security groups is crucial for maintaining the security of an AWS environment.
Rule Description
This rule ensures that your AWS environment has the necessary log metric filters and alarms to detect changes to EC2 security groups. The logging should capture events like
AuthorizeSecurityGroupIngress
, RevokeSecurityGroupIngress
, AuthorizeSecurityGroupEgress
, and RevokeSecurityGroupEgress
. Having a metric filter and alarm in place allows you to respond quickly to any unauthorized and potentially malicious modifications.Prerequisites
Before setting up the necessary metric filter and alarm, ensure that:
Step by Step Guide for Remediation
Step 1: Create the Metric Filter
Navigate to CloudWatch in the AWS Management Console.
Go to Logs and choose the log group that receives CloudTrail events.
Select
Create Metric Filter
.In the
Filter Pattern
box, enter the following pattern:{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupEgress) }
Click
Assign Metric
.Define the filter name and metric details:
SecurityGroupChanges
CISBenchmark
SecurityGroupEventCount
Click
Create Filter
.Step 2: Create the Alarm
Create Alarm
.Sum
.5 minutes
.SecurityGroupChangeAlarm
.Create Alarm
.Necessary AWS CLI Commands
To create a metric filter and alarm through AWS CLI, use the following commands:
Create Metric Filter
aws logs put-metric-filter \ --log-group-name <cloudtrail-log-group-name> \ --filter-name SecurityGroupChanges \ --filter-pattern '{ ($.eventName = AuthorizeSecurityGroupIngress) || ($.eventName = RevokeSecurityGroupIngress) || ($.eventName = AuthorizeSecurityGroupEgress) || ($.eventName = RevokeSecurityGroupEgress) }' \ --metric-transformations metricName=SecurityGroupEventCount,metricNamespace=CISBenchmark,metricValue=1
Create Alarm
aws cloudwatch put-metric-alarm \ --alarm-name SecurityGroupChangeAlarm \ --metric-name SecurityGroupEventCount \ --namespace CISBenchmark \ --statistic Sum \ --period 300 \ --evaluation-periods 1 \ --threshold 0 \ --comparison-operator GreaterThanThreshold \ --alarm-actions <sns-topic-arn> \ --insufficient-data-actions <sns-topic-arn>
Replace
<cloudtrail-log-group-name>
with the actual name of the log group, <sns-topic-arn>
with the ARN of your SNS topic, and adjust other parameter values as needed to match your setup.Troubleshooting Steps
If you encounter issues:
This detailed guide for creating metric filters and alarms for monitoring security group changes should help maintain the security and integrity of your AWS environment, in accordance with CIS v1.4.0 benchmarks.