Fix cross-tenant registry endpoint resolution in DeploymentTemplateOperations#46719
Open
PratibhaShrivastav18 wants to merge 1 commit intoAzure:mainfrom
Open
Fix cross-tenant registry endpoint resolution in DeploymentTemplateOperations#46719PratibhaShrivastav18 wants to merge 1 commit intoAzure:mainfrom
PratibhaShrivastav18 wants to merge 1 commit intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes cross-tenant registry endpoint resolution for DeploymentTemplateOperations by switching from an ARM-based registry lookup (which can fail with cross-tenant tokens) to the registry discovery API, and then deriving the deployment template dataplane endpoint from the discovery response.
Changes:
- Replaced ARM registry GET–based region lookup with a call to the registry discovery API.
- Constructed the deployment template dataplane endpoint based on the discovery response’s resolved primary region.
| self._operation_scope.registry_name | ||
| ) | ||
| ) | ||
|
|
Comment on lines
55
to
+84
| @@ -63,31 +69,19 @@ def _get_registry_endpoint(self) -> str: | |||
| credential = self._operation_config.credential | |||
|
|
|||
| if credential and self._operation_scope.registry_name: | |||
| # Get registry information to determine the region | |||
| registry_operations = RegistryOperations( | |||
| operation_scope=self._operation_scope, | |||
| service_client=ServiceClient102022( | |||
| credential=credential, | |||
| subscription_id=self._operation_scope.subscription_id, | |||
| resource_group_name=self._operation_scope.resource_group_name, | |||
| ), | |||
| all_operations=None, # type: ignore[arg-type] | |||
| credentials=credential, | |||
| # Use registry discovery API to get the primary region | |||
| discovery_base_url = _get_registry_discovery_endpoint_from_metadata(_get_default_cloud_name()) | |||
| discovery_client = ServiceClientRegistryDiscovery( | |||
| credential=credential, base_url=discovery_base_url | |||
| ) | |||
| response = ( | |||
| discovery_client.registry_management_non_workspace.get_registry_management_non_workspace( | |||
| self._operation_scope.registry_name | |||
| ) | |||
| ) | |||
|
|
|||
| registry = registry_operations.get(self._operation_scope.registry_name) | |||
|
|
|||
| # Extract region from registry location or replication locations | |||
| region = None | |||
| if registry.location: | |||
| region = registry.location | |||
| elif registry.replication_locations and len(registry.replication_locations) > 0: | |||
| region = registry.replication_locations[0].location | |||
|
|
|||
| if region: | |||
| # Format the endpoint using the detected region | |||
| # return f"https://int.experiments.azureml-test.net" | |||
| return f"https://{region}.api.azureml.ms" | |||
| if response.primary_region: | |||
| return f"https://{response.primary_region}.api.azureml.ms" | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
When running
az ml deployment-template list --registry-name <registry>against a registry in a different Azure AD tenant, the CLI uses the wrong API endpoint (INT/test environment) and fails with 403.Root Cause
_get_registry_endpoint()inDeploymentTemplateOperationswas making an ARM call (GET /subscriptions/.../registries/<name>) to determine the registry's region and construct the dataplane endpoint. This ARM call requires the caller's token to match the registry's tenant.Flow before fix:
https://int.experiments.azureml-test.netFix
Replace the ARM-based region lookup with the registry discovery API (
/registrymanagement/v1.0/registries/{name}/discovery).The discovery API:
primaryRegiondirectly, which is used to constructhttps://{primaryRegion}.api.azureml.msFlow after fix:
primaryRegion(e.g.eastus)https://eastus.api.azureml.msTesting
Verified with
--debugoutput showing:GET /registrymanagement/v1.0/registries/shrivastavp-reg/discovery-> 200https://eastus.api.azureml.ms/genericasset/v2.0/...-> 200