azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

ComputeManagementClient no longer picks up proper AzureUSGovernment endpoints from CLI creds.

Open tom-schultz opened this issue 5 years ago • 11 comments

  • 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:

  1. python3 -m venv .venv
  2. source .venv/bin/activate
  3. pip install azure-mgmt-compute==20.0.0 azure-common==1.1.27 azure-cli-core==2.22.0
  4. Update test.py with your subscription ID
  5. az cloud set --name AzureUSGovernment
  6. az login
  7. python 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.

tom-schultz avatar Apr 14 '21 22:04 tom-schultz

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:

  1. python3 -m venv .venv
  2. source .venv/bin/activate
  3. pip install azure-mgmt-compute==20.0.0 azure-common==1.1.27 azure-cli-core==2.22.0
  4. Update test.py with your subscription ID
  5. az cloud set --name AzureUSGovernment
  6. az login
  7. python 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:

Compute, Mgmt, Service Attention, bug, customer-reported, needs-triage, question

Milestone: -

ghost avatar Apr 15 '21 22:04 ghost

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Apr 15 '21 22:04 xiangyan99

Looking into the issue.

amjads1 avatar Apr 16 '21 17:04 amjads1

@jaylabell - Can you please look into this issue?

amjads1 avatar Apr 19 '21 21:04 amjads1

@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)

msyyc avatar May 06 '21 07:05 msyyc

We are working internally to route this to the appropriate team.

jaylabell avatar May 06 '21 18:05 jaylabell

Attempt in progress to fix it: https://github.com/Azure/azure-sdk-for-python/pull/18553

lmazuel avatar May 06 '21 23:05 lmazuel

@lmazuel Do you have an update on this issue?

jaylabell avatar Aug 05 '21 17:08 jaylabell

Removing Compute label on this issue because it is a generic issue with the CLI.

Drewm3 avatar Nov 04 '21 19:11 Drewm3

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.

ghost avatar Dec 15 '21 08:12 ghost

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.

ghost avatar Dec 22 '21 10:12 ghost