HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to list all users with specific role in GCP

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
allwithrolehowlistusersgcpspecific

Problem

gcloud projects get-iam-policy [PROJECT-ID] lists all users with their roles for specific project. There are different filters and formatters available but I can't seem to find the right way to just filter only by specific role.

$ gcloud projects get-iam-policy MY_PROJECT

bindings:
- members:
  - serviceAccount:12345678-compute@developer.gserviceaccount.com
  - user:alice@foobar.com
  role: roles/editor
- members:
  - user:you@yourdomain.com
  - user:someoneelse@yourdomain.com
  role: roles/owner
etag: ARBITRARY_ETAG_HERE
version: 1


What's the --filter= expression that I need to use to list only users with the role roles/owner?

Solution

That can be achieved using another gcloud command:

gcloud beta asset search-all-iam-policies --query policy:"roles/owner" --project $your_project_id --flatten="results[].policy[]" --format="csv(bindings.members[0])"

Code Snippets

gcloud beta asset search-all-iam-policies --query policy:"roles/owner" --project $your_project_id --flatten="results[].policy[]" --format="csv(bindings.members[0])"

Context

StackExchange DevOps Q#11291, answer score: 3

Revisions (0)

No revisions yet.