6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GCPのユーザ一覧をCLIで出すワンライナー

Last updated at Posted at 2019-06-10

gcloudにはユーザ一覧を簡単に出すコマンドが無いです
IAM権限ごとに該当するユーザを表示するコマンドgcloud projects get-iam-policyをjqで加工するワンライナーを書きました

※jqが必要です
brew install jq
※それぞれYOUR_PROJECT_IDをproject_idに置き換えてください

全てのユーザ一覧

gcloud projects get-iam-policy YOUR_PROJECT_ID --format=json | jq -r '.bindings | reduce .[].members as $item ([]; .+$item) | unique | .[] | select(startswith("user"))' | sed -e 's/user:\(.*\)/\1/'

管理者ユーザ一覧

gcloud projects get-iam-policy YOUR_PROJECT_ID --format=json | jq -r '.bindings[] | select(.role == "roles/owner") | .members[]' | sed -e 's/user:\(.*\)/\1/'

管理者以外のユーザ一覧

gcloud projects get-iam-policy YOUR_PROJECT_ID --format=json | jq -r '[.bindings | reduce .[].members as $item ([]; .+$item) | unique | .[] | select(startswith("user"))] - (.bindings[] | select(.role == "roles/owner") | .members) | .[]' | sed -e 's/user:\(.*\)/\1/'
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?