Skip to content

[ACR] az acr cache create/update: Add --identity parameter to support using user-assigned managed identity for cache rules - #33040

Merged
Julie Zhu (yanzhudd) merged 6 commits into
Azure:devfrom
AntonioVT:acr-to-acr-managed-identity
Mar 27, 2026
Merged

Julie Zhu (yanzhudd) merged 6 commits into
Azure:devfrom
AntonioVT:acr-to-acr-managed-identity

Conversation

@AntonioVT

@AntonioVT Tony Vargas (AntonioVT) commented Mar 24, 2026

Copy link
Copy Markdown
Member

Related command
az acr cache create
az acr cache update

Description
This PR adds managed identity support for Azure Container Registry cache rules as an alternative authentication method to credential sets. Users can now authenticate cache rules with upstream registries using user-assigned managed identities instead of storing credentials in Azure Key Vault.

Changes made

  • Added --identity parameter to az acr cache create and az acr cache update commands
  • Implemented parameter validation for ARM resource ID format
  • Added test coverage for managed identity scenarios
  • Updated help text and parameter descriptions

Testing Guide

Prerequisites: Create two ACR registries (source and target)
az acr create -n sourceregistry -g myResourceGroup --sku Standard -l eastus
az acr create -n targetregistry -g myResourceGroup --sku Standard -l eastus

Import a test image to the source registry
az acr import -n sourceregistry --source mcr.microsoft.com/dotnet/runtime-deps:8.0

Create a user-assigned managed identity
az identity create -n cache-identity -g myResourceGroup -l eastus

Get the identity resource ID
IDENTITY_ID=$(az identity show -n cache-identity -g myResourceGroup --query id -o tsv)

Create cache rule with managed identity
az acr cache create -r targetregistry -n dotnet-cache -s sourceregistry.azurecr.io/dotnet/runtime-deps -t dotnet-runtime-deps --identity $IDENTITY_ID

Update cache rule to use different managed identity
az identity create -n cache-identity2 -g myResourceGroup -l eastus
IDENTITY_ID2=$(az identity show -n cache-identity2 -g myResourceGroup --query id -o tsv)

az acr cache update -r targetregistry -n dotnet-cache --identity $IDENTITY_ID2


This checklist is used to make sure that common guidelines for a pull request are followed.

@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi Tony Vargas (@AntonioVT),
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Mar 24, 2026

Copy link
Copy Markdown
️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Mar 24, 2026

Copy link
Copy Markdown
⚠️AzureCLI-BreakingChangeTest
⚠️acr
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd acr cache create cmd acr cache create added parameter identity
⚠️ 1006 - ParaAdd acr cache update cmd acr cache update added parameter identity

@yonzhan

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions

Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@AntonioVT

Tony Vargas (AntonioVT) commented Mar 24, 2026

Copy link
Copy Markdown
Member Author

Need to wait for #33017 getting merged, rebase and update.
#33017 has been merged

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds user-assigned managed identity support to az acr cache create / az acr cache update so cache rules can authenticate to upstream registries without credential sets, and updates the ACR SDK/API version and tests to support the new capability.

Changes:

  • Add --identity support for ACR cache rule create/update and wire it into request models.
  • Introduce validation for user-assigned identity ARM IDs and add live test + recording coverage.
  • Bump azure-mgmt-containerregistry and move ACR cache rules to 2026-01-01-preview API version (including profile updates).

Reviewed changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/azure-cli/setup.py Bumps azure-mgmt-containerregistry version to support new cache rule identity fields.
src/azure-cli/azure/cli/command_modules/acr/cache.py Adds identity support to cache create/update request payloads via SDK models.
src/azure-cli/azure/cli/command_modules/acr/_validators.py Adds validation for cache credential option combinations and identity ARM ID format.
src/azure-cli/azure/cli/command_modules/acr/_params.py Exposes --identity and hooks validation into argument parsing.
src/azure-cli/azure/cli/command_modules/acr/_constants.py Adds a template used to display identity ARM ID format examples.
src/azure-cli/azure/cli/command_modules/acr/_client_factory.py Switches cache rules client to 2026-01-01-preview.
src/azure-cli-core/azure/cli/core/profiles/_shared.py Updates ACR cache rules default API version and adjusts API version resolution behavior.
src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands.py Adds a managed identity live test for cache rules.
src/azure-cli/azure/cli/command_modules/acr/tests/latest/recordings/test_acr_cache_managed_identity.yaml Adds the recording for the new managed identity scenario test.
src/azure-cli/HISTORY.rst Documents the new --identity parameter in release history.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/azure-cli/setup.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/_params.py
Comment thread src/azure-cli/azure/cli/command_modules/acr/cache.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/cache.py Outdated
Comment thread src/azure-cli-core/azure/cli/core/profiles/_shared.py Outdated
Comment thread src/azure-cli/azure/cli/command_modules/acr/_constants.py Outdated
@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

Tony Vargas (AntonioVT) and others added 5 commits March 26, 2026 16:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Fix trailing whitespace in cache.py and _validators.py
- Break long lines to stay under 120 char limit
- Add pylint disable for unused-argument on acr_cache_update_get
- Add re.IGNORECASE flag to identity resource ID regex match

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AntonioVT
Tony Vargas (AntonioVT) force-pushed the acr-to-acr-managed-identity branch from 882071d to c192891 Compare March 26, 2026 23:45
@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@northtyphoon Bin Du (northtyphoon) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread src/azure-cli/HISTORY.rst Outdated
@yanzhudd Julie Zhu (yanzhudd) changed the title {ACR} Add managed identity support to cache rule create/update commands [ACR] az acr cache create/update: Add --identity parameter to support using user-assigned managed identity for cache rules Mar 27, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yanzhudd

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@yanzhudd
Julie Zhu (yanzhudd) merged commit d6e3aba into Azure:dev Mar 27, 2026
49 checks passed
khang-11 pushed a commit to khang-11/azure-cli that referenced this pull request Apr 30, 2026
…port using user-assigned managed identity for cache rules (Azure#33040)
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

🔔 Routing this PR to @act-observability-squad.

nihalvar added a commit to nihalvar/azure-cli that referenced this pull request Jun 4, 2026
PR Azure#33060 added @live_only() to skip this test in replay mode after the SDK split in PR Azure#33017 (azure-mgmt-containerregistry 15.1.0b1) converted RegistriesOperations.update into an async LRO (begin_update). The caller in connected_registry.py kept using the returned poller as a finished result, so the cassette stopped matching real traffic.

PR Azure#33040 already shipped the real fix on dev: it wraps acr_update_set in LongRunningOperation(cmd.cli_ctx)(...) and refreshes the cassette with the LRO polling interactions. The test passes in replay mode against current dev (verified locally, ~14s).

This change drops the now-unnecessary @live_only() decorator and its unused import.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants