Created
February 14, 2020 01:17
-
-
Save jaketf/27c4bfc31ed07b7abd06e6cda0bb23fb to your computer and use it in GitHub Desktop.
Search for GCP Roles containing a given permission
This file contains 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
#!/usr/bin/bash | |
# This is not an official product of Google Inc. | |
# This is a SLOW but convenient utility for finding | |
# GCP roles containing a permission. | |
# Example use: | |
# ./iam_search.sh compute.instances.setMetadata | |
# $1 a gcp permission (e.g. compute.instances.setMetadata) | |
function search_for_roles(){ | |
for ROLE in $(gcloud iam roles list | grep -oP "^name: \K(.+)") | |
do | |
DESCRIPTION=$(gcloud iam roles describe "${ROLE}") | |
if echo "${DESCRIPTION}" | grep -q "$1"; then | |
echo "${DESCRIPTION}" | grep -oP "^name: \K(.+)" | |
fi | |
done | |
} | |
search_for_roles $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment