Skip to content

Instantly share code, notes, and snippets.

@jaketf
Created February 14, 2020 01:17
Show Gist options
  • Save jaketf/27c4bfc31ed07b7abd06e6cda0bb23fb to your computer and use it in GitHub Desktop.
Save jaketf/27c4bfc31ed07b7abd06e6cda0bb23fb to your computer and use it in GitHub Desktop.
Search for GCP Roles containing a given permission
#!/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