forked from webpwnized/gcp-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cis-1.18.1-secrets-exposed-in-cloud-functions.sh
executable file
·84 lines (67 loc) · 2.02 KB
/
cis-1.18.1-secrets-exposed-in-cloud-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
source functions.inc
PROJECT_IDS="";
DEBUG="False";
HELP=$(cat << EOL
$0 [-p, --project PROJECT] [-d, --debug] [-h, --help]
EOL
);
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--debug") set -- "$@" "-d" ;;
"--project") set -- "$@" "-p" ;;
*) set -- "$@" "$arg"
esac
done
while getopts "hdp:" option
do
case "${option}"
in
p)
PROJECT_IDS=${OPTARG};;
d)
DEBUG="True";;
h)
echo $HELP;
exit 0;;
esac;
done;
declare SEPARATOR="----------------------------------------------------------------------------------------";
if [[ $PROJECT_IDS == "" ]]; then
declare PROJECT_IDS=$(get_projects);
fi;
for PROJECT_ID in $PROJECT_IDS; do
set_project $PROJECT_ID;
if ! api_enabled cloudfunctions.googleapis.com; then
echo "Cloud Functions not enabled for Project $PROJECT_ID.";
continue;
fi
declare RESULTS=$(gcloud functions list --quiet --format="json");
if [[ $RESULTS != "[]" ]]; then
# Get project details
get_project_details $PROJECT_ID
echo $SEPARATOR;
echo "Cloud functions for project $PROJECT_ID";
echo "Project Application: $PROJECT_APPLICATION";
echo "Project Owner: $PROJECT_OWNER";
echo "";
echo $RESULTS | jq -r -c '.[]' | while IFS='' read -r CLOUD_FUNCTION;do
NAME=$(echo $CLOUD_FUNCTION | jq -rc '.name' | cut -d '/' -f 6);
BUILD_ENIVRONMENT_VARIABLES=$(echo $CLOUD_FUNCTION | jq '.buildEnvironmentVariables');
ENIVRONMENT_VARIABLES=$(echo $CLOUD_FUNCTION | jq '.environmentVariables');
INGRESS_SETTINGS=$(echo $CLOUD_FUNCTION | jq '.ingressSettings');
echo "Name: $NAME";
echo "Build Environment Variables: $BUILD_ENIVRONMENT_VARIABLES";
echo "Environment Variables: $ENIVRONMENT_VARIABLES";
if [[ $INGRESS_SETTINGS =~ "ALLOW_ALL" ]]; then echo "VIOLATION: Cloud function allows all ingress"; fi;
echo "";
done;
else
echo $SEPARATOR;
echo "No cloud functions found for $PROJECT_ID";
echo "";
fi;
sleep 0.5;
done;