LoginSignup
4
4

More than 3 years have passed since last update.

gcloudコマンドからIAM Permission付与、取り消し

Last updated at Posted at 2019-05-09

Cloud Build 経由の AppEngineデプロイなど、サービスが関連して処理するものにはあらかじめPermissionが必要。
(この場合、CloudBuildのサービスアカウントに appengine/appAdmin のロールが必要)

=> こちらも参考に:Permissionに対する適切なRoleを調べる方法

毎度GCPのConsoleから付与してたけど、付与したいものもだいたい決まってきたから、コマンドで実行したい。

と思い立って調べたけど、タイプ数考えたら画面からポチポチするのと大差ない気もした。


サービスアカウントを特定する必要もあるので、多分手順の流れとしては、

  • 現在のpermission確認
  • 付与したいサービスアカウント名コピペ
  • (必要であればロール一覧確認)
  • permission付与(メンバーのとこでサービスアカウント名貼り付け)

な感じになるんじゃなかろうか。


以下、プロジェクトID = ideodora-sandbox001 とする。

Permission 確認

gcloud projects get-iam-policy ideodora-sandbox001

=>
bindings:
- members:
  - serviceAccount:xxxx@cloudbuild.gserviceaccount.com
  role: roles/cloudbuild.builds.builder
- members:
  - user:ideodora@gmail.com
  role: roles/owner

...中略...

etag: BwWIYRKoU44=
version: 1

Permission 付与

gcloud projects add-iam-policy-binding ideodora-sandbox001 \
> --member serviceAccount:xxxx@cloudbuild.gserviceaccount.com \
> --role roles/appengine.appAdmin

=>
Updated IAM policy for project [ideodora-sandbox001].
bindings:
- members:
  - serviceAccount:xxxx@cloudbuild.gserviceaccount.com
  role: roles/cloudbuild.builds.builder
- members:
  - user:ideodora@gmail.com
  role: roles/owner
- members:
  - serviceAccount:xxxx@cloudbuild.gserviceaccount.com
  role: roles/appengine.appAdmin

...中略...

etag: BwWIav2yCRA=
version: 1

Permission 取り消し

gcloud projects remove-iam-policy-binding ideodora-sandbox001 \
> --member serviceAccount:xxxx@cloudbuild.gserviceaccount.com \
> --role roles/appengine.appAdmin

=>
Updated IAM policy for project [ideodora-sandbox001].
bindings:
- members:
  - serviceAccount:xxxx@cloudbuild.gserviceaccount.com
  role: roles/cloudbuild.builds.builder
- members:
  - user:ideodora@gmail.com
  role: roles/owner

...中略...

etag: BwWIavlbwJU=
version: 1

そもそもロールって何がある?

以下のコマンドで確認できる。リソースの指定がプロジェクトIDだけではできず、フルパスを指定しろと言われる。。。長いし覚えれん。。。

configで対象プロジェクトセットしてんだから、そっから判定して欲しい。。。

--filter つけないと、全ロール出力するので、適当に欲しい

gcloud iam list-grantable-roles //cloudresourcemanager.googleapis.com/projects/ideodora-sandbox001 --filter=appengine

=>
---
description: Full management of App Engine apps (but not storage).
name: roles/appengine.appAdmin
title: App Engine Admin
---
description: Ability to view App Engine app status.
name: roles/appengine.appViewer
title: App Engine Viewer
---
description: Ability to view App Engine app status and deployed source code.
name: roles/appengine.codeViewer
title: App Engine Code Viewer
---
description: Necessary permissions to deploy new code to App Engine, and remove old
  versions.
name: roles/appengine.deployer
title: App Engine Deployer
---
description: Can view and change traffic splits, scaling settings, and delete old
  versions; can't create new versions.
name: roles/appengine.serviceAdmin
title: App Engine Service Admin

4
4
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
4
4