Search code examples
authenticationgoogle-cloud-platformgoogle-cloud-storageservice-accountsgsutil

Can I pass a key file as parameter to connect to Google Cloud Storage using gsutil?


When I use gsutil to connect to my bucket on Google Cloud Storage, I usually use the following command:

gcloud auth activate-service-account --key-file="pathKeyFile"

What should I do if two scripts that are running on the same machine at the same time need two different Service Accounts?

I would like to use a command such as:

gsutil ls mybucket --key-file="mykeyspath"

I say this because in the case my script is running and another script changes the Service Account which is actually active, my script would not have permission to access the bucket anymore.


Solution

  • You can do this with BOTO file. You can create one as explained in the documentation.

    Then you can specify which file to use when you run your gsutil command (here an example in linux)

    # if you have several GSUTIL command to run
    export BOTO_CONFIG=/path/to/.botoMyBucket
    gsutil ls myBucket
    
    # For only one command, you can define an env var inline like this
    BOTO_CONFIG=/path/to/.botoMyBucket2 gsutil ls myBucket2