How do I list all IAM users for my Google Cloud Project

后端 未结 5 1342
野的像风
野的像风 2020-12-08 21:38

I\'d like to be able to list all users and service account associated with my projects (preferably using the gcloud CLI tool, but happy to make

5条回答
  •  攒了一身酷
    2020-12-08 22:01

    List all service accounts in a project

    The following command lists all service accounts associated with a project:

    $ gcloud iam service-accounts list
    
    NAME                                    EMAIL
    Compute Engine default service account  12345678-compute@developer.gserviceaccount.com
    dummy-sa-1                              dummy-sa-1@MY_PROJECT.iam.gserviceaccount.com
    

    List all Users and Service accounts in a project with their IAM roles

    If you would like to list all users/service-accounts who have been granted any IAM roles on a specified project, you can use this command:

    $ 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
    

    Formatting the output

    gcloud supports formatting the output as json and lot of other customizations as needed, which might be easier to parse in certain cases or print only the information you need.

    Examples:

    # Prints the output as json instead of the default yaml format
    $ gcloud projects get-iam-policy MY_PROJECT --format=json
    
    # Display just the bindings in json format
    $ gcloud projects get-iam-policy MY_PROJECT --format='json(bindings)'
    
    # Display the bindings in a flattened format
    $ $ gcloud projects get-iam-policy MY_PROJECT --format='flattened(bindings)'
    

提交回复
热议问题