forked from webpwnized/gcp-audit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility-list-cloud-run-services.sh
executable file
·68 lines (56 loc) · 1.73 KB
/
utility-list-cloud-run-services.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
#!/bin/bash
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;
if [[ $PROJECT_IDS == "" ]]; then
declare PROJECT_IDS=$(gcloud projects list --format="flattened(PROJECT_ID)" | grep project_id | cut -d " " -f 2);
fi;
for PROJECT_ID in $PROJECT_IDS; do
gcloud config set project $PROJECT_ID 2>/dev/null;
declare SERVICES=$(gcloud run services list --quiet --format="json");
if [[ $SERVICES != "[]" ]]; then
echo "---------------------------------------------------------------------------------";
echo "Cloud Run Services for Project $PROJECT_ID";
echo "---------------------------------------------------------------------------------";
echo $SERVICES | jq -rc '.[]' | while IFS='' read -r SERVICE;do
NAME=$(echo $SERVICE | jq -rc '.metadata.name');
INGRESS_SETTING=$(echo $SERVICE | jq -rc '.metadata.annotations."run.googleapis.com/ingress"');
echo "Service Name: $NAME";
echo "Service Ingress Setting: $INGRESS_SETTING";
if [[ $INGRESS_SETTING == "all" ]]; then
echo "Violation: The ingress setting is configured to ALL, which allows all requests including requests directly from the internet";
fi;
echo "";
done;
echo "";
else
echo "No Cloud Run Services found for Project $PROJECT_ID";
echo "";
fi;
sleep 0.5;
done;