Repository navigation
Support WithReference on Azure Container Registry in run mode - #22939
Mitch Denny (mitchdenny) wants to merge 5 commits into
Conversation
Referencing a registry adds it to the run model at build time so the Azure run-mode provisioner handles it, injects the login server as connection info, and defaults referencing identities to AcrPull. Unreferenced registries keep their existing run and manifest behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22939Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22939" |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Registry references with dashed names can fail App Service publish/deploy because connection-reference metadata is lost, leaving an invalid environment-variable alias. Portable aliases can also silently overwrite another resource’s connection string because collision validation is missing. Adding references also reinstates AcrPull assignments after ClearDefaultRoleAssignments(), defeating the explicit opt-out and potentially failing provisioning for developers without role-assignment permissions.
5 open issues
Retain connection-reference metadata for App Service alias projection · New Validate portable alias collisions with other connection strings · New Add live coverage for registry provisioning and authenticated access · New Preserve explicit clearing of default role assignments · New Use unprefixed environment variables for an empty connection name · New
What changed in this PR
Enables workloads to reference Azure Container Registry through WithReference, integrating referenced registries with Aspire’s existing run-mode provisioning while preserving deployment-only behavior.
Changes:
- Adds connection information injection, default AcrPull assignments, and polyglot reference dispatch.
- Documents workload references and incompatibility with
WithRunMode. - Adds model tests and snapshots for connection information and role assignments.
| File | Description |
|---|---|
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_WritesConsumerEnvironmentWithoutRegistryConnectionString.verified.json | Captures consumer and registry manifests. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_RespectsExplicitRoleAssignments_operation=Run.verified.bicep | Captures run-mode AcrPush override. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_RespectsExplicitRoleAssignments_operation=Publish.verified.bicep | Captures deployment AcrPush override. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_InjectsConnectionInformation.verified.txt | Captures injected connection information. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_GeneratesRoleAssignments_operation=Run_existing=True.verified.bicep | Covers existing-registry run-mode roles. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_GeneratesRoleAssignments_operation=Run_existing=False.verified.bicep | Covers new-registry run-mode roles. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_GeneratesRoleAssignments_operation=Publish_existing=True.verified.bicep | Covers existing-registry deployment roles. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerRegistryTests.WithReference_GeneratesRoleAssignments_operation=Publish_existing=False.verified.bicep | Covers new-registry deployment roles. |
| tests/Aspire.Hosting.Azure.Tests/AzureContainerRegistryTests.cs | Tests registration, references, roles, and incompatible configuration. |
| src/Aspire.Hosting.Azure.ContainerRegistry/README.md | Documents references and connection properties. |
| src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryResource.cs | Adds polyglot reference dispatch. |
| src/Aspire.Hosting.Azure.ContainerRegistry/AzureContainerRegistryExtensions.cs | Implements references, provisioning registration, and default roles. |
| src/Aspire.Hosting.Azure.ContainerRegistry/Aspire.Hosting.Azure.ContainerRegistry.csproj | Includes the shared environment-variable name encoder. |
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Deployment tests starting on PR #22939... This will deploy to real Azure infrastructure. Results will be posted here when complete. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Registry references with dashed names fail App Service deployment validation because they lack the metadata required for portable alias projection. Separately, referencing a registry reinstates AcrPull despite explicitly cleared or customized role defaults, causing provisioning failures for callers without role-assignment permissions. Connection-name collisions can also silently overwrite other connections in either reference order.
6 open issues
Validate portable alias collisions with other connection strings Retain connection-reference metadata for App Service alias projection Use unprefixed environment variables for an empty connection name Preserve explicit clearing of default role assignments Add live coverage for registry provisioning and authenticated access Include the deployment-test result in the PR description · New
Review effort: Balanced
Route WithReference(registry) through the standard connection string reference so the connection value carries ConnectionStringReference metadata. This lets App Service project dashed connection names to their portable alias, validates alias collisions, and uses the shared empty connection name handling. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
Consumers calling WithReference(registry, optional: false) or using a source typed as IResourceBuilder<IResourceWithConnectionString> bypass registry initialization. The registry is then absent from the run model, leaving loginServer unavailable, and publish mode loses the AcrPull defaults.
3 open issues
4 resolved since last review
Review effort: Balanced
| public static IResourceBuilder<TDestination> WithReference<TDestination>( | ||
| this IResourceBuilder<TDestination> builder, | ||
| IResourceBuilder<AzureContainerRegistryResource> source, | ||
| string? connectionName = null) |
…entity Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🔵 Needs a closer look
Registry references reinstate AcrPull after ClearDefaultRoleAssignments(), overriding the explicit opt-out and causing provisioning to fail for existing registries when the developer lacks role-assignment permissions. Separately, WithReference(registry, optional: false) selects the shared overload and bypasses registry registration, leaving the registry unprovisioned and its login server unresolved in run mode.
2 open issues
1 resolved since last review
Review effort: Balanced
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/deployment-test |



Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
cfadef8d41a714f8a58b30f05b4330fd875184a6↑ Snapshots verify referenced-resource role assignments and unchanged unreferenced registry manifests.
↑ Live run-mode E2E (
AzureContainerRegistryRunModeTests) passed in deployment run 47282206452.↓ Five Copilot review comments (portable alias metadata, alias collision validation, role re-add after clear, empty connection name) are unresolved.
Description
Allow an app workload to reference an Azure Container Registry with
WithReference. Referenced registries are added to the run-mode model at build time, enabling the existing Azure run-mode provisioner; they receive AcrPull by default for the referencing workload's identity. Registries used only as deployment infrastructure remain out of the run model and keep their existing manifest shape.User-facing usage
The consumer receives the login server as
ConnectionStrings__registry, plusREGISTRY_HOSTandREGISTRY_URI. In deploy, the consumer's identity receives AcrPull by default; local runs assign AcrPull to the development principal. UseWithRoleAssignmentson the consumer to override the role.Validation:
dotnet test --project tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"— passed (2,420 passed, 5 skipped). Live run mode: newAzureContainerRegistryRunModeTestsE2E (aspire start, waits forregistryandregistry-roles, asserts only the referenced registry exists in Azure, the consumer env vars match the login server, and AcrPull is granted to the AppHost principal) passed in deployment run 47282206452 (1 passed, 0 skipped).Security considerations
This adds a default AcrPull role assignment for the referencing workload's identity during deploy and the local development principal during run mode. The test suite verifies generated role-assignment templates; no separate threat model or security review was performed.
Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?