CLI error with Application Default Credentials: "You do not currently have an active account..."

Short Version:

I've had a working Dev image for some time.  I recently `gcloud components update` to get to a more current version, as well as adding some new testing tools (for IaC solutions like chef, ansible, etc. using tools like kitchen (ruby) or molecule (python)).  I am now facing an issue where my cli commands return: `You do not currently have an active account selected.` after having gone through the authentication flow via `gcloud auth application-default login`.

Details:

I have a script I run to initialize the testing environment with env variables.  Part of the script checks for `~/.config/gcloud/application-default-credentials.json` and runs `gcloud auth application-default login` if the file is missing or sufficiently old.  This has been working perfectly until recently.  My testing tools are giving back errors when trying to run compute commands against the API.  To troubleshoot, I tried running `gcloud compute instances list` and got the error `You do not currently have an active account selected.`. 

  • I can login to the console and see the project without issue
  • I can `gcloud auth login` without ADC and I'm able to get a valid response from the cli
  • I can see the file `application-default-credentials.json` is created in `~/.config/gcloud/`
  • I can verify that gcloud is able to recognize the login with `gcloud auth application-default print-access-token`
  • I have set the `GOOGLE_APPLICATION_CREDENTIALS` variable to point to the literal path of the `json` file
  • I have `gcloud components update`d again

I'm at a loss as to what the problem might be. Any help or guidance is greatly appreciated.

Solved Solved
0 2 315
1 ACCEPTED SOLUTION

I've been over the docs, including the pages you referenced, for hours and hours trying to understand/solve this problem to no avail.  

Then I stumbled on this: 

"These credentials are not used by the gcloud CLI. For more ways to set up ADC, see Set up Application Default Credentials."

So - at least in current versions of the CLI, the Application-default credentials are ignored for CLI commands, but work for API commands that use the installed google python libraries. 😕

This was not presented very well in the documentation.

View solution in original post

2 REPLIES 2

Hi @Dan-Joe,

Welcome to Google Cloud Community!

It seems that you forgot to perform the command gcloud init as gcloud auth login only authorizes access only. Meaning that you are logged but it will prevent you performing other steps within your project. Please check this documentation on authorizing the gcloud CLI for your reference.

Hope this helps.

I've been over the docs, including the pages you referenced, for hours and hours trying to understand/solve this problem to no avail.  

Then I stumbled on this: 

"These credentials are not used by the gcloud CLI. For more ways to set up ADC, see Set up Application Default Credentials."

So - at least in current versions of the CLI, the Application-default credentials are ignored for CLI commands, but work for API commands that use the installed google python libraries. 😕

This was not presented very well in the documentation.