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.

1 answer

  • answered 2018-11-12 22:37 John Hanley

    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 test@development-123456.iam.gserviceaccount.com --key-file=test_google_account.json