Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the apphost from running if the application url is http and ASPIRE_ALLOW_UNSECURED_TRANSPORT is not set #3177

Merged
merged 41 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f59b339
Minimal change to kick start the branch.
mitchdenny Mar 26, 2024
9700e04
WIP.
mitchdenny Mar 26, 2024
eb14d59
WIP
mitchdenny Mar 26, 2024
9024c6c
Remove unnecessary change.
mitchdenny Mar 26, 2024
a2c8928
Change mins to zero to increase entropy.
mitchdenny Mar 26, 2024
6729211
Make token properties read-only.
mitchdenny Mar 26, 2024
8fb7574
WIP
mitchdenny Mar 26, 2024
6eb42d2
Improved error message.
mitchdenny Mar 26, 2024
02e9ad9
Improve exception.
mitchdenny Mar 26, 2024
a5ee58f
Tweak exception message.
mitchdenny Mar 26, 2024
8dcdf0c
Return validation result instead of throwing.
mitchdenny Mar 26, 2024
4a2c658
Add defaults to password gen, and add #if def for ToHexStringLower
mitchdenny Mar 27, 2024
f827070
Add flag to allow setting on ASPIRE_ALLOW_UNSECURED_TRANSPORT for tes…
mitchdenny Mar 27, 2024
3bc8cd1
Getting tests passing.
mitchdenny Mar 27, 2024
415fb6d
Fix test cases.
mitchdenny Mar 27, 2024
93e053f
Update src/Aspire.Hosting/Dashboard/DashboardTokenProvider.cs
mitchdenny Mar 27, 2024
d7e6286
PR feedback.
mitchdenny Mar 27, 2024
17afc6d
PR feedback.
mitchdenny Mar 27, 2024
edbd7b2
Bikeshedding on arguments to PasswordGenerator :)
mitchdenny Mar 27, 2024
e462fc4
Merge branch 'main' into mitchdenny/dashboard-auth-basic-plumbing
mitchdenny Mar 27, 2024
7f115c0
Move transport check after guard clause.
mitchdenny Mar 27, 2024
93c8896
Merge branch 'mitchdenny/dashboard-auth-basic-plumbing' of https://gi…
mitchdenny Mar 27, 2024
392b652
KnownEnvironmentVaraibles to KnownConfigNames
mitchdenny Mar 27, 2024
341c1e0
Reword failure message.
mitchdenny Mar 27, 2024
0b62088
Add some test cases.
mitchdenny Mar 27, 2024
c63b4fd
Use ValidateOnstart
mitchdenny Mar 27, 2024
d298d85
Remove random file.
mitchdenny Mar 27, 2024
da1ff6b
We don't need the dummy call inside DashboardServiceHost.
mitchdenny Mar 27, 2024
54e5dad
bool? -> bool with some extra test coverage.
mitchdenny Mar 27, 2024
84b02d6
Update apphost launch settings.
mitchdenny Mar 27, 2024
4e03c64
PR feedback.
mitchdenny Mar 27, 2024
82efb14
Handle DistributedApplicationOptions.AllowUnsecuredTransport and Dist…
mitchdenny Mar 27, 2024
b04f9d1
remove unnecessary set of config.
mitchdenny Mar 27, 2024
11c6e40
Cover other URLs and complete code coverage.
mitchdenny Mar 27, 2024
741dc58
Fix issue of project not working in helix.
mitchdenny Mar 27, 2024
b0300f9
Enable unsecured transport in helix fixture.
mitchdenny Mar 27, 2024
9a605df
Helix test debugging.
mitchdenny Mar 27, 2024
d2b05e7
Update TransportOptions.cs
mitchdenny Mar 27, 2024
b077b82
Don't need to set config manually anymore.
mitchdenny Mar 27, 2024
5ae82c1
launchSettings apalooza
mitchdenny Mar 28, 2024
654fa37
Remove unnecessary fixture subclass.
mitchdenny Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion playground/AWS/AWS.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16216"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16216",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
mitchdenny marked this conversation as resolved.
Show resolved Hide resolved
}
},
"manifest-publish": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16155"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16155",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
},
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16195"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16195",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"http-UseConnectionString": {
Expand All @@ -23,7 +24,8 @@
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"SimulateProduction": "true"
"SimulateProduction": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
3 changes: 2 additions & 1 deletion playground/TestShop/AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16031",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:17031",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
3 changes: 2 additions & 1 deletion playground/dapr/AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16031",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16160"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16160",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
3 changes: 2 additions & 1 deletion playground/nats/Nats.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16160"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16160",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16031",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
3 changes: 2 additions & 1 deletion playground/seq/Seq.AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175",
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true"
"DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16099"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16099",
"ASPIRE_ALLOW_UNSECURED_TRANSPORT": "true"
}
},
"generate-manifest": {
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Aspire.Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="$(SharedDir)IConfigurationExtensions.cs" Link="Utils\IConfigurationExtensions.cs" />
<Compile Include="$(SharedDir)KnownFormats.cs" Link="Utils\KnownFormats.cs" />
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="Utils\KnownResourceNames.cs" />
<Compile Include="$(SharedDir)KnownConfigNames.cs" Link="Utils\KnownConfigNames.cs" />
<Compile Include="$(SharedDir)PathNormalizer.cs" Link="Utils\PathNormalizer.cs" />
<Compile Include="$(SharedDir)StringComparers.cs" Link="Utils\StringComparers.cs" />
<Compile Include="$(SharedDir)TaskHelpers.cs" Link="Utils\TaskHelpers.cs" />
Expand Down
10 changes: 10 additions & 0 deletions src/Aspire.Hosting/Dashboard/TransportOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Hosting.Dashboard;

internal class TransportOptions
{
public bool AllowUnsecureTransport { get; set; }
public string? BrowserToken { get; set; }
mitchdenny marked this conversation as resolved.
Show resolved Hide resolved
}
75 changes: 75 additions & 0 deletions src/Aspire.Hosting/Dashboard/TransportOptionsValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

namespace Aspire.Hosting.Dashboard;

internal class TransportOptionsValidator(IConfiguration configuration, DistributedApplicationExecutionContext executionContext, DistributedApplicationOptions distributedApplicationOptions) : IValidateOptions<TransportOptions>
{
public ValidateOptionsResult Validate(string? name, TransportOptions transportOptions)
{
var effectiveAllowUnsecureTransport = transportOptions.AllowUnsecureTransport || distributedApplicationOptions.DisableDashboard || distributedApplicationOptions.AllowUnsecuredTransport;

if (executionContext.IsPublishMode || effectiveAllowUnsecureTransport)
{
return ValidateOptionsResult.Success;
}
davidfowl marked this conversation as resolved.
Show resolved Hide resolved

// Validate ASPNETCORE_URLS
var applicationUrls = configuration[KnownConfigNames.AspNetCoreUrls];
if (string.IsNullOrEmpty(applicationUrls))
{
return ValidateOptionsResult.Fail($"AppHost does not have applicationUrl in launch profile, or {KnownConfigNames.AspNetCoreUrls} environment variable set.");
}

var firstApplicationUrl = applicationUrls.Split(";").First();

if (!Uri.TryCreate(firstApplicationUrl, UriKind.Absolute, out var parsedFirstApplicationUrl))
{
return ValidateOptionsResult.Fail($"The 'applicationUrl' setting of the launch profile has value '{firstApplicationUrl}' which could not be parsed as a URI.");
}
mitchdenny marked this conversation as resolved.
Show resolved Hide resolved

if (parsedFirstApplicationUrl.Scheme == "http")
{
return ValidateOptionsResult.Fail($"The 'applicationUrl' setting must be an https address unless the '{KnownConfigNames.AllowUnsecuredTransport}' environment variable is set to true. This configuration is commonly set in the launch profile. See https://aka.ms/dotnet/aspire/allowunsecuredtransport for more details.");
}

// Vaidate DOTNET_DASHBOARD_OTLP_ENDPOINT_URL
var dashboardOtlpEndpointUrl = configuration[KnownConfigNames.DashboardOtlpEndpointUrl];
if (string.IsNullOrEmpty(dashboardOtlpEndpointUrl))
{
return ValidateOptionsResult.Fail($"AppHost does not have the {KnownConfigNames.DashboardOtlpEndpointUrl} setting defined.");
}

if (!Uri.TryCreate(dashboardOtlpEndpointUrl, UriKind.Absolute, out var parsedDashboardOtlpEndpointUrl))
{
return ValidateOptionsResult.Fail($"The {KnownConfigNames.DashboardOtlpEndpointUrl} setting with a value of '{dashboardOtlpEndpointUrl}' could not be parsed as a URI.");
}

if (parsedDashboardOtlpEndpointUrl.Scheme == "http")
{
return ValidateOptionsResult.Fail($"The '{KnownConfigNames.DashboardOtlpEndpointUrl}' setting must be an https address unless the '{KnownConfigNames.AllowUnsecuredTransport}' environment variable is set to true. This configuration is commonly set in the launch profile. See https://aka.ms/dotnet/aspire/allowunsecuredtransport for more details.");
}

// Vaidate DOTNET_DASHBOARD_RESOURCE_SERVER_ENDPOINT_URL
var resourceServiceEndpointUrl = configuration[KnownConfigNames.ResourceServiceEndpointUrl];
if (string.IsNullOrEmpty(resourceServiceEndpointUrl))
{
return ValidateOptionsResult.Fail($"AppHost does not have the {KnownConfigNames.ResourceServiceEndpointUrl} setting defined.");
}

if (!Uri.TryCreate(resourceServiceEndpointUrl, UriKind.Absolute, out var parsedResourceServiceEndpointUrl))
{
return ValidateOptionsResult.Fail($"The {KnownConfigNames.ResourceServiceEndpointUrl} setting with a value of '{resourceServiceEndpointUrl}' could not be parsed as a URI.");
}

if (parsedResourceServiceEndpointUrl.Scheme == "http")
{
return ValidateOptionsResult.Fail($"The '{KnownConfigNames.ResourceServiceEndpointUrl}' setting must be an https address unless the '{KnownConfigNames.AllowUnsecuredTransport}' environment variable is set to true. This configuration is commonly set in the launch profile. See https://aka.ms/dotnet/aspire/allowunsecuredtransport for more details.");
}

return ValidateOptionsResult.Success;
}
}
12 changes: 12 additions & 0 deletions src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
using Aspire.Hosting.Publishing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace Aspire.Hosting;

Expand Down Expand Up @@ -89,6 +91,8 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
_innerBuilder.Services.AddSingleton<ResourceLoggerService>();

// Dashboard
_innerBuilder.Services.AddOptions<TransportOptions>().ValidateOnStart().PostConfigure(MapTransportOptionsFromCustomKeys);
_innerBuilder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<TransportOptions>, TransportOptionsValidator>());
_innerBuilder.Services.AddSingleton<DashboardServiceHost>();
_innerBuilder.Services.AddHostedService<DashboardServiceHost>(sp => sp.GetRequiredService<DashboardServiceHost>());
_innerBuilder.Services.AddLifecycleHook<DashboardManifestExclusionHook>();
Expand Down Expand Up @@ -119,6 +123,14 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
LogBuilderConstructed(this);
}

