dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.58k stars 394 forks source link

WithLaunchProfile and 0.0.0.0 binding #3146

Open cliedeman opened 5 months ago

cliedeman commented 5 months ago

I am testing a setup where I need a service to be exposed outside of localhost on other network interfaces.

launchSettings.json

{
    "profiles": {
        "http": {
            "commandName": "Project",
            "dotnetRunMessages": true,
            "launchBrowser": true,
            "applicationUrl": "http://0.0.0.0:5033",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        ...
    }
}

AppHost/Program.cs

var exposed = builder.AddProject<Project1>("project1")
  .WithLaunchProfile("http");

If I launch the app directly (without aspire) I can access it on non localhost ips but when launching with App host I can't access Project1 exception on localhost.

mitchdenny commented 4 months ago

You could use the DevTunnels feature in VS?

clarkezone commented 1 month ago

I'm also hitting this issue. My linux box is joined to my tailscale tailnet, I want all the services to bind to 0.0.0.0 not localhost or 127.0.0.1 to permit correct routing over the talent. This works fine in a non-aspire .NET Core webapp by editing the http launch scheme replacing localhost with 0.0.0.0. In an empty aspire app with just the AppHost and ServiceDefaults projects, doing this for AppHost's launch profile:

"http": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "applicationUrl": "http://0.0.0.0:15061", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", "DOTNET_ENVIRONMENT": "Development", "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://0.0.0.0:19281", "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://0.0.0.0:20198" } }

results in:

dotnetaspire dotnet run -lp http --project dotnetaspire.AppHost/dotnetaspire.AppHost.csproj

Building... Unhandled exception. System.AggregateException: One or more errors occurred. (DOTNET_RESOURCE_SERVICE_ENDPOINT_U RL must contain a local loopback address.) ---> System.ArgumentException: DOTNET_RESOURCE_SERVICE_ENDPOINT_URL must contain a local loopback address. at Aspire.Hosting.Dashboard.DashboardServiceHost.<>c__DisplayClass4_0.<.ctor>g_ConfigureKestrel|0(KestrelSer verOptions kestrelOptions) in //src/Aspire.Hosting/Dashboard/DashboardServiceHost.cs:line 158 at Microsoft.Extensions.Options.OptionsFactory1.Create(String name) at Microsoft.Extensions.Options.UnnamedOptionsManager1.get_Value() at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.CreateServiceContext(IOptions1 options, ILogge rFactory loggerFactory, DiagnosticSource diagnosticSource, KestrelMetrics metrics) at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl..ctor(IOptions1 options, IEnumerable1 transpo rtFactories, IEnumerable1 multiplexedFactories, IHttpsConfigurationService httpsConfigurationService, ILoggerFa ctory loggerFactory, KestrelMetrics metrics) at System.RuntimeMethodHandle.InvokeMethod(Object target, Void* arguments, Signature sig, Boolean isConstruc tor) at System.Reflection.MethodBaseInvoker.InvokeWithManyArgs(Object obj, BindingFlags invokeAttr, Binder binder, [aspire] 0:[tmux]

which is a showstopper for my use case.

mitchdenny commented 1 month ago

We are currently trying to figure out how Aspire interacts with these various tunneling and VPN services. You can see some experimentation that I've done here around DevTunnels (#4771).

You could potentially take a similar approach by using the Tailscale CLI to spin up a reverse proxy to expose the .NET project to your tailnet.

cliedeman commented 1 month ago

@mitchdenny dev tunnels should probably get its own ticket. In my case it was a physical device connected to my laptop that I was testing with. So the tunnel based solutions don't apply

Ciaran

mitchdenny commented 1 month ago

There already is ;)

clarkezone commented 1 month ago

@glennc fyi as we were discussing recently