Last active
December 27, 2022 20:34
-
-
Save bluPhy/258a69c5a0be26221ab18218e5554b90 to your computer and use it in GitHub Desktop.
Script to retrieve GCP IAM roles, users and serviceaccounts, must be used in conjunction with iam-json-reformat.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to retrieve GCP IAM roles, users and serviceaccounts | |
# Author - Alejandro Leal [email protected] (Originally from Rajathithan Rajasekar) | |
echo 'project-id,roles/rolename,user:username-and-serviceaccounts' > iamlist.csv | |
prjs=( $(gcloud projects list | awk '/PROJECT_ID/{print $2}') ) | |
for i in "${prjs[@]}" | |
do | |
echo "------------------------------------------------------------" | |
echo "Collecting IAM roles & users for Project: $i" | |
gcloud projects get-iam-policy "$i" --format="table(bindings)[0]" | sed -e 's/^\w*\ *//' | tail -c +2 | python iam-json-reformat.py "$i" >> iamlist.csv | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment