Project: KICS (Provisioning / Security & Compliance)
File: 8b1b1e67-6248-4dca-bbad-93486bb181c0.md

title: CloudWatch Root Account Use Missing hide: toc: true navigation: true <style> .highlight .hll { background-color: #ff171742; } .md-content { max-width: 1100px; margin: 0 auto; } </style> Query id: 8b1b1e67-6248-4dca-bbad-93486bb181c0 Query name: CloudWatch Root Account Use Missing Platform: Terraform Severity: <span style="color:#ff7213">Medium</span> Category: Observability URL: Ensure a log metric filter and alarm exist for root acount usage<br> ```tf title="Positive test num. 1 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "cisrootaccountusemetric_filter" { name = "CIS-RootAccountUsage" pattern = "{ $.userIdentity.type = \"Root\" && $.userIdentity.invokedBy NOT EXISTS && $.eventType != \"AwsServiceEvent\" }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-RootAccountUsage" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisrootaccountusecwalarm" { alarm_name = "CIS-3.3-RootAccountUsage" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metric_name = "XXX NOT YOUR FILTER XXX" namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for root account logins will provide visibility into the use of a fully privileged account and an opportunity to reduce the use of it." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } resource "awscloudwatchlogmetricfilter" "cisnomfaconsolesigninmetricfilter" { name = "CIS-ConsoleSigninWithoutMFA" pattern = "{ ($.eventName = \"ConsoleLogin\") && ($.additionalEventData.MFAUsed != \"Yes\") }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-ConsoleSigninWithoutMFA" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisnomfaconsolesignincw_alarm" { alarm_name = "CIS-3.2-ConsoleSigninWithoutMFA" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisnomfaconsolesigninmetric_filter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for single-factor console logins will increase visibility into accounts that are not protected by MFA." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ``` ```tf title="Positive test num. 2 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "cisrootaccountusemetric_filter" { name = "CIS-RootAccountUsage" pattern = "{ $.userIdentity.type = \"Root\" && $.eventType != \"AwsServiceEvent\" }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-RootAccountUsage" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisrootaccountusecwalarm" { alarm_name = "CIS-3.3-RootAccountUsage" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisrootaccountusemetricfilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for root account logins will provide visibility into the use of a fully privileged account and an opportunity to reduce the use of it." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ``` ```tf title="Positive test

3 - tf file" hl_lines="1" resource "awscloudwatchlogmetricfilter" "cisrootaccountusemetric_filter" { name = "CIS-RootAccountUsage" pattern = "{ $.userIdentity.invokedBy NOT EXISTS && $.eventType != \"AwsServiceEvent\" }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-RootAccountUsage" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisrootaccountusecwalarm" { alarm_name = "CIS-3.3-RootAccountUsage" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisrootaccountusemetricfilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for root account logins will provide visibility into the use of a fully privileged account and an opportunity to reduce the use of it." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } ``` <details><summary>Positive test num. 4 - tf file</summary> ```tf hl_lines="1" resource "awscloudwatchmetricalarm" "cisunauthorizedapicallscwalarm" { alarm_name = "CIS-3.1-UnauthorizedAPICalls" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisunauthorizedapicallsmetricfilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring unauthorized API calls will help reveal application errors and may reduce time to detect malicious activity." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } resource "awscloudwatchlogmetricfilter" "cisunauthorizedapicallsmetric_filter" { name = "CIS-UnauthorizedAPICalls" pattern = "{ $.userIdentity.type = \"Root\" || $.eventType != \"AwsServiceEvent\" }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-UnauthorizedAPICalls" namespace = "CISMetricAlarm_Namespace" value = "1" } } ``` </details> ```tf title="Negative test num. 1 - tf file" resource "awscloudwatchlogmetricfilter" "cisrootaccountusemetric_filter" { name = "CIS-RootAccountUsage" pattern = "{ $.userIdentity.type = \"Root\" && $.userIdentity.invokedBy NOT EXISTS && $.eventType != \"AwsServiceEvent\" }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-RootAccountUsage" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "CISRootAccountUseCWAlarm" { alarm_name = "CIS-3.3-RootAccountUsage" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisrootaccountusemetricfilter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for root account logins will provide visibility into the use of a fully privileged account and an opportunity to reduce the use of it." alarmactions = [awssnstopic.CISAlertsSNSTopic.arn] insufficientdataactions = [] } resource "awscloudwatchlogmetricfilter" "cisnomfaconsolesigninmetricfilter" { name = "CIS-ConsoleSigninWithoutMFA" pattern = "{ ($.eventName = \"ConsoleLogin\") && ($.additionalEventData.MFAUsed != \"Yes\") }" loggroupname = awscloudwatchloggroup.CISCloudWatch_LogsGroup.name metric_transformation { name = "CIS-ConsoleSigninWithoutMFA" namespace = "CISMetricAlarm_Namespace" value = "1" } } resource "awscloudwatchmetricalarm" "cisnomfaconsolesignincw_alarm" { alarm_name = "CIS-3.2-ConsoleSigninWithoutMFA" comparison_operator = "GreaterThanOrEqualToThreshold" evaluation_periods = "1" metricname = awscloudwatchlogmetricfilter.cisnomfaconsolesigninmetric_filter.id namespace = "CISMetricAlarm_Namespace" period = "300" statistic = "Sum" threshold = "1" alarm_description = "Monitoring for single-factor console logins will increase visibility into accounts that are not protected by MFA." alarmactions = ["awssnstopic.CISAlertsSNSTopic.arn"] insufficientdataactions = [] } ```