Skip to content

Instantly share code, notes, and snippets.

@bluPhy
Last active December 27, 2022 20:34
Show Gist options
  • Save bluPhy/258a69c5a0be26221ab18218e5554b90 to your computer and use it in GitHub Desktop.
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
#!/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