How to invoke gcloud with service account impersonation

試著忘記壹切 提交于 2020-08-22 06:23:06

问题


I have a service running in GCE with default service account A. This service uses gcloud to talk to various GCP services. Currently, it uses service account B to talk to some of the GCP services (using private key). However, we want to get rid of using private key and use account impersonation. To do that, I have added account A to the service account B's role and given token creator role.

I wrote a test program in go and was able to verify the impersonation works. However, our service is in PHP, and uses gcloud SDK. I couldn't find a way to configure gcloud to impersonate a service account or provide custom token.

One option is that I rewrite all the gcloud code to use google SDK, but that is lots of work, and I'd rather avoid that. My question is, how do I invoke gcloud using service account B in this scenario?. Is there a way to pass access token to gcloud or specify impersonation user?


回答1:


gcloud has a --impersonate-service-account flag for this.




回答2:


The Service Account User role is used to run operations as other service account. Using it you can act as a service account and run gcloud commands. The example shows how to use iam.serviceAccountUser role alongside with the compute.instanceAdmin role to create an instance.



来源:https://stackoverflow.com/questions/50921909/how-to-invoke-gcloud-with-service-account-impersonation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!