Add proxyless endpoint port allocator
Description
Proxyless endpoints without explicit public ports currently have inconsistent run-mode behavior: executable endpoints can fail validation, while container endpoints can depend on delayed allocation. This PR gives DCP a single allocation path for undefined proxyless public ports so both resource types get predictable host ports before workload creation.
The implementation adds a singleton proxyless endpoint port allocator that scans a configurable stable port range, pre-excludes fixed public ports, and tracks allocator-assigned ports to avoid duplicates. Persistent resources store dynamically assigned proxyless public ports in user secrets and reuse them on later runs; if persistence fails, Aspire logs a warning that explains how to avoid recreating the persistent resource each run. The old delayed on-demand endpoint allocation callback path is removed.
User-facing usage
Proxyless endpoints without an explicit public port now get an assigned public port during DCP service preparation:
builder.AddExecutable("worker", "worker", Environment.CurrentDirectory)
.WithEndpoint(name: "http", isProxied: false);
builder.AddContainer("database", "image")
.WithEndpoint(name: "tcp", targetPort: 5432, isProxied: false);
The default allocation range is 10000-32767. It can be overridden with:
ASPIRE_PROXYLESS_ENDPOINT_PORT_RANGE=12000-13000
Persistent resources reuse the assigned port from user secrets when available.
Breaking changes
This changes proxyless endpoint allocation timing and behavior in run mode. Code or tests that expected executable proxyless endpoints without a public port to fail, or expected container proxyless public ports to be allocated later by DCP/container startup, should update to expect Aspire to assign the public port during service preparation.
Security considerations
This change assigns host public ports for proxyless endpoints and can persist selected port numbers in user secrets for persistent resources. The allocator probes candidate ports only to determine availability, and stored user-secrets values are port numbers rather than credentials.
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
- If yes, did you have an API Review for it?
- No
- Yes
- 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
- If yes, have you done a threat model and had a security review?
- No
- Yes