azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Unable to connect to `login.microsoftonline.com` when running `az login` on WSL: `ConnectTimeoutError`

Open sabbour opened this issue 10 months ago • 11 comments

Describe the bug

I'm unable to run Azure CLI commands on a WSL Ubuntu 24.04. I am able to resolve login.microsoft.com.

nslookup login.microsoftonline.com
Server:         10.255.255.254
Address:        10.255.255.254#53

Non-authoritative answer:
Name:   login.microsoftonline.com
Address: 6.6.0.4

Eventually it times out with a connection timeout.

I have checked https://github.com/Azure/azure-cli/issues/21514 and it doesn't help.

Related command

az login

Errors

urllib3.connectionpool: Starting new HTTPS connection (1): login.microsoftonline.com:443 urllib3.util.retry: Incremented Retry for (url='/organizations/v2.0/.well-known/openid-configuration'): Retry(total=0, connect=None, read=None, redirect=None, status=None) urllib3.connectionpool: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38858c80>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)')': /organizations/v2.0/.well-known/openid-configuration

Issue script & Debug output

az login --debug
cli.knack.cli: Command arguments: ['login', '--debug']
cli.knack.cli: __init__ debug log:
Enable color in terminal.
cli.knack.cli: Event: Cli.PreExecute []
cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f0b39d2f740>, <function OutputProducer.on_global_arguments at 0x7f0b39a82700>, <function CLIQuery.on_global_arguments at 0x7f0b39ac7c40>]
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate []
cli.azure.cli.core: Modules found from index for 'login': ['azure.cli.command_modules.profile']
cli.azure.cli.core: Loading command modules:
cli.azure.cli.core: Name                  Load Time    Groups  Commands
cli.azure.cli.core: profile                   0.016         2         8
cli.azure.cli.core: Total (1)                 0.016         2         8
cli.azure.cli.core: Loaded 2 groups, 8 commands.
cli.azure.cli.core: Found a match in the command table.
cli.azure.cli.core: Raw command  : login
cli.azure.cli.core: Command table: login
cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f0b38c12d40>]
cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/asabbour/.azure/commands/2025-02-05.12-19-48.login.1413.log'.
az_command_data_logger: command args: login --debug
cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x7f0b38c57ce0>]
cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad []
cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x7f0b38c860c0>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x7f0b38c86200>, <function register_upcoming_breaking_change_info.<locals>.update_breaking_change_info at 0x7f0b38c862a0>]
cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded []
cli.knack.cli: Event: CommandInvoker.OnPreParseArgs []
cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f0b39a827a0>, <function CLIQuery.handle_query_parameter at 0x7f0b39ac7ce0>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x7f0b38c86160>]
cli.azure.cli.core.auth.persistence: build_persistence: location='/home/asabbour/.azure/msal_token_cache.json', encrypt=False
cli.azure.cli.core.auth.binary_cache: load: /home/asabbour/.azure/msal_http_cache.bin
cli.azure.cli.core.auth.binary_cache: /home/asabbour/.azure/msal_http_cache.bin not found. Using a fresh one.
urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None)
msal.authority: Initializing with Entra authority: https://login.microsoftonline.com/organizations
urllib3.connectionpool: Starting new HTTPS connection (1): login.microsoftonline.com:443
urllib3.util.retry: Incremented Retry for (url='/organizations/v2.0/.well-known/openid-configuration'): Retry(total=0, connect=None, read=None, redirect=None, status=None)
urllib3.connectionpool: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38858c80>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)')': /organizations/v2.0/.well-known/openid-configuration


