TL;DR
Install wslu and run the command with DISPLAY='ANYTHING'
DISPLAY='X' gcloud auth application-default login
Why does this work?
There are two steps to solving this problem:
- We want to set a default browser to the linux distribution. This is one approach - https://superuser.com/a/1368878
- We want to get
gcloud
to work with our setting
After digging around the python CLI implementation, I found this piece of code inside check_browser.py
# These are environment variables that can indicate a running compositor on
# Linux.
_DISPLAY_VARIABLES = ['DISPLAY', 'WAYLAND_DISPLAY', 'MIR_SOCKET']
....
current_os = platforms.OperatingSystem.Current()
if (current_os is platforms.OperatingSystem.LINUX and
not any(encoding.GetEncodedValue(os.environ, var) for var
in _DISPLAY_VARIABLES)):
launch_browser = False
An easy solution that works for me is running the gcloud CLI with the environment variable DISPLAY='X'
:
DISPLAY='X' gcloud auth application-default login
You can also set an alias:
alias gauth='DISPLAY="X" gcloud auth application-default login'
Troubleshooting
However, this might now work on all systems. Also the code might change in the future. If Anyone else is interested in tweaking with it in a different manner, I located the relevant file under:
/usr/lib/google-cloud-sdk/lib/googlecloudsdk/command_lib/util/check_browser.py
And you can playaround with it in python
In [21]: from googlecloudsdk.command_lib.util.check_browser import *
In [22]: ShouldLaunchBrowser(True)
Out[22]: False