From 38ad3ca657fd8b80c5a5e9f601f09b6b42349786 Mon Sep 17 00:00:00 2001 From: Toni de la Fuente Date: Thu, 19 Apr 2018 09:47:16 -0400 Subject: [PATCH] region and profile handling improved --- include/aws_profile_loader | 13 +++++++++++++ prowler | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/aws_profile_loader b/include/aws_profile_loader index 842fa155..c7e9d5ea 100644 --- a/include/aws_profile_loader +++ b/include/aws_profile_loader @@ -17,6 +17,9 @@ # instance profile (metadata server) if runs in an EC2 instance INSTANCE_PROFILE=$(curl -s -m 1 http://169.254.169.254/latest/meta-data/iam/security-credentials/) +if echo "$INSTANCE_PROFILE" | grep -q '404 - Not Found'; then + INSTANCE_PROFILE= +fi if [[ $PROFILE ]]; then PROFILE_OPT="--profile $PROFILE" @@ -32,3 +35,13 @@ else PROFILE="default" PROFILE_OPT="--profile $PROFILE" fi + +# Set default region by aws config, fall back to us-east-1 +REGION_CONFIG=$(aws configure get region) +if [[ $REGION_OPT ]]; then + REGION="$REGION_OPT" +elif [[ $REGION_CONFIG ]]; then + REGION="$REGION_CONFIG" +else + REGION="us-east-1" +fi diff --git a/prowler b/prowler index d3f9c992..24d67abf 100755 --- a/prowler +++ b/prowler @@ -35,7 +35,7 @@ OPTNORMAL="" PROWLER_VERSION=2.0-beta2 PROWLER_DIR=$(dirname "$0") -REGION="us-east-1" +REGION="" FILTERREGION="" MAXITEMS=100 MONOCHROME=0 @@ -92,7 +92,7 @@ while getopts ":hlkp:r:c:g:f:m:M:enb" OPTION; do PROFILE=$OPTARG ;; r ) - REGION=$OPTARG + REGION_OPT=$OPTARG ;; c ) CHECK_ID=$OPTARG