-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[ACR] Support Custom ACR Scope for Disconnected Clouds (ALDO) #33294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,13 @@ | |
| get_access_credentials, | ||
| get_authorization_header, | ||
| get_manifest_authorization_header, | ||
| _resolve_acr_scope, | ||
| RepoAccessTokenPermission, | ||
| HelmAccessTokenPermission, | ||
| EMPTY_GUID | ||
| ) | ||
| from azure.cli.command_modules.acr._docker_utils import ResourceNotFound | ||
| from azure.cli.command_modules.acr._constants import ACR_AUDIENCE_RESOURCE_NAME | ||
| from azure.cli.core.mock import DummyCli | ||
|
|
||
|
|
||
|
|
@@ -1446,3 +1448,43 @@ def _setup_cmd(self): | |
| mock_sku.premium.value = 'Premium' | ||
| cmd.get_models.return_value = mock_sku | ||
| return cmd | ||
|
|
||
|
|
||
| class ResolveAcrScopeTests(unittest.TestCase): | ||
| """Unit tests for _docker_utils._resolve_acr_scope. | ||
|
|
||
| The helper resolves the AAD audience used for ACR's /oauth2/exchange call. | ||
| Operators can override the default via ``az config set acr.audience_resource=<value>``. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def _ctx(configured): | ||
| cli_ctx = mock.MagicMock() | ||
| cli_ctx.config.get.return_value = configured | ||
| return cli_ctx | ||
|
|
||
| def test_default_when_unset(self): | ||
| self.assertEqual( | ||
| _resolve_acr_scope(self._ctx(None)), | ||
| "https://{}.azure.net".format(ACR_AUDIENCE_RESOURCE_NAME), | ||
| ) | ||
|
|
||
| def test_short_name_is_expanded(self): | ||
| self.assertEqual( | ||
| _resolve_acr_scope(self._ctx("containerregistry")), | ||
| "https://containerregistry.azure.net", | ||
| ) | ||
|
|
||
| def test_full_url_is_used_verbatim(self): | ||
| self.assertEqual( | ||
| _resolve_acr_scope(self._ctx("https://customregistry.example.com")), | ||
| "https://customregistry.example.com", | ||
| ) | ||
|
|
||
| def test_config_exception_falls_back_to_default(self): | ||
| cli_ctx = mock.MagicMock() | ||
| cli_ctx.config.get.side_effect = RuntimeError("no config") | ||
| self.assertEqual( | ||
| _resolve_acr_scope(cli_ctx), | ||
| "https://{}.azure.net".format(ACR_AUDIENCE_RESOURCE_NAME), | ||
| ) | ||
|
Comment on lines
+1472
to
+1490
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config parsing here treats any override that doesn’t start with
https://as a short name and appends.azure.net. This will produce an invalid audience for common inputs likecontainerregistry.azure.net(no scheme) or non-HTTPS schemes likehttp://.../api://...(it becomeshttps://http://....azure.net). Consider detecting “already a URL/host” more robustly (e.g., if it contains://use verbatim; else if it contains a dot treat it as a host and just prefixhttps://; else treat it as a short name and append.azure.net).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback