From e1e57db93e0980cb5d8d45f74486d6ed10b0b2af Mon Sep 17 00:00:00 2001 From: Joel Maisenhelder Date: Wed, 1 Dec 2021 19:44:34 -0600 Subject: [PATCH] New check 7164 Check if Cloudwatch log groups are protected by AWS KMS@maisenhe --- checks/check_extra7164 | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 checks/check_extra7164 diff --git a/checks/check_extra7164 b/checks/check_extra7164 new file mode 100644 index 0000000000..0fe7ed33f2 --- /dev/null +++ b/checks/check_extra7164 @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2019) by Toni de la Fuente +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. + +# Remediation: +# +# https://docs.aws.amazon.com/cli/latest/reference/logs/associate-kms-key.html +# associate-kms-key +# --log-group-name +# --kms-key-id +# [--cli-input-json ] +# [--generate-cli-skeleton ] + +CHECK_ID_extra7164="7.164" +CHECK_TITLE_extra7164="[extra7164] Check if CloudWatch log groups are protected by AWS KMS " +CHECK_SCORED_extra7164="NOT_SCORED" +CHECK_TYPE_extra7164="EXTRA" +CHECK_SEVERITY_extra7164="Medium" +CHECK_ASFF_RESOURCE_TYPE_extra7164="Logs" +CHECK_ALTERNATE_extra7164="extra7164" +CHECK_SERVICENAME_extra7164="logs" +CHECK_RISK_extra7164="" +CHECK_REMEDITATION_extra7164="Associate KMS Key with Cloudwatch log group." +CHECK_DOC_extra7164="https://docs.aws.amazon.com/cli/latest/reference/logs/associate-kms-key.html" +CHECK_CAF_EPIC_extra7164="Data Protection" + +extra7164(){ + # "Check if Cloudwatch log groups are associated with AWS KMS" + for regx in $REGIONS; do + LIST_OF_LOGGROUPS=$($AWSCLI logs describe-log-groups $PROFILE_OPT --region $regx --output json | jq '.logGroups[]') + if [[ $LIST_OF_LOGGROUPS ]]; then + LIST_OF_LOGGROUPS_WITHOUT_KMS=$(echo "${LIST_OF_LOGGROUPS}" | jq '. | select( has("kmsKeyId") == false )' | jq -r '.logGroupName') + LIST_OF_LOGGROUPS_WITH_KMS=$(echo "${LIST_OF_LOGGROUPS}" | jq '. | select( has("kmsKeyId") == true )' | jq -r '.logGroupName') + if [[ $LIST_OF_LOGGROUPS_WITHOUT_KMS ]]; then + for loggroup in $LIST_OF_LOGGROUPS_WITHOUT_KMS; do + textFail "$regx: ${loggroup} does not have AWS KMS keys associated." "$regx" "${loggroup}" + done + fi + if [[ $LIST_OF_LOGGROUPS_WITH_KMS ]]; then + for loggroup in $LIST_OF_LOGGROUPS_WITH_KMS; do + textPass "$regx: ${loggroup} does have AWS KMS keys associated." "$regx" "${loggroup}" + done + fi + else + textPass "$regx: No Cloudwatch log groups found." "$regx" + fi + done +}