Ensure a log metric filter and alarm exist for SSM actions

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 actions done by the Systems Manager Agent (SSM). Monitoring actions done by the Systems Manager Agent (SSM), will help ensure authentication and authorization controls remain intact.

Risk Level: High
Cloud Entity: CloudTrail
CloudGuard Rule ID: D9.AWS.MON.23
Covered by Spectral: No
Category: Management Tools

GSL LOGIC

List<CloudTrail> should have items with [hasSNSSubscriber='true' and metricFilters with [filterPattern isFilterPatternEqual('{($.eventName=ListCommands)||($.eventName=ListCommandInvocations)||($.eventName=SendCommand)||($.eventName=StartSession)||($.eventName=DescribeSessions)||($.eventName=GetConnectionStatus)||($.eventName=DescribeInstanceProperties)||($.eventName=DescribeInstanceInformation)||($.eventName=TerminateSession)||($.eventName=ResumeSession)}')] length() > 0]

REMEDIATION

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=ListCommands)||($.eventName=ListCommandInvocations)||($.eventName=SendCommand)||($.eventName=StartSession)||($.eventName=DescribeSessions)||($.eventName=GetConnectionStatus)||($.eventName=DescribeInstanceProperties)||($.eventName=DescribeInstanceInformation)||($.eventName=TerminateSession)||($.eventName=ResumeSession)}'
  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=ListCommands)||($.eventName=ListCommandInvocations)||($.eventName=SendCommand)||($.eventName=StartSession)||($.eventName=DescribeSessions)||($.eventName=GetConnectionStatus)||($.eventName=DescribeInstanceProperties)||($.eventName=DescribeInstanceInformation)||($.eventName=TerminateSession)||($.eventName=ResumeSession)}"
	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=ListCommands)||($.eventName=ListCommandInvocations)||($.eventName=SendCommand)||($.eventName=StartSession)||($.eventName=DescribeSessions)||($.eventName=GetConnectionStatus)||($.eventName=DescribeInstanceProperties)||($.eventName=DescribeInstanceInformation)||($.eventName=TerminateSession)||($.eventName=ResumeSession)}' --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

References

  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/systems-manager/latest/APIReference/API_Operations.html

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

  • AWS CloudGuard Best Practices
  • AWS CloudGuard SOC2 based on AICPA TSC 2017
  • AWS HITRUST v11.0.0
  • AWS ISO27001:2022
  • AWS MITRE ATT&CK Framework v10
  • AWS MITRE ATT&CK Framework v11.3
  • AWS NIST 800-53 Rev 5
  • CloudGuard AWS All Rules Ruleset