Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are the console steps to enable an “Authorization Failures” alarm in CloudWatch based on CloudTrail logs.
Once done, any CloudTrail event that matches the filter (authorization failures) will increment the metric, and if it exceeds the threshold (>0 in the period), the CloudWatch alarm will enter
Prerequisites
- You already have an AWS CloudTrail trail sending events to a CloudWatch Logs log group.
1. Confirm / Set CloudTrail Log Group
- In the AWS Console, go to CloudTrail.
- In the left menu, choose Trails.
- Click your active trail.
- Under CloudWatch Logs, confirm:
- CloudWatch Logs log group is set (for example:
/aws/cloudtrail/your-trail). - If not configured:
- Click Edit (or Configure).
- Enable Send to CloudWatch Logs.
- Select / create a Log group.
- Select / create an IAM role if prompted.
- Save changes and wait a few minutes for logs to start streaming.
- CloudWatch Logs log group is set (for example:
2. Create a Metric Filter for Authorization Failures
- Go to CloudWatch in the console.
- In the left menu, select Logs → Log groups.
-
Click the CloudTrail log group (e.g.,
/aws/cloudtrail/your-trail). - Go to the Metric filters tab and click Create metric filter.
-
In Filter pattern, use a pattern that matches authorization errors, for example:
- Click Next.
-
For Assign metric, fill in:
- Filter name:
AuthorizationFailuresFilter - Metric namespace:
CIS/CloudTrail(or any custom namespace) - Metric name:
AuthorizationFailures - Metric value:
1 - Default value (optional):
0
- Filter name:
- Click Next, then Create metric filter.
3. Create a CloudWatch Alarm on the Metric
- Still in CloudWatch, go to Alarms → All alarms.
- Click Create alarm.
- Click Select metric.
- Navigate to Custom namespaces → your namespace (e.g.,
CIS/CloudTrail) → select theAuthorizationFailuresmetric. - Click Select metric.
- Set Statistic to
Sumand choose a Period (e.g.,5 minutes). - Define the condition:
- Threshold type: Static
- Whenever Sum is:
Greater than - Threshold:
0
- Click Next.
4. Configure Notification (SNS)
- In the Notification section:
- Under Alarm state trigger, select In alarm.
- Choose an existing SNS topic or click Create new topic.
- If creating a new topic:
- Provide a name (e.g.,
AuthorizationFailuresTopic). - Enter one or more email addresses.
- Provide a name (e.g.,
- After creation, confirm subscription from the email(s) you receive.
- Click Next.
5. Name and Create the Alarm
- Give the alarm a name and description, for example:
- Name:
AuthorizationFailuresAlarm - Description:
Alarm when CloudTrail records authorization failures (AccessDenied / UnauthorizedOperation).
- Name:
- Review all settings.
- Click Create alarm.
Once done, any CloudTrail event that matches the filter (authorization failures) will increment the metric, and if it exceeds the threshold (>0 in the period), the CloudWatch alarm will enter
ALARM state and trigger your SNS notification.Using CLI
Using CLI
Below are concise, step‑by‑step AWS CLI instructions to set up a CloudWatch alarm for authorization failures (e.g.,
Pick the CloudTrail log group name, for example:
Verify:
Subscribe your email (or another endpoint):Confirm the subscription from your email inbox.
Check the alarm:
AuthorizationFailure, AccessDenied) from CloudTrail logs.Assumptions:- You already have CloudTrail sending logs to a CloudWatch Logs log group.
- Replace all ALL_CAPS placeholders with your values.
1. Identify your CloudTrail log group
If you don’t know it:/aws/cloudtrail/your-account-trailsSet it in a variable (optional but convenient):2. Create a metric filter for authorization failures
Filter pattern to catch common authorization failures:3. Create/choose an SNS topic for the alarm notification
Create topic:4. Create the CloudWatch alarm on the metric
Example: alarm if ≥ 1 authorization failure in 5 minutes.5. Test the alarm (optional)
- Intentionally perform an AWS action your IAM user/role is not allowed to do (in a safe, non‑prod way).
- Wait a few minutes; the alarm should go into
ALARMstate and send an SNS notification.
Using Python
Using Python
Below are step‑by‑step remediation instructions and example Python (boto3) code to ensure an “Authorization Failures” alarm is enabled in AWS using CloudWatch.Assumptions:
Notes:
Adjust:
If you tell me:
- You have:
- A CloudTrail trail logging to a CloudWatch Logs log group (e.g.
/aws/cloudtrail/logs) - An IAM principal with permissions for
logs:*,cloudwatch:*,iam:*, andcloudtrail:*.
- A CloudTrail trail logging to a CloudWatch Logs log group (e.g.
1. Decide what to alarm on
Common pattern: alarm on CloudTrail events where API calls fail with:errorCode = "AccessDenied*"- OR
errorCode = "UnauthorizedOperation"
- Create a CloudWatch Logs Metric Filter on the CloudTrail log group.
- Create a CloudWatch Alarm on that metric.
- (Optional) Wire it into an SNS topic for notifications.
2. Create the CloudWatch Logs Metric Filter (Python)
This metric filter will increment a metric every time an “authorization failure” is seen.- Adjust
LOG_GROUP_NAMEto your actual CloudTrail CloudWatch Logs group. - Adjust
region_nameas needed.
3. Create an SNS Topic for Alarm Notifications (optional but recommended)
4. Create the CloudWatch Alarm on This Metric (Python)
This alarm triggers when more than a certain number of authorization failures occur in a given time window.SNS_TOPIC_ARNto the ARN from step 3 or omitAlarmActionsif you don’t want notifications.THRESHOLD,PERIOD,EVALUATION_PERIODSbased on your sensitivity to alerts.
5. Verify the Alarm
-
In the AWS Console:
- Go to CloudWatch → Logs → Log groups: confirm the metric filter exists.
- Go to CloudWatch → Metrics → Security/Authorization: confirm the metric is visible after some denied API calls.
- Go to CloudWatch → Alarms: verify
AuthorizationFailuresAlarmisOKand configured with the correct metric and SNS action.
-
Generate a test authorization failure (e.g., call an API without required permissions) and confirm:
- Metric increments.
- Alarm moves to
ALARMstate when threshold is crossed. - Notification is sent (if SNS configured).
If you tell me:
- Your region
- Your CloudTrail log group name I can adapt the code snippets exactly to your environment.
Using Terraform
Using Terraform
terraform plan should show creation of aws_cloudwatch_log_metric_filter.authorization_failures and aws_cloudwatch_metric_alarm.authorization_failures (and the log group if it is not already managed in Terraform), with the metric name, namespace, pattern, threshold, period, and alarm name matching the CLI remediation.
