Skip to main content

Triage and Remediation

Remediation

Using Console

  1. Configure CloudTrail to Deliver Logs to CloudWatch Logs:
    • Go to the AWS Management Console.
    • Open the CloudTrail service.
    • Select your trail.
    • Click on “Edit”.
    • In the “CloudWatch Logs” section, select an existing log group or create a new one.
    • Click “Save changes”.
  2. Create Metric Filter and Alarm:
    • Go to the CloudWatch service in the AWS Management Console.
    • In the left-hand navigation pane, choose “Logs” and then select the log group you configured in CloudTrail.
    • Click on “Create metric filter”.
    • Define a filter pattern that matches IAM policy changes. For example, you might use a pattern like { $.eventSource = "iam.amazonaws.com" && $.eventName = "AttachRolePolicy" }.
    • Click “Assign metric”.
    • Give your metric a name like IAMPolicyChangesEventCount or IAMPolicyEventCount.
    • Click “Create filter”.
    • Once your filter is created, you can set up an alarm based on this metric.

  1. Create Metric Filter:
    or
    Replace "YOUR_LOG_GROUP_NAME" with the name of your CloudTrail log group.
  2. Create CloudWatch Alarm (optional): Use the put-metric-alarm command to create an alarm based on the metric you created.
Set an alarm for “IAMPolicyChangesEventCount” Metric
Or set an alarm for “IAMPolicyEventCount” Metric
Replace "YOUR_LOG_GROUP_NAME" with the name of your CloudTrail log group.These steps should help you set up the IAMPolicyChangesEventCount or IAMPolicyEventCount metric in CloudWatch using the AWS Console, AWS CLI, or Python script. Remember to adjust the configuration according to your specific use case and environment.
Substitute:
  • CLOUDTRAIL_LOG_GROUP_NAME with your CloudTrail log group name (from CloudWatchLogsLogGroupArn).
  • IAM_POLICY_CHANGES_ALERT_EMAIL@example.com with the destination email; the recipient must confirm the SNS subscription from the email they receive.
This creates new monitoring resources (SNS topic, subscription, metric filter, and alarm) and does not force replacement of existing ones.To verify, terraform plan should show these resources with + create and no ~ update or - destroy for existing CloudWatch alarms.