Search code examples
google-cloud-platformservice-accounts

Is there a way to activate a Google cloud service account non-globally?


I have such requirement to manipulate different services on different projects. Hence I need to activate multiple service accounts at the same time to do those jobs. Those service accounts' roles are well controlled so there's no way to make a "admin"-like account to run on all projects. So I'm wondering if there's a way to activate one service account only in current process or some isolated environment without impact on global gcloud info settings. Any suggestion is appreciated.


Solution

  • You can use glcoud config configurations and setup multiple account configurations to select from.

    Then use the --configuration=configuration_name to select which one to use: gcloud compute instances list --configuration=NAME

    Run gcloud init and select Create a new configuration.

    You can change the default configuration with gcloud config configurations activate NAME.

    I wrote an article that documents gcloud configurations:

    Google Cloud – Understanding Gcloud Configurations

    You can also activate service account credentials which will then be part of gcloud config configurations.

    Creating and Authorizing Service Account Credentials with the CLI

    gcloud auth activate-service-account [email protected] --key-file=test_google_account.json