ComputeManagementClient no longer picks up proper AzureUSGovernment endpoints from CLI creds.
- Package Name: azure-mgmt-compute
- Package Version: 17.0.0-20.0.0
- Operating System: Fedora WSL
- Python Version: 3.7.9
Describe the bug
When using get_client_from_cli_profile(ComputeManagementClient, subscription_id=sub), ComputeManagementClient does not pick up the Gov endpoint from the CLI profile. This can be seen with list(client.virtual_machines.list_all()). The CLI profile is correct, az account show and az vm list produce expected results.
To Reproduce
Steps to reproduce the behavior:
python3 -m venv .venvsource .venv/bin/activatepip install azure-mgmt-compute==20.0.0 azure-common==1.1.27 azure-cli-core==2.22.0- Update test.py with your subscription ID
az cloud set --name AzureUSGovernmentaz loginpython test.py
test.py:
from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient
from azure.common.cloud import get_cli_active_cloud
cloud = get_cli_active_cloud()
print(cloud)
sub = <REDACTED>
client = get_client_from_cli_profile(ComputeManagementClient, subscription_id=sub)
vms = list(client.virtual_machines.list_all())
print(vms)
Expected behavior A list of VMs printed on the console.
Screenshots
Console output from python test.py:
{'endpoints': {'active_directory': 'https://login.microsoftonline.us',
'active_directory_data_lake_resource_id': None,
'active_directory_graph_resource_id': 'https://graph.windows.net/',
'active_directory_resource_id': 'https://management.core.usgovcloudapi.net/',
'app_insights_resource_id': 'https://api.applicationinsights.us',
'app_insights_telemetry_channel_resource_id': 'https://dc.applicationinsights.us/v2/track',
'attestation_resource_id': None,
'azmirror_storage_account_resource_id': None,
'batch_resource_id': 'https://batch.core.usgovcloudapi.net/',
'gallery': 'https://gallery.usgovcloudapi.net/',
'log_analytics_resource_id': 'https://api.loganalytics.us',
'management': 'https://management.core.usgovcloudapi.net/',
'media_resource_id': 'https://rest.media.usgovcloudapi.net',
'microsoft_graph_resource_id': 'https://graph.microsoft.us/',
'ossrdbms_resource_id': 'https://ossrdbms-aad.database.usgovcloudapi.net',
'portal': 'https://portal.azure.us',
'resource_manager': 'https://management.usgovcloudapi.net/',
'sql_management': 'https://management.core.usgovcloudapi.net:8443/',
'synapse_analytics_resource_id': 'https://dev.azuresynapse.usgovcloudapi.net',
'vm_image_alias_doc': 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json'},
'is_active': True,
'name': 'AzureUSGovernment',
'profile': 'latest',
'suffixes': {'acr_login_server_endpoint': '.azurecr.us',
'attestation_endpoint': None,
'azure_datalake_analytics_catalog_and_job_endpoint': None,
'azure_datalake_store_file_system_endpoint': None,
'keyvault_dns': '.vault.usgovcloudapi.net',
'mariadb_server_endpoint': '.mariadb.database.usgovcloudapi.net',
'mhsm_dns': '.managedhsm.usgovcloudapi.net',
'mysql_server_endpoint': '.mysql.database.usgovcloudapi.net',
'postgresql_server_endpoint': '.postgres.database.usgovcloudapi.net',
'sql_server_hostname': '.database.usgovcloudapi.net',
'storage_endpoint': 'core.usgovcloudapi.net',
'storage_sync_endpoint': 'afs.azure.us',
'synapse_analytics_endpoint': '.dev.azuresynapse.usgovcloudapi.net'}}
Traceback (most recent call last):
File "test.py", line 9, in <module>
vms = list(client.virtual_machines.list_all())
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/paging.py", line 129, in __next__
return next(self._page_iterator)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/paging.py", line 76, in __next__
self._response = self._get_next(self.continuation_token)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/mgmt/compute/v2020_12_01/operations/_virtual_machines_operations.py", line 1159, in get_next
map_error(status_code=response.status_code, response=response, error_map=error_map)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/exceptions.py", line 102, in map_error
raise error
azure.core.exceptions.ClientAuthenticationError: (InvalidAuthenticationTokenAudience) The access token has been obtained for wrong audience or resource 'https://management.azure.com'. It should exactly match with one of the allowed audiences 'https://management.core.usgovcloudapi.net/','https://management.core.usgovcloudapi.net','https://management.usgovcloudapi.net/','https://management.usgovcloudapi.net'.
Additional context Add any other context about the problem here.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Drewm3, @avirishuv, @vaibhav-agar, @amjads1.
Issue Details
- Package Name: azure-mgmt-compute
- Package Version: 17.0.0-20.0.0
- Operating System: Fedora WSL
- Python Version: 3.7.9
Describe the bug
When using get_client_from_cli_profile(ComputeManagementClient, subscription_id=sub), ComputeManagementClient does not pick up the Gov endpoint from the CLI profile. This can be seen with list(client.virtual_machines.list_all()). The CLI profile is correct, az account show and az vm list produce expected results.
To Reproduce
Steps to reproduce the behavior:
python3 -m venv .venvsource .venv/bin/activatepip install azure-mgmt-compute==20.0.0 azure-common==1.1.27 azure-cli-core==2.22.0- Update test.py with your subscription ID
az cloud set --name AzureUSGovernmentaz loginpython test.py
test.py:
from azure.common.client_factory import get_client_from_cli_profile
from azure.mgmt.compute import ComputeManagementClient
from azure.common.cloud import get_cli_active_cloud
cloud = get_cli_active_cloud()
print(cloud)
sub = <REDACTED>
client = get_client_from_cli_profile(ComputeManagementClient, subscription_id=sub)
vms = list(client.virtual_machines.list_all())
print(vms)
Expected behavior A list of VMs printed on the console.
Screenshots
Console output from python test.py:
{'endpoints': {'active_directory': 'https://login.microsoftonline.us',
'active_directory_data_lake_resource_id': None,
'active_directory_graph_resource_id': 'https://graph.windows.net/',
'active_directory_resource_id': 'https://management.core.usgovcloudapi.net/',
'app_insights_resource_id': 'https://api.applicationinsights.us',
'app_insights_telemetry_channel_resource_id': 'https://dc.applicationinsights.us/v2/track',
'attestation_resource_id': None,
'azmirror_storage_account_resource_id': None,
'batch_resource_id': 'https://batch.core.usgovcloudapi.net/',
'gallery': 'https://gallery.usgovcloudapi.net/',
'log_analytics_resource_id': 'https://api.loganalytics.us',
'management': 'https://management.core.usgovcloudapi.net/',
'media_resource_id': 'https://rest.media.usgovcloudapi.net',
'microsoft_graph_resource_id': 'https://graph.microsoft.us/',
'ossrdbms_resource_id': 'https://ossrdbms-aad.database.usgovcloudapi.net',
'portal': 'https://portal.azure.us',
'resource_manager': 'https://management.usgovcloudapi.net/',
'sql_management': 'https://management.core.usgovcloudapi.net:8443/',
'synapse_analytics_resource_id': 'https://dev.azuresynapse.usgovcloudapi.net',
'vm_image_alias_doc': 'https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json'},
'is_active': True,
'name': 'AzureUSGovernment',
'profile': 'latest',
'suffixes': {'acr_login_server_endpoint': '.azurecr.us',
'attestation_endpoint': None,
'azure_datalake_analytics_catalog_and_job_endpoint': None,
'azure_datalake_store_file_system_endpoint': None,
'keyvault_dns': '.vault.usgovcloudapi.net',
'mariadb_server_endpoint': '.mariadb.database.usgovcloudapi.net',
'mhsm_dns': '.managedhsm.usgovcloudapi.net',
'mysql_server_endpoint': '.mysql.database.usgovcloudapi.net',
'postgresql_server_endpoint': '.postgres.database.usgovcloudapi.net',
'sql_server_hostname': '.database.usgovcloudapi.net',
'storage_endpoint': 'core.usgovcloudapi.net',
'storage_sync_endpoint': 'afs.azure.us',
'synapse_analytics_endpoint': '.dev.azuresynapse.usgovcloudapi.net'}}
Traceback (most recent call last):
File "test.py", line 9, in <module>
vms = list(client.virtual_machines.list_all())
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/paging.py", line 129, in __next__
return next(self._page_iterator)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/paging.py", line 76, in __next__
self._response = self._get_next(self.continuation_token)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/mgmt/compute/v2020_12_01/operations/_virtual_machines_operations.py", line 1159, in get_next
map_error(status_code=response.status_code, response=response, error_map=error_map)
File "/home/thomas.schultz/test/.venv/lib64/python3.7/site-packages/azure/core/exceptions.py", line 102, in map_error
raise error
azure.core.exceptions.ClientAuthenticationError: (InvalidAuthenticationTokenAudience) The access token has been obtained for wrong audience or resource 'https://management.azure.com'. It should exactly match with one of the allowed audiences 'https://management.core.usgovcloudapi.net/','https://management.core.usgovcloudapi.net','https://management.usgovcloudapi.net/','https://management.usgovcloudapi.net'.
Additional context Add any other context about the problem here.
| Author: | tom-schultz |
|---|---|
| Assignees: | msyyc |
| Labels: |
|
| Milestone: | - |
Thanks for the feedback, we’ll investigate asap.
Looking into the issue.
@jaylabell - Can you please look into this issue?
@tom-schultz Does it work before 17.0.0? (After 17.0.0b1, azure-mgmt-compute is track2 version. There are some difference between track1 version(lower than 17.0.0) and track2 version(lager than 17.0.0b1), which is described in CHANGELOG.md. You could also reference the guidance: https://github.com/Azure/azure-sdk-for-python/blob/master/doc/sphinx/python_mgmt_migration_guide.rst)
We are working internally to route this to the appropriate team.
Attempt in progress to fix it: https://github.com/Azure/azure-sdk-for-python/pull/18553
@lmazuel Do you have an update on this issue?
Removing Compute label on this issue because it is a generic issue with the CLI.
Hi @tom-schultz. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text “/unresolve” to remove the “issue-addressed” label and continue the conversation.
Hi @tom-schultz, since you haven’t asked that we “/unresolve” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve” to reopen the issue.