Skip to content
Open
37 changes: 18 additions & 19 deletions src/azure-cli/azure/cli/command_modules/acr/check_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,24 @@ def _check_registry_health(cmd, registry_name, repository, ignore_errors):
registry and registry.role_assignment_mode == RoleAssignmentMode.ABAC_REPOSITORY_PERMISSIONS
_get_endpoint_and_token_status(cmd, login_server, registry_abac_enabled, repository, ignore_errors)

if cmd.supported_api_version(min_api='2020-11-01-preview', resource_type=ResourceType.MGMT_CONTAINERREGISTRY): # pylint: disable=too-many-nested-blocks
# CMK settings
if registry and registry.encryption and registry.encryption.key_vault_properties: # pylint: disable=too-many-nested-blocks
client_id = registry.encryption.key_vault_properties.identity
valid_identity = False
if registry.identity:
valid_identity = ((client_id == 'system') and
bool(registry.identity.principal_id)) # use system identity?
if not valid_identity and registry.identity.user_assigned_identities:
for k, v in registry.identity.user_assigned_identities.items():
if v.client_id == client_id:
from azure.core.exceptions import HttpResponseError
try:
valid_identity = resolve_identity_client_id(cmd.cli_ctx, k) == client_id
except HttpResponseError:
pass
if not valid_identity:
from ._errors import CMK_MANAGED_IDENTITY_ERROR
_handle_error(CMK_MANAGED_IDENTITY_ERROR.format_error_message(registry_name), ignore_errors)
# CMK settings
if registry and registry.encryption and registry.encryption.key_vault_properties: # pylint: disable=too-many-nested-blocks
Comment on lines +352 to +353
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change also makes from azure.cli.core.profiles import ResourceType (near the top of _check_registry_health) unused, since ResourceType was only referenced by the removed cmd.supported_api_version(...) call. Please remove that import (or reintroduce the version check) to avoid unused-import lint failures.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

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

client_id = registry.encryption.key_vault_properties.identity
Comment on lines +353 to +354
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the cmd.supported_api_version(... MGMT_CONTAINERREGISTRY ...) guard changes runtime behavior and can cause an AttributeError on clouds/profiles using older Container Registry API versions where the returned Registry model may not have an encryption attribute. Please either restore the API-version gate (as before) or switch these accesses to getattr(registry, 'encryption', None) / getattr(..., 'key_vault_properties', None) so az acr check-health remains compatible across profiles.

Suggested change
if registry and registry.encryption and registry.encryption.key_vault_properties: # pylint: disable=too-many-nested-blocks
client_id = registry.encryption.key_vault_properties.identity
encryption = getattr(registry, 'encryption', None) if registry else None
key_vault_properties = getattr(encryption, 'key_vault_properties', None)
if key_vault_properties: # pylint: disable=too-many-nested-blocks
client_id = key_vault_properties.identity

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by #33117

valid_identity = False
if registry.identity:
valid_identity = ((client_id == 'system') and
bool(registry.identity.principal_id)) # use system identity?
if not valid_identity and registry.identity.user_assigned_identities:
for k, v in registry.identity.user_assigned_identities.items():
if v.client_id == client_id:
from azure.core.exceptions import HttpResponseError
try:
valid_identity = resolve_identity_client_id(cmd.cli_ctx, k) == client_id
except HttpResponseError:
pass
if not valid_identity:
from ._errors import CMK_MANAGED_IDENTITY_ERROR
_handle_error(CMK_MANAGED_IDENTITY_ERROR.format_error_message(registry_name), ignore_errors)
Comment on lines +352 to +369
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title/description focus on ACR test refactoring, but this hunk changes production behavior in acr/check_health.py (CMK validation now runs unconditionally and the API-version gate is removed). Please update the PR description to explicitly call out this functional change (or move it into a separate PR) so reviewers can assess the runtime impact appropriately.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That modification should be addressed by #33117



