Ensure IAM policy changes are monitored

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 changes made to Identity and Access Management (IAM) policies. Monitoring changes to IAM policies will help ensure authentication and authorization controls remain intact.

Risk Level: Low
Cloud Entity: CloudTrail
CloudGuard Rule ID: D9.AWS.MON.04
Covered by Spectral: Yes
Category: Management Tools

GSL LOGIC

List<CloudTrail> should have items with [hasSNSSubscriber='true' and metricFilters with [filterPattern isFilterPatternEqual('{($.eventName=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)||($.eventName=SetDefaultPolicyVersion)||($.eventName=AddUserToGroup)||($.eventName=UpdateAssumeRolePolicy)}')] 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=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)||($.eventName=SetDefaultPolicyVersion)||($.eventName=AddUserToGroup)||($.eventName=UpdateAssumeRolePolicy)}'
  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=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)||($.eventName=SetDefaultPolicyVersion)||($.eventName=AddUserToGroup)||($.eventName=UpdateAssumeRolePolicy)}"
	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=DeleteGroupPolicy)||($.eventName=DeleteRolePolicy)||($.eventName=DeleteUserPolicy)||($.eventName=PutGroupPolicy)||($.eventName=PutRolePolicy)||($.eventName=PutUserPolicy)||($.eventName=CreatePolicy)||($.eventName=DeletePolicy)||($.eventName=CreatePolicyVersion)||($.eventName=DeletePolicyVersion)||($.eventName=AttachRolePolicy)||($.eventName=DetachRolePolicy)||($.eventName=AttachUserPolicy)||($.eventName=DetachUserPolicy)||($.eventName=AttachGroupPolicy)||($.eventName=DetachGroupPolicy)||($.eventName=SetDefaultPolicyVersion)||($.eventName=AddUserToGroup)||($.eventName=UpdateAssumeRolePolicy)}' --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/IAM/latest/APIReference/API_Operations.html
  8. CIS AWS Foundations Benchmark: https://workbench.cisecurity.org/benchmarks/679

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 CIS Foundations v. 1.0.0
  • AWS CIS Foundations v. 1.1.0
  • AWS CIS Foundations v. 1.2.0
  • AWS CIS Foundations v. 1.3.0
  • AWS CIS Foundations v. 1.4.0
  • AWS CIS Foundations v. 1.5.0
  • AWS CIS Foundations v. 2.0.0
  • AWS CSA CCM v.3.0.1
  • AWS CSA CCM v.4.0.1
  • AWS CloudGuard Best Practices
  • AWS CloudGuard SOC2 based on AICPA TSC 2017
  • AWS CloudGuard Well Architected Framework
  • AWS GDPR Readiness
  • AWS HIPAA
  • AWS HITRUST
  • AWS HITRUST v11.0.0
  • AWS ISO 27001:2013
  • AWS ISO27001:2022
  • AWS ITSG-33
  • AWS LGPD regulation
  • AWS MAS TRM Framework
  • AWS MITRE ATT&CK Framework v10
  • AWS MITRE ATT&CK Framework v11.3
  • AWS NIST 800-171
  • AWS NIST 800-53 Rev 4
  • AWS NIST 800-53 Rev 5
  • AWS NIST CSF v1.1
  • AWS PCI-DSS 3.2
  • AWS PCI-DSS 4.0
  • CloudGuard AWS All Rules Ruleset