0
votes

I have one compute engine instance running in one project say ABC. I have service account of another project say xyz. I want to run a script on this compute engine but using service account of different project in Google cloud. How can I do this?

1
By run a script on machine "using" a service account of a different project, do you mean that the gcloud commands in that bash script run with the identity of the service account?Kolban
Service accounts can be given permission on more than one project. However, scripts are not run by service accounts, they are run by remote execution using SSH.John Hanley
If we have same project in same service account, then also we need to authenticate ??Bhagesh Arora

1 Answers

0
votes

If you want to run only a script for that session. you can use the following command, to make the current shell envrionment authenticated with that service account.

gcloud auth activate-service-account [ACCOUNT] --key-file=KEY_FILE [--password-file=PASSWORD_FILE | --prompt-for-password] [GCLOUD_WIDE_FLAG …]

Refer the documentation below.

https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account