Skip to content

[Containerapp] az containerapp up: Validate image registry before inferring credentials - #34302

Merged
mansoor sarfraz (msarfraz) merged 3 commits into
Azure:devfrom
Greedygre:fix-containerapp-image-registry
Nov 9, 2026
Merged

mansoor sarfraz (msarfraz) merged 3 commits into
Azure:devfrom
Greedygre:fix-containerapp-image-registry

Conversation

@Greedygre

@Greedygre Greedygre (Greedygre) commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

Related command

az containerapp up --image

Description

Use the existing ACR hostname helpers for image-based registry inference in az containerapp up.

  • Use the registry authority, rather than the full image reference, to identify ACR images.
  • Reuse the supported ACR suffix helpers and require an ASCII alphanumeric registry name.
  • Recognize <registry>.<region>.geo regional endpoints, using the resource name for credential lookup while preserving the complete registry authority.
  • Derive the credential lookup name from that validated authority.
  • Preserve explicit credentials and existing lookup error handling for valid ACR images.
  • Add unit coverage for non-ACR and malformed authorities, regional endpoints, supported sovereign clouds, tag and digest references, explicit and partial credentials, lookup errors, and the defaults call path.

This complements #34262 by updating the image-inference entry point, rather than duplicating its registry-details validation. The change is independently applicable to dev.

Testing Guide

From the Azure CLI repository root, using the existing Azure CLI 2.91.0 Python runtime for dependencies:

& 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' -c "import sys; sys.dont_write_bytecode=True; sys.path.insert(0, r'src\azure-cli'); import unittest; unittest.main(module=None, argv=['unittest', 'azure.cli.command_modules.containerapp.tests.latest.test_containerapp_up_image_unit', '-v'])"

Result: passed, 7 test methods and their parameterized subtests for commit 193d16323b2c6c4f78436ef895ca372907b686ef. Before the regional-endpoint correction, the expanded suite failed with 31 failing cases. Tests load the checked-out command module; resource and credential operations are mocked.

git diff --check
git diff --cached --check

Result: passed before committing.

Full repository azdev/CI suites and live Azure scenarios were not run locally for this revision. The bot-managed validation section above tracks CI separately.

History Notes

[Containerapp] az containerapp up: Validate image registry before inferring credentials


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

…erring credentials

Use the image authority and supported ACR hostname helpers for registry inference. Derive the lookup name from that validated authority and retain explicit credentials and existing lookup error handling.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🟡 Changes recommended

Automatic registry credential lookup does not enforce cloud matching, risking exposure of admin credentials to an unrelated registry and causing authentication failures.

3 open issues
What changed in this PR

This PR tightens registry credential inference for az containerapp up --image, complementing #34262’s registry-server validation.

Changes:

  • Uses the image’s registry authority and shared ACR suffix helpers instead of substring matching.
  • Adds registry-name validation before credential lookup.
  • Adds mocked tests for malformed authorities, sovereign-cloud suffixes, credentials, lookup failures, and the defaults path.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​containerapp/​tests/​latest/​test_containerapp_up_image_unit.py Adds unit coverage for image-based registry inference.
src/​azure-cli/​azure/​cli/​command_modules/​containerapp/​_up_utils.py Validates the registry authority before inferring ACR credentials.

Review effort: Balanced

@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

Greedygre (Greedygre) and others added 2 commits October 30, 2026 10:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Recognize registry.region.geo authorities before validating the ACR resource name, preserving the complete registry destination. Cover regional tag and digest references, partial credentials, supported cloud suffixes, defaults inference, and malformed or non-ASCII authorities.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

@Tratcher Chris Ross (Tratcher) 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.

Duplicate of #34262?

@Greedygre

Copy link
Copy Markdown
Contributor Author

This complements #34262 by updating the image-inference entry point, rather than duplicating its registry-details validation.

Thanks for checking. These are related, but they cover different credential-inference paths.

[Azure/azure-cli#34262](#34262) adds validation in _get_registry_details(). This PR adds validation in _get_acr_from_image(), which is called by _set_up_defaults() for image-based deployments. In the [image-only flow](

# Check and see if registry username and passwords are specified. If so, set is_registry_server_params_set to True to use those creds.
is_registry_server_params_set = bool(registry_server and registry_user and registry_pass)
_set_up_defaults(cmd, name, resource_group_name, logs_customer_id, location, resource_group, env, app, is_registry_server_params_set)
if app.check_exists():
if app.get()["properties"]["provisioningState"] == "InProgress":
raise ValidationError("Containerapp has an existing provisioning in progress. Please wait until provisioning has completed and rerun the command.")
resource_group.create_if_needed()
env.create_if_needed(name)
if source or repo:
if not registry_server:
_get_registry_from_app(app, source) # if the app exists, get the registry
), _get_registry_details() is not called—it is only invoked when source or repo is supplied—so the validation in the other PR does not cover this entry point.

The intent is to complement [Azure/azure-cli#34262](#34262). The added tests exercise the image-inference path, including the defaults call path and valid regional ACR endpoints.

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

@msarfraz
mansoor sarfraz (msarfraz) merged commit 4bc1cb2 into Azure:dev Nov 9, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants