Skip to content

Support WithReference on Azure Container Registry in run mode - #22939

Draft
Mitch Denny (mitchdenny) wants to merge 5 commits into
mainfrom
mitchdenny-acr-run-mode-spike
Draft

Mitch Denny (mitchdenny) wants to merge 5 commits into
mainfrom
mitchdenny-acr-run-mode-spike

Conversation

@mitchdenny

@mitchdenny Mitch Denny (mitchdenny) commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: cfadef8d41a714f8a58b30f05b4330fd875184a6

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Azure hosting test project passed: 2,420 passed, 5 skipped.
↑ 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

var registry = builder.AddAzureContainerRegistry("registry");
builder.AddContainer("worker", "worker-image").WithReference(registry);

The consumer receives the login server as ConnectionStrings__registry, plus REGISTRY_HOST and REGISTRY_URI. In deploy, the consumer's identity receives AcrPull by default; local runs assign AcrPull to the development principal. Use WithRoleAssignments on 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: new AzureContainerRegistryRunModeTests E2E (aspire start, waits for registry and registry-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

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

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>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22939

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 22939"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Dec 4, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot December 4, 2026 04:09
@github-actions

This comment has been minimized.

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

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
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>
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot December 4, 2026 06:33
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployment tests starting on PR #22939...

This will deploy to real Azure infrastructure. Results will be posted here when complete.

View workflow run

@github-actions

This comment has been minimized.

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

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

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>
@github-actions

This comment has been minimized.

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

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

Comment on lines +87 to +90
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>
@github-actions

This comment has been minimized.

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.

🔵 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

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

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>
@mitchdenny

Copy link
Copy Markdown
Member Author

/deployment-test

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot December 5, 2026 09:48
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive
@github-actions
github-actions Bot temporarily deployed to deployment-testing December 5, 2026 10:04 Inactive

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants