Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are the steps to enable a CloudTrail changes alarm in CloudWatch using the AWS Console.
Once done, any time someone changes CloudTrail configuration (creates/updates/deletes trail, starts/stops logging, or changes selectors), CloudWatch will detect it via the metric filter and trigger the alarm, which will send a notification.
1. Confirm CloudTrail is sending logs to CloudWatch Logs
- Go to AWS Console → CloudTrail.
- In the left menu, choose Trails.
- Select your trail.
- Under CloudWatch Logs, confirm:
- CloudWatch Logs log group is set (for example:
/aws/cloudtrail/main). - If not set:
- Click Edit.
- In CloudWatch Logs, choose or create a Log group.
- Choose or create an IAM role (CloudTrail will suggest one).
- Save the changes.
- CloudWatch Logs log group is set (for example:
2. Create a Metric Filter for CloudTrail configuration changes
- Go to CloudWatch → Logs → Log groups.
-
Click the log group used by CloudTrail (e.g.
/aws/cloudtrail/main). - Go to the Metric filters tab.
- Click Create metric filter.
-
In Filter pattern, paste:
- Click Next.
-
Under Assign metric, fill in:
- Filter name:
CloudTrailConfigChanges - Metric namespace: e.g.
Security/CloudTrail - Metric name: e.g.
CloudTrailChangesCount - Metric value:
1 - Leave default for other options (or as required by your org).
- Filter name:
- Click Next, then Create metric filter.
3. Create a CloudWatch Alarm on that metric
- Still in CloudWatch, go to Alarms → All alarms.
- Click Create alarm.
- Click Select metric.
- Navigate to the namespace you used:
- Custom namespaces → Security/CloudTrail → Metrics with no dimensions (or matching your setup).
- Select CloudTrailChangesCount.
- Click Next.
Configure alarm conditions
- Under Statistic, select Sum.
- Under Period, choose a period (e.g. 5 minutes).
- Under Conditions:
- Threshold type:
Static - Whenever metric is:
>= - Threshold value:
1
- Threshold type:
- Click Next.
Configure notifications
- Under Notification, choose an existing SNS topic or:
- Click Create a new topic.
- Give it a name (e.g.
cloudtrail-config-change-alerts). - Add email endpoints (e.g. your security team email).
- Confirm the subscription via the email sent from AWS.
- Choose Alarm state trigger:
In alarm. - Click Next.
Name and create alarm
- Alarm name:
CloudTrail-Config-Changes-Alarm - Add a description (optional, e.g. “Alerts on create/update/delete or logging changes to CloudTrail”).
- Review all settings and click Create alarm.
Once done, any time someone changes CloudTrail configuration (creates/updates/deletes trail, starts/stops logging, or changes selectors), CloudWatch will detect it via the metric filter and trigger the alarm, which will send a notification.
Using CLI
Using CLI
Below is a minimal, CLI‑only way to set up an alarm that triggers when CloudTrail configuration is changed (CreateTrail/UpdateTrail/DeleteTrail/StartLogging/StopLogging).Assumptions:
This creates a metric
Explanation of key choices (brief):
- You already have a CloudTrail trail sending logs to a CloudWatch Logs log group.
- You know the log group name (replace
YOUR_LOG_GROUP_NAMEbelow). - You know the SNS topic ARN you want to notify (replace
YOUR_SNS_TOPIC_ARN).
1. Create a CloudWatch Logs metric filter for CloudTrail changes
CloudTrailChanges in namespace CloudTrailMetrics whenever such an event appears in the log stream.2. Create a CloudWatch alarm on that metric
period 300= 5 minutes.- Alarm fires if at least 1 such event is detected in 1 evaluation period (
threshold 1,evaluation-periods 1).
3. (Optional) Test the alarm
Trigger a CloudTrail change (e.g., update a trail description) and confirm:- The
CloudTrailChangesmetric increments. - The
CloudTrail_Changes_Alarmgoes into ALARM state. - SNS notifications are delivered.
Using Python
Using Python
Below are step‑by‑step remediation instructions and a minimal Python (boto3) example that:
- Creates a CloudWatch Logs metric filter to detect CloudTrail configuration changes.
- Creates a CloudWatch alarm on that metric.
- You already have at least one CloudTrail writing to a CloudWatch Logs log group.
- You know the log group name where CloudTrail is sending logs (e.g.,
/aws/cloudtrail/organization). - You have permissions for
logs:*,cloudwatch:*, andsns:*(if using SNS notifications).
1. What you need to detect
CloudTrail changes usually include events such as:CreateTrailUpdateTrailDeleteTrailStartLoggingStopLogging
2. High-level remediation steps
- Identify the CloudWatch Logs log group that CloudTrail is using.
- Create a metric filter in that log group for CloudTrail configuration change events.
- Create or use a CloudWatch metric namespace and metric name (e.g.,
CloudTrailMetrics,CloudTrailConfigChanges). - Create a CloudWatch alarm that:
- Monitors the metric from step 3.
- Triggers when the metric is ≥ 1 within a 5-minute period (or your chosen interval).
- (Optional) Attach an SNS topic to the alarm for notifications.
3. Python (boto3) example
Replace the following placeholders before running:REGION→ e.g."us-east-1"LOG_GROUP_NAME→ CloudTrail log group (e.g."/aws/cloudtrail/organization")METRIC_NAMESPACE→ e.g."CloudTrailMonitoring"METRIC_NAME→ e.g."CloudTrailConfigChanges"ALARM_NAME→ e.g."CloudTrailChangesAlarm"SNS_TOPIC_ARN→ Your SNS topic ARN for notifications (or remove if not needed).
4. Post‑setup verification
- Confirm the metric filter exists:
- CloudWatch Console → Logs → Log groups → your log group → Metric filters.
- Confirm the alarm:
- CloudWatch Console → Alarms → look for
CloudTrailChangesAlarm.
- CloudWatch Console → Alarms → look for
- Trigger a test (e.g., update a trail in a non‑prod account) and verify:
- The metric increments.
- The alarm goes into
ALARMstate and sends SNS notification (if configured).
Using Terraform
Using Terraform
CLOUDTRAIL_LOG_GROUP_NAME, REGION, ACCOUNT_ID, and TOPIC_NAME with your actual values, terraform plan should show one aws_cloudwatch_log_metric_filter to add and one aws_cloudwatch_metric_alarm to add (or to update if they already exist but differ).