private void MapTransportOptionsFromCustomKeys(TransportOptions options)
{
if (Configuration.GetBool(KnownConfigNames.AllowUnsecuredTransport) is { } allowUnsecuredTransport)
{
options.AllowUnsecureTransport = allowUnsecuredTransport;
}
}

private static bool IsOtlpApiKeyAuthDisabled(IConfiguration configuration)
{
return configuration.GetBool(DisableOtlpApiKeyAuthKey) ?? false;
Expand Down
5 changes: 5 additions & 0 deletions src/Aspire.Hosting/DistributedApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public DistributedApplicationOptions()

internal bool DashboardEnabled => !DisableDashboard;

/// <summary>
/// Allows the use of HTTP urls for for the AppHost resource endpoint.
/// </summary>
public bool AllowUnsecuredTransport { get; set; }

private string? ResolveProjectDirectory()
{
var assemblyMetadata = Assembly?.GetCustomAttributes<AssemblyMetadataAttribute>();
Expand Down
12 changes: 12 additions & 0 deletions src/Shared/KnownConfigNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Hosting;

internal static class KnownConfigNames
mitchdenny marked this conversation as resolved.
Show resolved Hide resolved
{
public static string AspNetCoreUrls = "ASPNETCORE_URLS";
public static string AllowUnsecuredTransport = "ASPIRE_ALLOW_UNSECURED_TRANSPORT";
public static string DashboardOtlpEndpointUrl = "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL";
public static string ResourceServiceEndpointUrl = "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL";
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public IntegrationServicesFixture(IMessageSink diagnosticMessageSink)
{
BuildEnvironment.EnvVars["TestsRunningOutsideOfRepo"] = "true";
}
BuildEnvironment.EnvVars.Add("ASPIRE_ALLOW_UNSECURED_TRANSPORT", "true");
}

public async Task InitializeAsync()
Expand Down
Loading