Missing alarm for IAM policy changes

Without a CloudWatch log filter and alarm for IAM policy changes, permission changes can be discovered late.

Description

Monitor changes to inline and managed IAM policies, including policy versions, attachments, and detachments.

Potential impact

An unexpected policy change can grant more access than a user, group, or role needs.

Remediation

  1. Deliver CloudTrail events to CloudWatch Logs and filter for the policy changes your team needs to review.
  2. Set the alarm’s metric name and namespace to the filter’s output. Choose the statistic, period, evaluation periods, and threshold.
  3. Add an SNS notification action. Verify that new matching policy-change events make the alarm enter ALARM and that a subscriber receives its notification.

Examples

The filter name equals the metric name here, so the alarm uses the filter’s id.

Before

hcl
resource "aws_cloudwatch_metric_alarm" "example" {
  alarm_name          = "CIS-4.4-IAM-Policy-Change"
  metric_name         = "XXXX NOT YOUR FILTER XXXX"
  namespace           = "CIS_Metric_Alarm_Namespace"
  comparison_operator = "GreaterThanOrEqualToThreshold"
}

After

hcl
resource "aws_cloudwatch_log_metric_filter" "example" {
  name           = "CIS-4.4-IAM-Policy-Change"
  pattern        = "{($.eventName=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)}"
  log_group_name = aws_cloudwatch_log_group.CIS_CloudWatch_LogsGroup.name

  metric_transformation {
    name      = "CIS-4.4-IAM-Policy-Change"
    namespace = "CIS_Metric_Alarm_Namespace"
    value     = "1"
  }
}

resource "aws_cloudwatch_metric_alarm" "example" {
  alarm_name          = "CIS-4.4-IAM-Policy-Change"
  metric_name         = aws_cloudwatch_log_metric_filter.example.id
  namespace           = "CIS_Metric_Alarm_Namespace"
  comparison_operator = "GreaterThanOrEqualToThreshold"
}

References