Repository navigation
[ACR] az acr: Validate the WWW-Authenticate realm before sending credentials to the registry token endpoint - #34301
Conversation
|
Thank you for your contribution Jasmine Tang (@jasminetMSFT)! We will review the pull request and get back to you soon. |
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
🟡 Changes recommended
The untrusted-realm rejection is caught as a CLIError, allowing login to proceed with admin credentials instead of stopping.
1 open issue
What changed in this PR
This PR hardens ACR authentication by validating challenge realms and deriving token endpoints from the registry login server.
Changes:
- Require HTTPS realms matching the login server, allowing case differences and the default port.
- Build token URLs from the login server and report untrusted realms in health checks.
- Add tests for realm validation, credential flows, and diagnostics.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/acr/tests/latest/test_acr_commands_mock.py |
Adds realm validation and authentication regression tests. |
src/azure-cli/azure/cli/command_modules/acr/check_health.py |
Handles untrusted-realm diagnostics. |
src/azure-cli/azure/cli/command_modules/acr/_errors.py |
Defines the untrusted token endpoint error. |
src/azure-cli/azure/cli/command_modules/acr/_docker_utils.py |
Validates realms and constructs registry-local token URLs. |
Review effort: Balanced
…edentials to the registry token endpoint Only follow a realm that uses HTTPS and whose host matches the registry login server, and build the /oauth2/exchange and /oauth2/token URLs from the login server. Otherwise fail with CONNECTIVITY_UNTRUSTED_REALM_ERROR before any credential is requested or sent. `az acr check-health` reports the new error.
af53a43 to
d63da94
Compare
Zoey Li (lizMSFT)
left a comment
There was a problem hiding this comment.
Could you validate that this change preserves login behavior for DNL registries, regional endpoints (--endpoint), Private Link, and the fallback path when ARM lookup is unavailable (including --suffix where applicable)? Please cover both successful logins and expected failures, including rejection of untrusted realms.
Also could you document the scenarios tested, commands used, and results in the PR description, and note any scenarios that couldn’t be validated. Please redact credentials or tokens from the output
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
|
The fix is sound: the realm is now validated, token URLs are built from the login server, and the admin-fallback leak Copilot raised is closed (d63da94). Two follow-ups before merge:
|
mansoor sarfraz (msarfraz)
left a comment
There was a problem hiding this comment.
Jasmine Tang (@jasminetMSFT) please resolve the followup questions so it can be merged
|
Hi Zoey Li (@lizMSFT) mansoor sarfraz (@msarfraz), thanks for the review. I updated the Testing Guide in the PR description with the commands and results. I tested all the scenarios in your lists:
The Docker, Private Link and Redacted output: Could you help take another look if everything looks good? |
|
Jasmine Tang (@jasminetMSFT) Have you verified that this change addresses the scenario described in MSRC case? |
Yes Zoey Li (@lizMSFT) , I verified it end to end with the CLI and a local test registry, through the AAD, username/password and admin fallback paths. With this change, the CLI stops with CONNECTIVITY_UNTRUSTED_REALM_ERROR and doesn't send any credentials. I added the details to the case. |
|
Zoey Li (@lizMSFT) Please let us know if you have any questions that need to be addressed before merging this PR? |

🤖 PR Validation — ️✔️ All clear
Related command
az acr login,az acr check-health, and otheraz acrcommands that get a registry token (for exampleaz acr repository,az acr manifest)Description
Harden the ACR token flow so registry credentials are only sent to the registry login server over HTTPS:
realmin the registry'sWWW-Authenticatechallenge before requesting a token. It must use HTTPS and match the registry login server (case-insensitive, default port 443 ignored). Otherwise, getting the token fails with the newCONNECTIVITY_UNTRUSTED_REALM_ERRORbefore an AAD token is requested or any credential is posted./oauth2/exchangeand/oauth2/tokenURLs from the login server instead of the challenge realm.az acr check-healthreports the new error.No behavior change for Azure Container Registry, whose challenge realm is always
https://<login-server>/oauth2/token.Testing Guide
The new tests in
test_acr_commands_mock.pycover accepted and rejected realms. They check that no AAD token is requested and nothing is posted for an untrusted realm, that an untrusted realm doesn't fall back to admin or prompted credentials, and that token URLs are built from the login server.<name>-<hash>.azurecr.io). All passed, and every token request went tohttps://<login-server>/oauth2/*:az acr repository listgave the same results:Untrusted realm: a local fake registry returned an
httprealm or a realm on another host. Both the AAD and the username/password paths failed withCONNECTIVITY_UNTRUSTED_REALM_ERROR, and no credentials were sent.Docker login,
--endpointand Private Link, from a Linux VM with Docker in the private endpoint's virtual network.<registry>has regional endpoints enabled. Each command ran on Azure CLI 2.92.0 first and then with this change, with the same results:History Notes
[ACR]
az acr: Validate the token endpoint before sending credentialsThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.