From 9a060a3c43101f19f482d0471bf7de5a9eef0c7c Mon Sep 17 00:00:00 2001 From: Martina Rath Date: Wed, 30 Dec 2020 08:41:01 +0100 Subject: [PATCH] Add new extras check (7130) to check encryption of a SNS topic --- checks/check_extra7130 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 checks/check_extra7130 diff --git a/checks/check_extra7130 b/checks/check_extra7130 new file mode 100644 index 00000000..0ac8b245 --- /dev/null +++ b/checks/check_extra7130 @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Prowler - the handy cloud security tool (copyright 2018) 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. + +CHECK_ID_extra7130="7.130" +CHECK_TITLE_extra7130="[extra7130] Ensure there are no SNS Topics unencrypted (Not Scored) (Not part of CIS benchmark)" +CHECK_SCORED_extra7130="NOT_SCORED" +CHECK_TYPE_extra7130="EXTRA" +CHECK_SEVERITY_extra7130="Medium" +CHECK_ASFF_RESOURCE_TYPE_extra7130="AwsSnsTopic" +CHECK_ALTERNATE_check7130="extra7130" + +extra7130(){ + textInfo "Looking for SNS Topics in all regions... " + for regx in $REGIONS; do + LIST_SNS=$($AWSCLI sns list-topics --region $regx --query 'Topics[*].TopicArn' --output text) + if [[ $LIST_SNS ]];then + for topic in $LIST_SNS; do + SHORT_TOPIC=$(echo $topic | awk -F ":" '{print $NF}') + SNS_ENCRYPTION=$($AWSCLI sns get-topic-attributes --region $regx --topic-arn $topic --query 'Attributes.KmsMasterKeyId' --output text) + if [[ "None" == $SNS_ENCRYPTION ]]; then + textFail "$regx: $SHORT_TOPIC is not encrypted!" "$regx" + else + textPass "$regx: $SHORT_TOPIC is encrypted" "$regx" + fi + done + else + textInfo "$regx: No SNS topic found" "$SHORT_TOPIC" "$regx" + fi + done +}