Skip to content

Fix HostUrl with container tunnel - #16684

Merged
David Negstad (danegsta) merged 2 commits into
microsoft:mainfrom
danegsta:danegsta/hosturl-container-tunnel-fix
May 5, 2026
Merged

Fix HostUrl with container tunnel#16684
David Negstad (danegsta) merged 2 commits into
microsoft:mainfrom
danegsta:danegsta/hosturl-container-tunnel-fix

Conversation

@danegsta

Copy link
Copy Markdown
Member

Description

Fixes #16641
Fixes #16642

This fixes HostUrl resolution for container resources when the Aspire container tunnel is enabled.

  • Treat HostUrl values that match an app-model host endpoint as dependencies so DCP creates the corresponding container tunnel service before the container environment is resolved.
  • Resolve matching HostUrl values through the endpoint reference's async port property instead of reading the endpoint's allocated port synchronously before tunnel allocation completes.
  • Keep unmatched host-local HostUrl values on the container host bridge instead of rewriting them to aspire.dev.internal when no tunnel service backs that port.
  • Add DCP-level regression tests for both matching and unmatched HostUrl host-port scenarios.

Validation:

  • dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-method "*.ContainerHostUrlMatchingHostEndpointUsesTunnelPort" --filter-method "*.ContainerHostUrlWithoutMatchingHostEndpointUsesContainerHostBridge" --filter-method "*.HostUrlPropertyGetsResolved" --filter-method "*.HostUrlPropertyGetsResolvedInOtlpExporterEndpoint" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.DcpExecutorTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

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
  • Does the change require an update in our Aspire docs?

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

github-actions Bot commented May 1, 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 -- 16684

Or

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

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 fixes HostUrl resolution for container resources when the Aspire container tunnel is enabled, ensuring HostUrl values that correspond to app-model host endpoints are resolved via the tunnel (including async port allocation), while unmatched host-local URLs remain on the container host bridge.

Changes:

  • Update HostUrl resolution to (a) detect localhost targets robustly, (b) resolve matching host endpoints via the tunnel using the endpoint’s async Port property, and (c) keep unmatched host-local URLs on the host bridge hostname.
  • Treat matching HostUrl values as dependencies during dependency discovery so tunnel services are created before container environment evaluation.
  • Add/adjust regression tests covering both the “matching host endpoint uses tunnel port” and “unmatched host-local port uses host bridge” scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/Aspire.Hosting.Tests/ExpressionResolverTests.cs Updates expectations for HostUrl rewriting when tunnel is enabled but no matching app-model host endpoint exists.
tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs Adds DCP regression tests for matched vs. unmatched HostUrl host-port behavior and updates test executor DI setup.
src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Extends dependency discovery to treat certain HostUrl values as resource dependencies.
src/Aspire.Hosting/ApplicationModel/HostUrl.cs Updates HostUrl resolution logic to support container tunnel port allocation and adds localhost/port parsing helper.

Comment thread src/Aspire.Hosting/ApplicationModel/HostUrl.cs Outdated
Comment thread src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@danegsta
David Negstad (danegsta) enabled auto-merge (squash) May 5, 2026 01:08
@danegsta
David Negstad (danegsta) merged commit 798d1a8 into microsoft:main May 5, 2026
2786 of 2843 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 13.4 milestone May 5, 2026
@danegsta

Copy link
Copy Markdown
Member Author

/backport to release/13.3

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/13.3 (link to workflow run)

Nell Shamrell-Harrington (nellshamrell) pushed a commit to nellshamrell/aspire that referenced this pull request May 18, 2026
* Fix HostUrl with container tunnel

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

* Scope HostUrl matching to host endpoints

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

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[13.3] HostUrl doesn't work with container tunnel. [13.3] HostUrl causes container to FailToStart with container tunnel

3 participants