From 559b0585dc663dc3a9a6a673ffca401966ac3f2c Mon Sep 17 00:00:00 2001 From: Nimrod Kor Date: Thu, 12 Dec 2019 09:42:42 +0200 Subject: [PATCH] Add trail count to check21 and fail if no trail exist (cherry picked from commit fcf28dfa70fb93df9f61393b8dff2cc5fc14729e) --- checks/check21 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/checks/check21 b/checks/check21 index 64b82ebcce..383578e3d2 100644 --- a/checks/check21 +++ b/checks/check21 @@ -15,19 +15,25 @@ CHECK_TYPE_check21="LEVEL1" CHECK_ALTERNATE_check201="check21" check21(){ + trail_count=0 # "Ensure CloudTrail is enabled in all regions (Scored)" for regx in $REGIONS; do LIST_OF_TRAILS=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region $regx --query 'trailList[*].Name' --output text --no-include-shadow-trails) if [[ $LIST_OF_TRAILS ]];then for trail in $LIST_OF_TRAILS;do - MULTIREGION_TRAIL_STATUS=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region $regx --query 'trailList[*].IsMultiRegionTrail' --output text --trail-name-list $trail) - if [[ "$MULTIREGION_TRAIL_STATUS" == 'False' ]];then - textFail "$trail trail in $regx is not enabled in multi region mode" - else - textPass "$trail trail in $regx is enabled for all regions" - fi + trail_count=$((trail_count + 1)) + MULTIREGION_TRAIL_STATUS=$($AWSCLI cloudtrail describe-trails $PROFILE_OPT --region $regx --query 'trailList[*].IsMultiRegionTrail' --output text --trail-name-list $trail) + if [[ "$MULTIREGION_TRAIL_STATUS" == 'False' ]];then + textFail "$trail trail in $regx is not enabled in multi region mode" + else + textPass "$trail trail in $regx is enabled for all regions" + fi done fi done + + if [[ $trail_count == 0 ]]; then + textFail "No CloudTrail trails were found in the account" + fi }