def _check_private_endpoint(cmd, registry_name, vnet_of_private_endpoint): # pylint: disable=too-many-locals, too-many-statements
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interactions:
ParameterSetName:
- -n -l
User-Agent:
- AZURECLI/2.84.0 azsdk-python-core/1.38.0 Python/3.12.3 (Linux-6.17.0-1008-azure-x86_64-with-glibc2.39)
- AZURECLI/2.85.0 azsdk-python-core/1.39.0 Python/3.12.3 (Linux-6.17.0-1010-azure-x86_64-with-glibc2.39)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/randomresourcegroupname?api-version=2024-11-01
response:
Expand All @@ -31,7 +31,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 24 Mar 2026 01:23:54 GMT
- Wed, 01 Apr 2026 23:18:47 GMT
expires:
- '-1'
pragma:
Expand All @@ -47,7 +47,7 @@ interactions:
x-ms-ratelimit-remaining-subscription-writes:
- '799'
x-msedge-ref:
- 'Ref A: A0026F57F38A4176A67C16EEDAE9D05E Ref B: BY1AA1072318040 Ref C: 2026-03-24T01:23:54Z'
- 'Ref A: A5F40DFAD3854D7FBD03635781C58ECE Ref B: SJC211051205039 Ref C: 2026-04-01T23:18:46Z'
status:
code: 200
message: OK
Expand All @@ -70,12 +70,12 @@ interactions:
ParameterSetName:
- -n -g -l --sku --dnl-scope
User-Agent:
- AZURECLI/2.84.0 azsdk-python-core/1.38.0 Python/3.12.3 (Linux-6.17.0-1008-azure-x86_64-with-glibc2.39)
- AZURECLI/2.85.0 azsdk-python-core/1.39.0 Python/3.12.3 (Linux-6.17.0-1010-azure-x86_64-with-glibc2.39)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.ContainerRegistry/registries/clireg000002?api-version=2026-01-01-preview
response:
body:
string: '{"sku":{"name":"Premium","tier":"Premium"},"type":"Microsoft.ContainerRegistry/registries","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.ContainerRegistry/registries/clireg000002","name":"clireg000002","location":"westus","tags":{},"systemData":{"createdBy":"test@example.com","createdByType":"User","createdAt":"2026-03-24T01:23:55.1847073+00:00","lastModifiedBy":"test@example.com","lastModifiedByType":"User","lastModifiedAt":"2026-03-24T01:23:55.1847073+00:00"},"properties":{"loginServer":"clireg000002-awgjg5g6hdg2h7h5.azurecr.io","creationDate":"2026-03-24T01:23:55.1847073Z","provisioningState":"Succeeded","adminUserEnabled":false,"networkRuleSet":{"defaultAction":"Allow","ipRules":[]},"policies":{"quarantinePolicy":{"status":"disabled"},"trustPolicy":{"type":"Notary","status":"disabled"},"retentionPolicy":{"days":7,"lastUpdatedTime":"2026-03-24T01:24:12.1575165+00:00","status":"disabled"},"exportPolicy":{"status":"enabled"},"azureADAuthenticationAsArmPolicy":{"status":"enabled"},"softDeletePolicy":{"retentionDays":7,"lastUpdatedTime":"2026-03-24T01:24:12.1575871+00:00","status":"disabled"}},"encryption":{"status":"disabled"},"dataEndpointEnabled":false,"regionalEndpoints":"Disabled","dataEndpointHostNames":[],"regionalEndpointHostNames":[],"endpointProtocol":"IPv4","privateEndpointConnections":[],"publicNetworkAccess":"Enabled","networkRuleBypassOptions":"AzureServices","networkRuleBypassAllowedForTasks":false,"zoneRedundancy":"Disabled","anonymousPullEnabled":false,"metadataSearch":"Disabled","roleAssignmentMode":"LegacyRegistryPermissions","autoGeneratedDomainNameLabelScope":"ResourceGroupReuse"}}'
string: '{"sku":{"name":"Premium","tier":"Premium"},"type":"Microsoft.ContainerRegistry/registries","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.ContainerRegistry/registries/clireg000002","name":"clireg000002","location":"westus","tags":{},"systemData":{"createdBy":"test@example.com","createdByType":"User","createdAt":"2026-04-01T23:18:47.9382667+00:00","lastModifiedBy":"test@example.com","lastModifiedByType":"User","lastModifiedAt":"2026-04-01T23:18:47.9382667+00:00"},"properties":{"loginServer":"clireg000002-cad2deadbab9caa8.azurecr.io","creationDate":"2026-04-01T23:18:47.9382667Z","provisioningState":"Succeeded","adminUserEnabled":false,"networkRuleSet":{"defaultAction":"Allow","ipRules":[]},"policies":{"quarantinePolicy":{"status":"disabled"},"trustPolicy":{"type":"Notary","status":"disabled"},"retentionPolicy":{"days":7,"lastUpdatedTime":"2026-04-01T23:18:55.0352572+00:00","status":"disabled"},"exportPolicy":{"status":"enabled"},"azureADAuthenticationAsArmPolicy":{"status":"enabled"},"softDeletePolicy":{"retentionDays":7,"lastUpdatedTime":"2026-04-01T23:18:55.0353253+00:00","status":"disabled"}},"encryption":{"status":"disabled"},"dataEndpointEnabled":false,"regionalEndpoints":"Disabled","dataEndpointHostNames":[],"regionalEndpointHostNames":[],"endpointProtocol":"IPv4","privateEndpointConnections":[],"publicNetworkAccess":"Enabled","networkRuleBypassOptions":"AzureServices","networkRuleBypassAllowedForTasks":false,"zoneRedundancy":"Disabled","anonymousPullEnabled":false,"metadataSearch":"Disabled","roleAssignmentMode":"LegacyRegistryPermissions","autoGeneratedDomainNameLabelScope":"ResourceGroupReuse"}}'
headers:
api-supported-versions:
- 2026-01-01-preview
Expand All @@ -86,7 +86,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 24 Mar 2026 01:24:11 GMT
- Wed, 01 Apr 2026 23:18:54 GMT
expires:
- '-1'
pragma:
Expand All @@ -98,13 +98,13 @@ interactions:
x-content-type-options:
- nosniff
x-ms-operation-identifier:
- tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47,objectId=68abb7a6-9056-4d60-bf87-3b50a45559cd/westus/193136e3-e374-4c1a-953c-013750a19df1
- tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47,objectId=68abb7a6-9056-4d60-bf87-3b50a45559cd/westus2/386d5de8-dc7b-4411-89a5-0ebd8cc4aa0a
x-ms-ratelimit-remaining-subscription-global-writes:
- '12000'
x-ms-ratelimit-remaining-subscription-writes:
- '800'
x-msedge-ref:
- 'Ref A: 1CEFEFBC72FD42EC99E2CA5A2C694BA1 Ref B: BY1AA1072317034 Ref C: 2026-03-24T01:23:54Z'
- 'Ref A: 5689C184BBBA4D1EBDD6A67C602F09C1 Ref B: BY1AA1072318031 Ref C: 2026-04-01T23:18:47Z'
status:
code: 200
message: OK
Expand All @@ -127,7 +127,7 @@ interactions:
ParameterSetName:
- -n -g -l --sku --dnl-scope
User-Agent:
- AZURECLI/2.84.0 azsdk-python-core/1.38.0 Python/3.12.3 (Linux-6.17.0-1008-azure-x86_64-with-glibc2.39)
- AZURECLI/2.85.0 azsdk-python-core/1.39.0 Python/3.12.3 (Linux-6.17.0-1010-azure-x86_64-with-glibc2.39)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/randomresourcegroupname/providers/Microsoft.ContainerRegistry/registries/clireg000002?api-version=2026-01-01-preview
response:
Expand All @@ -145,7 +145,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 24 Mar 2026 01:24:12 GMT
- Wed, 01 Apr 2026 23:18:56 GMT
expires:
- '-1'
pragma:
Expand All @@ -157,13 +157,13 @@ interactions:
x-content-type-options:
- nosniff
x-ms-operation-identifier:
- tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47,objectId=68abb7a6-9056-4d60-bf87-3b50a45559cd/westus/58902548-ffe6-41ad-8442-99339ce12a12
- tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47,objectId=68abb7a6-9056-4d60-bf87-3b50a45559cd/westus/a4f53797-ee69-4879-9018-dab45046d93d
x-ms-ratelimit-remaining-subscription-global-writes:
- '11999'
x-ms-ratelimit-remaining-subscription-writes:
- '799'
x-msedge-ref:
- 'Ref A: FC06032182E44611B62577ED61915CA7 Ref B: BY1AA1072319060 Ref C: 2026-03-24T01:24:12Z'
- 'Ref A: 4CF7BB98CCF440B1AAEADCE9BB1FD954 Ref B: BY1AA1072317052 Ref C: 2026-04-01T23:18:55Z'
status:
code: 409
message: Conflict
Expand Down
Loading
Loading