Ensure a log metric filter and alarm exist for STS 'AssumeRole' action

Risk Level: Medium
Rule ID: D9.AWS.MON.22
Category: Management Tools
Real-time monitoring of API calls can be achieved by directing CloudTrail Logs to CloudWatch Logs and establishing corresponding metric filters and alarms. It is recommended that a metric filter and alarm be established for changes done by the Security Token Service 'AssumeRole' action. Monitoring changes done by the Security Token Service 'AssumeRole' action, will help ensure authentication and authorization controls remain intact.

gsl logic

List<CloudTrail> should have items with [hasSNSSubscriber='true' and metricFilters with [filterPattern isFilterPatternEqual('{($.eventName=AssumeRole)}')] length() > 0]

Dome9 rules are powered by the Governance Specification Language (GSL). GSL allows our customers to write and run custom security and compliance checks that can be easily read

Learn more:
Compliance Engine
GSL Language


Note: This remediation process assumes SNS topic and log group are already configured.

From Portal:
1. Go to 'CloudWatch'
2. In the menu, under 'Logs', choose 'Log groups' and choose the relevant log group
3. Press 'Create new metric filter' and add the following 'Filter pattern': '{($.eventName=AssumeRole)}'
4. Review and create the new metric filter
5. In the menu, under 'Alarms', choose 'All alarms' and choose the relevant log group
6. Press 'Create alarm' and choose the relevant metric and press 'Next'
7. Under 'Metric', make sure 'Statistic' is set to 'Sum'
8. Under 'Conditions', make sure the threshold type is set to 'Static', an alarm condition is set to 'Greater/Equal' and the threshold value is set to '1'
9. Configure your SNS topic under 'Notification'
10. Create the alarm

From TF:
Create a new CloudWatch metric filter:

resource "aws_cloudwatch_log_metric_filter" "metric_filter_example" {
 name = "FILTER-NAME"
 pattern = "{($.eventName=AssumeRole)}"
 log_group_name = "LOG-GROUP-NAME"

 metric_transformation {
  name = "METRIC-NAME"
  namespace = "NAMESPACE-NAME"
  value = "1"

Create a new CloudWatch metric alarm:

resource "aws_cloudwatch_metric_alarm" "metric_alarm_example" {
 alarm_name = "ALARM-NAME"
 comparison_operator = "GreaterThanOrEqualToThreshold"
 evaluation_periods = "1"
 metric_name = "METRIC-NAME"
 namespace = "NAMESPACE-NAME"
 period = "PERIOD"
 statistic = "Sum"
 threshold = "1"
 alarm_actions = ["SNS-TOPIC-ARN"]

From Command Line:
Create a new CloudWatch metric filter:

aws logs put-metric-filter --region REGION --log-group-name LOG-GROUP-NAME --filter-name FILTER-NAME --filter-pattern '{($.eventName=AssumeRole)}' --metric-transformations metricName=METRIC-NAME,metricNamespace=METRIC-NAMESPACE,metricValue=1

Create a new CloudWatch metric alarm:

aws cloudwatch put-metric-alarm --region REGION --alarm-name ALARM-NAME --metric-name METRIC-NAME --statistic Sum --period PERIOD --threshold 1 --comparison-operator GreaterThanOrEqualToThreshold --evaluation-periods 1 --namespace NAMESPACE --alarm-actions SNS-TOPIC-ARN

1. https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CreateMetricFilterProcedure.html
2. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ConsoleAlarms.html
3. https://awscli.amazonaws.com/v2/documentation/api/latest/reference/logs/put-metric-filter.html
4. https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudwatch/put-metric-alarm.html
5. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_metric_filter
6. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_metric_alarm
7. https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html

Related Links:
What Is AWS CloudTrail?


AWS CloudTrail is a service that enables governance, compliance, operational auditing, and risk auditing of your AWS account. With CloudTrail, you can log, continuously monitor, and retain account activity related to actions across your AWS infrastructure. CloudTrail provides event history of your AWS account activity, including actions taken through the AWS Management Console, AWS SDKs, command line tools, and other AWS services. This event history simplifies security analysis, resource change tracking, and troubleshooting.

Compliance Frameworks