Description
Use CloudTrail events and a CloudWatch alarm to tell the responsible team about AWS Organizations changes such as account moves or policy attachments.
Potential impact
A missed change can leave an account in the wrong organizational unit or subject to an unintended policy.
Remediation
Allow CloudTrail to deliver the events to the log group. Configure the alarm with the filter’s metric name and namespace, threshold and evaluation period. Subscribe recipients to the SNS topic. Verify that a matching event updates the metric and that recipients receive an SNS notification when the alarm enters the ALARM state. Allow time for delivery and evaluation.
Examples
Define the referenced log group and SNS topic separately. The first filter counts EC2 events. The second counts five Organizations actions. Add any other actions your team needs to monitor.
Before
resource "aws_cloudwatch_log_metric_filter" "organizations_changes" {
name = "organizations-changes"
log_group_name = aws_cloudwatch_log_group.cloudtrail.name
pattern = "{ ($.eventSource = \"ec2.amazonaws.com\") }"
metric_transformation {
name = "organizations-changes"
namespace = "Security"
value = "1"
}
}
After
resource "aws_cloudwatch_log_metric_filter" "organizations_changes" {
name = "organizations-changes"
log_group_name = aws_cloudwatch_log_group.cloudtrail.name
pattern = "{ ($.eventSource = \"organizations.amazonaws.com\") && (($.eventName = AcceptHandshake) || ($.eventName = AttachPolicy) || ($.eventName = CreateAccount) || ($.eventName = MoveAccount) || ($.eventName = RemoveAccountFromOrganization)) }"
metric_transformation {
name = "organizations-changes"
namespace = "Security"
value = "1"
}
}
resource "aws_cloudwatch_metric_alarm" "organizations_changes" {
alarm_name = "organizations-changes"
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 1
metric_name = "organizations-changes"
namespace = "Security"
period = 300
statistic = "Sum"
threshold = 1
alarm_actions = [aws_sns_topic.security_alerts.arn]
}
The example notifies SNS when the five-minute sum reaches at least one and the alarm changes to ALARM.