Search code examples
google-cloud-platformgcloud

Why does gcloud crash when multiple scopes are passed?


I'm adding scopes to an access token via this gcloud command: gcloud auth application-default login --scopes='https://www.googleapis.com/auth/drive'. It works fine when I'm only adding 1 scope but whenever I try adding another like so gcloud auth application-default login --scopes='https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/cloud-platform', I am brought to the consent screen where I see the scopes provided. Upon accepting, I get this in my terminal:

ERROR: gcloud crashed (Warning): Scope has changed from "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/accounts.reauth" to "https://www.googleapis.com/auth/accounts.reauth https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/drive"

Any idea why this is happening? Am I not passing the scopes correctly?

NB. The scopes shown are already added in the console on GCP.


Solution

  • Try removing the spaces anywhere in your scope list, and use commas instead to separate each scope (in addition to enclosing the whole list in quotes), like so:

    gcloud auth application-default login --scopes='https://www.googleapis.com/auth/drive,https://www.googleapis.com/auth/cloud-platform'
    

    I received the same error at first using your command, but after looking at this issue report, it's caused by gcloud parsing the arguments incorrectly when spaces are present. Using the command above resolved it on my test.