azure-cli version >= 2.0.30 fails to run basic commands from workstations
azure-cli version >= 2.0.30 fails to run basic commands from workstations
Since azure-cli version 2.0.30, many az commands fail to run. They instead timeout after trying to reach 169.254.169.254. I'm guessing that the Python code is trying to interact with the Azure metadata service available from VMs and with MSI. I believe the error would not be visible if run from an Azure VM but manifests itself from workstations.
See trace dumps below for timeout and retry.
Environment summary
Mac OS High Sierra (10.13.4) Installed via Homebrew Shell: bash
Similar errors also observed on Linux and Windows workstations
Workaround: revert to <= 2.0.29.
Output of az -v
~/Desktop/tmp/test $ az -v
azure-cli (2.0.30)
acr (2.0.22)
acs (2.0.30)
advisor (0.5.0)
appservice (0.1.30)
backup (1.1.0)
batch (3.1.11)
batchai (0.1.6)
billing (0.1.7)
cdn (0.0.13)
cloud (2.0.12)
cognitiveservices (0.1.11)
command-modules-nspkg (2.0.1)
configure (2.0.14)
consumption (0.2.2)
container (0.1.20)
core (2.0.30)
cosmosdb (0.1.19)
dla (0.0.18)
dls (0.0.20)
eventgrid (0.1.11)
eventhubs (0.1.1)
extension (0.0.11)
feedback (2.1.0)
find (0.2.8)
interactive (0.3.18)
iot (0.1.18)
keyvault (2.0.20)
lab (0.0.20)
monitor (0.1.4)
network (2.0.26)
nspkg (3.0.2)
profile (2.0.21)
rdbms (0.2.0)
redis (0.2.11)
reservations (0.1.1)
resource (2.0.26)
role (2.0.21)
servicebus (0.1.1)
servicefabric (0.0.11)
sql (2.0.24)
storage (2.0.30)
vm (2.0.29)
Python location '/usr/local/opt/python/bin/python3.6'
Extensions directory '/Users/{redacted}/.azure/cliextensions'
Python (Darwin) 3.6.5 (default, Mar 30 2018, 06:41:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
Output from az group list:
HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /metadata/identity/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10531cdd8>: Failed to establish a new connection: [Errno 60] Operation timed out',))
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
(self.host, self.port), self.timeout, **extra_kw)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/util/connection.py", line 83, in create_connection
raise err
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/util/connection.py", line 73, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
self.send(msg)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
self.connect()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
conn = self._new_conn()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x10531cdd8>: Failed to establish a new connection: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /metadata/identity/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10531cdd8>: Failed to establish a new connection: [Errno 60] Operation timed out',))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 347, in execute
six.reraise(*sys.exc_info())
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 319, in execute
result = cmd(params)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 180, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/knack/commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 420, in default_command_handler
result = op(**command_args)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/command_modules/resource/custom.py", line 436, in list_resource_groups
return list(groups)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/msrest/paging.py", line 121, in __next__
self.advance_page()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/msrest/paging.py", line 107, in advance_page
self._response = self._get_next(self.next_link)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/mgmt/resource/resources/v2017_05_10/operations/resource_groups_operations.py", line 520, in internal_paging
request, header_parameters, **operation_config)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/msrest/service_client.py", line 191, in send
session = self.creds.signed_session()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/msi_imds_authentication.py", line 65, in signed_session
self._set_token()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/msi_imds_authentication.py", line 43, in _set_token
token_entry = self.get_token()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/msi_imds_authentication.py", line 60, in get_token
token_entry = self._retrieve_token_from_imds_with_retry()
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/azure/cli/core/msi_imds_authentication.py", line 85, in _retrieve_token_from_imds_with_retry
result = requests.get(request_uri, params=payload, headers={'Metadata': 'true'})
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.30/libexec/lib/python3.6/site-packages/requests/adapters.py", line 508, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /metadata/identity/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10531cdd8>: Failed to establish a new connection: [Errno 60] Operation timed out',))
@brichins what command you used to login? If you invoked az login w/o --msi or --identity, CLI should not try to connect to the IMDS wireserver as revealed from the stack trace you pasted.
Also, please share the output of az account show
I just login with az login. It give me a link and a code to paste into a browser. Here's a redacted version of az account show
az account show -o json
{
"environmentName": "AzureCloud",
"id": "{redacted}",
"isDefault": true,
"name": "{redacted}",
"state": "Enabled",
"tenantId": "{redacted}",
"user": {
"name": "{redacted}",
"type": "user"
}
}
I tried to logout and back in. That didn't fix it. I also deleted my $HOME/.azure* directories but that didn't fix it either.
So your VM does have MSI associated or no?
Also to confirm you still see the error after the following steps?
az account clear
az login (use the code and link to login)
az group list
I'm not working on a VM. I'm working from a local workstation. Outside Azure. I suspect this commit changed the behavior.
https://github.com/Azure/msrestazure-for-python/commit/908465f9047822a589c293c86950223983078aa2#diff-e119e806bfeec4f8f27be3a53b181345
What is the name field value of the az account show
~/Desktop/tmp $ az login
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code REDACTED to authenticate.
CloudName IsDefault Name State TenantId
----------- ----------- ------------------- ------- ------------------------------------
AzureCloud True {REDACTED------} Enabled REDACTED
AzureCloud {REDACTED---------} Enabled REDACTED
AzureCloud {REDACTED----} Enabled REDACTED
AzureCloud {REDACTED--------} Enabled REDACTED
AzureCloud {REDACTED------} Enabled REDACTED
~/Desktop/tmp $ az group list
HTTPConnectionPool(host='169.254.169.254', port=80): Max retries exceeded with url: /metadata/identity/oauth2/token?resource=https%3A%2F%2Fmanagement.core.windows.net%2F&api-version=2018-02-01 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x111cbab38>: Failed to establish a new connection: [Errno 60] Operation timed out',))
Output of the az account show name is at https://pastebin.com/raw/H0N15WHS
This is a bug i will fix. It looks like your subscription name collides with a MSI pattern. For now if possible, can you rename it to not start with MSI-?
I can't. The subscription was created and provided by my manager and his manager. MSI stands for Motorola Solutions, Inc.
The other workaround is after log-in, you can update the name inside ~/.azure/AzureProfile.json to any other ones
Thanks for the help and workaround.
Sorry for the inconvenience.
Any update on when this will be fixed? It's starting to impact more and more teams that we are onboarding to Azure. ~250 developers now, and growing.
The fix will be public released on May 7th, the earliest public release.
Thanks for the update
How do we move up this release? All of the Azure/VSTS hosted build nodes, that we pay for, have updated their az-cli client and all az commands are broken across our company.
@derekbekoe for the best recommendation here, but I think you would want to get the Edge Build temporarily until the next public release: https://github.com/Azure/azure-cli#edge-builds