Score:2

authentication with gcloud not working

in flag

After setting up the gcloud cli months ago on my Mac and it working without issue, a few days ago gcloud generated an error because it said I was not authenticated. I ran gcloud auth login which was successful and no error generated. But, any subsequent gcloud command failed with an error. For example:

gcloud projects list
ERROR: (gcloud.projects.list) UNAUTHENTICATED: Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

I then revoked my credentials, backed up my ~/.config/gcloud/ directory and then removed it to attempt to start fresh with gcloud init. The first part of gcloud init succeeds and I get the "You are now authenticated with the Google Cloud SDK!" web page but the subsequent step that prompts you to set a default project fails with this error:

You are logged in as: [[email protected]].

WARNING: Listing available projects failed: HttpError accessing <https://cloudresourcemanager.googleapis.com/v1/projects?alt=json&filter=lifecycleState%3AACTIVE&pageSize=201>: response: <{'www-authenticate': 'Bearer realm="https://accounts.google.com/"', 'vary': 'Origin, X-Origin, Referer', 'content-type': 'application/json; charset=UTF-8', 'content-encoding': 'gzip', 'date': 'Wed, 23 Jun 2021 21:15:37 GMT', 'server': 'ESF', 'cache-control': 'private', 'x-xss-protection': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'server-timing': 'gfet4t7; dur=20', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"', 'transfer-encoding': 'chunked', 'status': 401}>, content <{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}
>
Enter project id you would like to use:

The issue is not with my account. I can login successfully on another machine and via gcloud in docker. I also created a new local account on my Mac and was able to setup gcloud successfully with the same Google account. I am at a loss as to what could be causing the issue at this point. All that I know is that it is something specific to my regular, daily use environment in my local account on my Mac.

Here are the steps I have tried that have been unsuccessful in getting gcloud to work again:

  • Change my shell from bash back to zsh.
  • Downloaded the gcloud archive that includes a python interpreter.
  • Ran gcloud init after following the uninstall directions.
  • Compared the contents of ~/.config/gcloud/ on a working machine with what is in the same dir on my non-working local account, including what is in the sqlite files (nothing jumps out as missing/broken).
  • Running gcloud init and using a different browser.
  • Running gcloud init --console-only.
  • Running gcloud init in a shell with with my .bash_profile removed so none of my shell customizations would be a factor.

If I had to guess what caused the issue was something new I installed or a regular update to an existing tool. I have reviewed anything that was updated to see what the culprit may be but did not find anything substantial.

Any additional avenues I can use to further debug or any method I can use to "reset" anything that gcloud may touch would be greatly appreciated!

Relevant gcloud info output:

Google Cloud SDK [346.0.0]

Platform: [Mac OS X, x86_64] uname_result(system='Darwin', node='Brandons-MacBook-Pro.local', release='19.6.0', version='Darwin Kernel Version 19.6.0: Thu May  6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64', machine='x86_64', processor='i386')
Locale: ('en_US', 'UTF-8')
Python Version: [3.8.8 (default, Mar 22 2021, 17:49:45)  [Clang 11.0.3 (clang-1103.0.32.62)]]
Python Location: [/Users/bboles/.pyenv/versions/3.8.8/bin/python3]
Site Packages: [Disabled]

Installation Root: [/Users/bboles/tools/google-cloud-sdk]
Installed Components:
  gsutil: [4.63]
  core: [2021.06.18]
  bq: [2.0.69]
System PATH: [/Users/bboles/.pyenv/versions/3.8.8/bin:/usr/local/Cellar/pyenv/2.0.1/libexec:/usr/local/Cellar/pyenv/2.0.1/plugins/python-build/bin:/Users/bboles/.rbenv/shims:/Users/bboles/.rbenv/bin:/Users/bboles/.pyenv/shims:/Users/bboles/.pyenv/bin:/Users/bboles/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/bboles/tools/google-cloud-sdk/bin:/Users/bboles/.rbenv/shims:/Users/bboles/.rbenv/bin:/Users/bboles/.pyenv/shims:/Users/bboles/.pyenv/bin:/Users/bboles/bin:/usr/local/opt/mysql-client/bin:/sbin:/usr/sbin:/usr/local/opt/mysql-client/bin]
Python PATH: [/Users/bboles/tools/google-cloud-sdk/lib/third_party:/Users/bboles/tools/google-cloud-sdk/lib:/Users/bboles/.pyenv/versions/3.8.8/lib/python38.zip:/Users/bboles/.pyenv/versions/3.8.8/lib/python3.8:/Users/bboles/.pyenv/versions/3.8.8/lib/python3.8/lib-dynload]
Cloud SDK on PATH: [True]
Kubectl on PATH: [/usr/local/bin/kubectl]

Installation Properties: [/Users/bboles/tools/google-cloud-sdk/properties]
User Config Directory: [/Users/bboles/.config/gcloud]
Active Configuration Name: [default]
Active Configuration Path: [/Users/bboles/.config/gcloud/configurations/config_default]

Account: [[email protected]]
Project: [None]

Current Properties:
  [core]
    account: [[email protected]]
    disable_usage_reporting: [True]

Logs Directory: [/Users/bboles/.config/gcloud/logs]
Last Log File: [/Users/bboles/.config/gcloud/logs/2021.06.23/16.05.57.047852.log]

git: [git version 2.32.0]
ssh: [OpenSSH_8.1p1, LibreSSL 2.7.3]
John Hanley avatar
cn flag
I think your Python environment is messed up. As a debugging step, create a new user. Login as that user and try the SDK installation and setup again. If that works, compare how the two users are set up regarding the environment, Python, pyenv, etc.
Score:1
cn flag

To have an answer on this question, as John said it is possible that you got this issue due to messed up setup of Python environment. Creating another user to login as a debugging step will help to determine the issue.

Another alternative way, since it was a months ago try to update the gcloud version or re-install using the latest Cloud SDK version.

bboles avatar
in flag
I did update to the latest and don't seem to have the issue any longer. Still perplexing because I have updated `gcloud` several times since initially encountering this problem but it made no difference. I am still not sure of root cause. FWIW here is my current version that does not exhibit any auth issues: `gcloud --version Google Cloud SDK 359.0.0 bq 2.0.71 core 2021.09.24 gsutil 5.2`
Score:0
es flag

I had this same error. Deleting ~/.netrc fixed it for me.

The Requests library, used by gcloud, looks for ~/.netrc. If that file exists in some form, Requests replaces the OAuth header with a Basic auth header.

Filipe Freire avatar
cn flag
I kept getting the `Credentials in post body and basic Authorization header do not match` error, and deleting the `.netrc` file also fixed it for me. Thank you!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.