Skip to main content

Triage and Remediation

Remediation

Using Console

Below are the console steps to enable an “Authorization Failures” alarm in CloudWatch based on CloudTrail logs.

Prerequisites

  • You already have an AWS CloudTrail trail sending events to a CloudWatch Logs log group.

1. Confirm / Set CloudTrail Log Group

  1. In the AWS Console, go to CloudTrail.
  2. In the left menu, choose Trails.
  3. Click your active trail.
  4. 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.

2. Create a Metric Filter for Authorization Failures

  1. Go to CloudWatch in the console.
  2. In the left menu, select Logs → Log groups.
  3. Click the CloudTrail log group (e.g., /aws/cloudtrail/your-trail).
  4. Go to the Metric filters tab and click Create metric filter.
  5. In Filter pattern, use a pattern that matches authorization errors, for example:
  6. Click Next.
  7. 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
  8. Click Next, then Create metric filter.

3. Create a CloudWatch Alarm on the Metric

  1. Still in CloudWatch, go to Alarms → All alarms.
  2. Click Create alarm.
  3. Click Select metric.
  4. Navigate to Custom namespaces → your namespace (e.g., CIS/CloudTrail) → select the AuthorizationFailures metric.
  5. Click Select metric.
  6. Set Statistic to Sum and choose a Period (e.g., 5 minutes).
  7. Define the condition:
    • Threshold type: Static
    • Whenever Sum is: Greater than
    • Threshold: 0
  8. Click Next.

4. Configure Notification (SNS)

  1. 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.
    • After creation, confirm subscription from the email(s) you receive.
  2. Click Next.

5. Name and Create the Alarm

  1. Give the alarm a name and description, for example:
    • Name: AuthorizationFailuresAlarm
    • Description: Alarm when CloudTrail records authorization failures (AccessDenied / UnauthorizedOperation).
  2. Review all settings.
  3. 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.
Below are concise, step‑by‑step AWS CLI instructions to set up a CloudWatch alarm for authorization failures (e.g., 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:
Pick the CloudTrail log group name, for example: /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:
Verify:

3. Create/choose an SNS topic for the alarm notification

Create topic:
Subscribe your email (or another endpoint):
Confirm the subscription from your email inbox.

4. Create the CloudWatch alarm on the metric

Example: alarm if ≥ 1 authorization failure in 5 minutes.
Check the alarm:

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 ALARM state and send an SNS notification.
This completes enabling an “Authorization Failures” alarm using AWS CLI.
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:
  • 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:*, and cloudtrail:*.

1. Decide what to alarm on

Common pattern: alarm on CloudTrail events where API calls fail with:
  • errorCode = "AccessDenied*"
  • OR errorCode = "UnauthorizedOperation"
We’ll:
  1. Create a CloudWatch Logs Metric Filter on the CloudTrail log group.
  2. Create a CloudWatch Alarm on that metric.
  3. (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.
Notes:
  • Adjust LOG_GROUP_NAME to your actual CloudTrail CloudWatch Logs group.
  • Adjust region_name as needed.


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.
Adjust:
  • SNS_TOPIC_ARN to the ARN from step 3 or omit AlarmActions if you don’t want notifications.
  • THRESHOLD, PERIOD, EVALUATION_PERIODS based on your sensitivity to alerts.

5. Verify the Alarm

  1. 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 AuthorizationFailuresAlarm is OK and configured with the correct metric and SNS action.
  2. Generate a test authorization failure (e.g., call an API without required permissions) and confirm:
    • Metric increments.
    • Alarm moves to ALARM state 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.
Running 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.