Answers: <p>After a bit more googling, I found that <a href="https://jamiekt.wordpress.com/2019/06/13/use-gcloud-to-list-all-project-roles-that-a-service-account-is-a-member-of/" rel="nofollow noreferrer">post</a>.</p>
  <p>Sorry!</p>
  <p>Here is the solution which works for me</p>
  <pre><code>gcloud projects get-iam-policy MY_PROJECT --format='table(bindings.role)' --filter=&quot;bindings.members:serviceAccount:12345678-compute@developer.gserviceaccount.com&quot;
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-06-22T12:08:19.877Z
Answers: 2021-06-22T12:08:19.877Z
Answers: KargWare
Body: <p><code>gcloud projects get-iam-policy [PROJECT-ID]</code> lists all users with their roles for specific project.</p>
  <p>There are different <a href="https://cloud.google.com/sdk/gcloud/reference/topic/filters" rel="nofollow noreferrer">filters</a> and formatters available but I can't seem to find the right way to just filter only by specific user.</p>
  <blockquote>
  <p><strong>HINT</strong>: I reused the example code of <a href="https://devops.stackexchange.com/questions/11291/how-to-list-all-users-with-specific-role-in-gcp">DevOps - How to list all users with specific role in GCP</a></p>
  </blockquote>
  <pre><code>$ gcloud projects get-iam-policy MY_PROJECT
  
  bindings:
  - members:
    - serviceAccount:12345678-compute@developer.gserviceaccount.com
    - user:alice@foobar.com
    role: roles/editor
  - members:
    - serviceAccount:12345678-compute@developer.gserviceaccount.com
    role: roles/pubsub.serviceAgent
  - members:
    - user:you@yourdomain.com
    - user:someoneelse@yourdomain.com
    role: roles/owner
  etag: ARBITRARY_ETAG_HERE
  version: 1
  </code></pre>
  <p>What's the <code>--filter=</code> expression that I need to use to list only items with the <strong>members</strong> <code>- serviceAccount:12345678-compute@developer.gserviceaccount.com</code>?</p>
  
Tags: <google-cloud-platform><gcp>
Title: How to filter all roles with specific user in GCP
UserDisplayName: KargWare
ThreadText: # How to filter all roles with specific user in GCP
  
  (Asked by: username_0 on 2021-06-22)
  
  `gcloud projects get-iam-policy [PROJECT-ID]` lists all users with their roles for specific project.
  
  There are different [filters](https://cloud.google.com/sdk/gcloud/reference/topic/filters) and formatters available but I can't seem to find the right way to just filter only by specific user.
  
  > **HINT**: I reused the example code of [DevOps - How to list all users with specific role in GCP](https://devops.stackexchange.com/questions/11291/how-to-list-all-users-with-specific-role-in-gcp)
  
  ```
  $ gcloud projects get-iam-policy MY_PROJECT
  
  bindings:
  - members:
    - serviceAccount:12345678-compute@developer.gserviceaccount.com
    - user:alice@foobar.com
    role: roles/editor
  - members:
    - serviceAccount:12345678-compute@developer.gserviceaccount.com
    role: roles/pubsub.serviceAgent
  - 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 items with the **members** `- serviceAccount:12345678-compute@developer.gserviceaccount.com`?
  
  **Tags:** google-cloud-platform, gcp
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-06-22. Score: 1
  
  After a bit more googling, I found that [post](https://jamiekt.wordpress.com/2019/06/13/use-gcloud-to-list-all-project-roles-that-a-service-account-is-a-member-of/).
  
  Sorry!
  
  Here is the solution which works for me
  
  ```
  gcloud projects get-iam-policy MY_PROJECT --format='table(bindings.role)' --filter="bindings.members:serviceAccount:12345678-compute@developer.gserviceaccount.com"
  
  ```
  
  
  ---
  
  