cli.azure.cli.core.azclierror: The command failed with an unexpected error. Here is the traceback:
az_command_data_logger: The command failed with an unexpected error. Here is the traceback:
cli.azure.cli.core.azclierror: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))
Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request
    self._validate_conn(conn)
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1060, in _validate_conn
    conn.connect()
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 179, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 829, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 801, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/retry.py", line 594, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/profile/custom.py", line 173, in login
    subscriptions = profile.login(
                    ^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/_profile.py", line 176, in login
    user_identity = identity.login_with_auth_code(scopes=scopes, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/auth/identity.py", line 167, in login_with_auth_code
    result = self._msal_app.acquire_token_interactive(
             ^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/auth/identity.py", line 126, in _msal_app
    self._msal_app_instance = PublicClientApplication(self.client_id, **self._msal_public_app_kwargs)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/application.py", line 1974, in __init__
    super(PublicClientApplication, self).__init__(
  File "/opt/az/lib/python3.12/site-packages/msal/application.py", line 608, in __init__
    self.authority = Authority(
                     ^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/authority.py", line 79, in __init__
    openid_config = tenant_discovery(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/authority.py", line 210, in tenant_discovery
    resp = http_client.get(tenant_discovery_endpoint, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/individual_cache.py", line 269, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/adapters.py", line 688, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))
az_command_data_logger: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))
Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 715, in urlopen
    httplib_response = self._make_request(
                       ^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 404, in _make_request
    self._validate_conn(conn)
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 1060, in _validate_conn
    conn.connect()
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 363, in connect
    self.sock = conn = self._new_conn()
                       ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connection.py", line 179, in _new_conn
    raise ConnectTimeoutError(
urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/requests/adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 829, in urlopen
    return self.urlopen(
           ^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/connectionpool.py", line 801, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/urllib3/util/retry.py", line 594, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/az/lib/python3.12/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 666, in execute
    raise ex
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 734, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 703, in _run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 336, in __call__
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/commands/command_operation.py", line 120, in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/command_modules/profile/custom.py", line 173, in login
    subscriptions = profile.login(
                    ^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/_profile.py", line 176, in login
    user_identity = identity.login_with_auth_code(scopes=scopes, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/auth/identity.py", line 167, in login_with_auth_code
    result = self._msal_app.acquire_token_interactive(
             ^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/azure/cli/core/auth/identity.py", line 126, in _msal_app
    self._msal_app_instance = PublicClientApplication(self.client_id, **self._msal_public_app_kwargs)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/application.py", line 1974, in __init__
    super(PublicClientApplication, self).__init__(
  File "/opt/az/lib/python3.12/site-packages/msal/application.py", line 608, in __init__
    self.authority = Authority(
                     ^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/authority.py", line 79, in __init__
    openid_config = tenant_discovery(
                    ^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/authority.py", line 210, in tenant_discovery
    resp = http_client.get(tenant_discovery_endpoint, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/msal/individual_cache.py", line 269, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/az/lib/python3.12/site-packages/requests/adapters.py", line 688, in send
    raise ConnectTimeout(e, request=request)
requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='login.microsoftonline.com', port=443): Max retries exceeded with url: /organizations/v2.0/.well-known/openid-configuration (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7f0b38859040>, 'Connection to login.microsoftonline.com timed out. (connect timeout=None)'))
To check existing issues, please visit: https://github.com/Azure/azure-cli/issues
cli.knack.cli: Event: Cli.PostExecute [<function AzCliLogging.deinit_cmd_metadata_logging at 0x7f0b38c12fc0>]
az_command_data_logger: exit code: 1
cli.__main__: Command ran in 268.221 seconds (init: 0.559, invoke: 267.662)
telemetry.main: Begin splitting cli events and extra events, total events: 1
telemetry.client: Accumulated 0 events. Flush the clients.
telemetry.main: Finish splitting cli events and extra events, cli events: 1
telemetry.save: Save telemetry record of length 7683 in cache file under /home/asabbour/.azure/telemetry/20250205122415978
telemetry.main: Begin creating telemetry upload process.
telemetry.process: Creating upload process: "/opt/az/bin/python3 /opt/az/lib/python3.12/site-packages/azure/cli/telemetry/__init__.py /home/asabbour/.azure /home/asabbour/.azure/telemetry/20250205122415978"
telemetry.process: Return from creating process 1488
telemetry.main: Finish creating telemetry upload process.

Expected behavior

Doesn't time out

Environment Summary

az -v
azure-cli                         2.68.0

core                              2.68.0
telemetry                          1.1.0

Dependencies:
msal                              1.31.1
azure-mgmt-resource               23.1.1

Python location '/opt/az/bin/python3'
Extensions directory '/home/asabbour/.azure/cliextensions'

Python (Linux) 3.12.8 (main, Jan  8 2025, 03:38:16) [GCC 13.3.0]

Legal docs and information: aka.ms/AzureCliLegal


Your CLI is up-to-date.
which az
/usr/bin/az
cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 10.255.255.254
search corp.microsoft.com redmond.corp.microsoft.com lan windeploy.ntdev.microsoft.com sangam.microsoft.com msft.net gtm.microsoft.com osdinfra.net qa.skype.gbl msstore.microsoftstore.com skype.net off svceng.com extest.microsoft.com ntdev.microsoft.com ap.gbl portal.gbl dns.microsoft.com phx.gbl sts.microsoft.com extranet.microsoft.com in-addr.arpa ip6.arpa ccc42azstack.com privatelink.database.windows.net privatelink.blob.core.windows.net privatelink.table.core.windows.net privatelink.queue.core.windows.net privatelink.file.core.windows.net privatelink.web.core.windows.net privatelink.dfs.core.windows.net ssc.microsoft.com privatelink.azurewebsites.net database.windows.net file.core.windows.net privatelink.vaultcore.azure.net privatelink.azurecr.io privatelink.redis.cache.windows.net privatelink.api.azureml.ms privatelink.azure-devices.net privatelink.datafactory.azure.net privatelink.notebooks.azure.net azurecr.io redis.cache.windows.net api.azureml.ms azure-devices.net azurewebsites.net datafactory.azure.net notebooks.azure.net nttest.microsoft.com eaglex.ic.gov

Additional context

No response

sabbour avatar Feb 05 '25 20:02 sabbour

Thank you for opening this issue, we will look into it.

yonzhan avatar Feb 05 '25 20:02 yonzhan

Here are some similar issues that might help you. Please check if they can solve your problem.

  • #23672
  • #24084
  • #24027
  • #23775

github-actions[bot] avatar Feb 05 '25 20:02 github-actions[bot]

I've started having the exact same issue with WSL on Ubuntu 22.04.5 LTS. It used to work before.

nslookup works - ~$ nslookup login.microsoftonline.com Server: 10.255.255.254 Address: 10.255.255.254#53

Non-authoritative answer: Name: login.microsoftonline.com Address: 6.6.0.100

But curl to https://login.microsoftonline.com/ from WSL hangs. Invoke-WebRequest https://login.microsoftonline.com/ from powershell in Windows works fine, so it seems to be WSL specific. I've tried disabling the Windows Firewall but that doesn't seem to help.

I'm on the latest az cli and the debug output is - ~$ az login --use-device-code --debug cli.knack.cli: Command arguments: ['login', '--use-device-code', '--debug'] cli.knack.cli: init debug log: Enable color in terminal. cli.knack.cli: Event: Cli.PreExecute [] cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x7f2b509fb740>, <function OutputProducer.on_global_arguments at 0x7f2b5074e700>, <function CLIQuery.on_global_arguments at 0x7f2b50793c40>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'login': ['azure.cli.command_modules.profile'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: profile 0.001 2 8 cli.azure.cli.core: Total (1) 0.001 2 8 cli.azure.cli.core: Loaded 2 groups, 8 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : login cli.azure.cli.core: Command table: login cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x7f2b4f9bade0>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to '/home/shivram/.azure/commands/2025-02-12.15-46-23.login.631.log'. az_command_data_logger: command args: login --use-device-code --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x7f2b4f9fbd80>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x7f2b4fa2e160>, <function register_cache_arguments..add_cache_arguments at 0x7f2b4fa2e2a0>, <function register_upcoming_breaking_change_info..update_breaking_change_info at 0x7f2b4fa2e340>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x7f2b5074e7a0>, <function CLIQuery.handle_query_parameter at 0x7f2b50793ce0>, <function register_ids_argument..parse_ids_arguments at 0x7f2b4fa2e200>] cli.azure.cli.core.auth.persistence: build_persistence: location='/home/shivram/.azure/msal_token_cache.json', encrypt=False cli.azure.cli.core.auth.binary_cache: load: /home/shivram/.azure/msal_http_cache.bin urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) msal.authority: Initializing with Entra authority: https://login.microsoftonline.com/organizations urllib3.connectionpool: Starting new HTTPS connection (1): login.microsoftonline.com:443

shivshanks avatar Feb 12 '25 23:02 shivshanks

I've been seeing the same issue since January 26th. For me, the issue only happens with Ubuntu 22.04 WSL, but not with my Ubuntu 24.04 instance (or Windows), for some reason. Wiping and reinstalling 22.04 doesn't seem to help either.

It also only occurs from home, but not when I use WSL on a DevBox (which is how I'm working around the issue currently).

stevchin avatar Feb 13 '25 17:02 stevchin

As curl doesn't work for @shivshanks either:

But curl to https://login.microsoftonline.com/ from WSL hangs. Invoke-WebRequest https://login.microsoftonline.com/ from powershell in Windows works fine, so it seems to be WSL specific. I've tried disabling the Windows Firewall but that doesn't seem to help.

I also think this is a WSL issue.

@sabbour, @stevchin, could you try using curl and see if it can connect to https://login.microsoftonline.com/ ?

curl https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration

You may also try using python:

/opt/az/bin/python3 -c "import requests; print(requests.get('https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration').status_code)"

If they also fail, I recommend opening an issue on https://github.com/microsoft/WSL/issues.

jiasli avatar Feb 14 '25 09:02 jiasli

Yes, it does seem to be a WSL issue. I installed Ubuntu 24.04 and still have issues making a request via curl to https://login.microsoftonline.com/. In fact, neither does https://www.microsoft.com work but https://www.google.com/ works!

One way to work around it is to install az-cli on Windows via the MSI. One of the nice things about WSL is that most windows programs can be invoked from within WSL, The MSI does add itself to the path that is exposed to WSL and it works within WSL. I've tested it with simple shell scripts inside WSL and it seems to be fine.

I'll file an issue with WSL later when I get a chance. If someone gets to it before, please share a link.

shivshanks avatar Feb 14 '25 17:02 shivshanks

When I changed the DNS server to 8.8.8.8 in resolv.conf, it immediately works until WSL overwrites the file again.

sabbour avatar Feb 14 '25 17:02 sabbour

Yes, that does seem to be the issue.

Even if you set the option - generateResolvConf = false

as it recommends, if you shutdown and restart WSL it resets it to the earlier option.

shivshanks avatar Feb 14 '25 17:02 shivshanks

It seems I misread the instructions on where to set the generateResolvConf. You need to set this option in wsl.conf and not resolv.conf (as I did by mistake). But next you need to remove the /etc/resolv.conf which is symlink and then create your own.

So, the steps to fix it are -

  1. Save your current /etc/resolv.conf
  2. Add the following to /etc/wsl.conf [network] generateResolvConf = false
  3. Shutdown wsl
  4. Start your distro again and remove the symlink via sudo rm /etc/resolv.conf.
  5. Create a new /etc/resolv.conf with your saved values and nameserver as 8.8.8.8 or whatever you need.

The real bug seems to be that WSL seems to be auto creating a resolv.conf with a nameserver that doesn't work.

shivshanks avatar Feb 14 '25 20:02 shivshanks

I've filed an issue against WSL here - https://github.com/microsoft/WSL/issues/12587

shivshanks avatar Feb 14 '25 21:02 shivshanks

I fixed this by turning networking to NAT and turning off these DNS options in WSL Settings:

Image

kennethgp avatar Jun 04 '25 16:06 kennethgp

Doing a wsl --update resolved this issue for me (version 2.6.1.0 now), no other networking or config changes needed.

sdherr avatar Sep 19 '25 14:09 sdherr