-
Notifications
You must be signed in to change notification settings - Fork 850
Added support for Aspire dashboard in App Service #11671
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
Merged
davidfowl
merged 23 commits into
microsoft:main
from
ShilpiRach:shilpirach/appsvc_dashboard
Oct 7, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3aa796d
Added support for Aspire dashboard in App Service
ShilpiR 4626741
Fixed failing tests
ShilpiR 2baefd2
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironment…
ShilpiRach f21c564
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironment…
ShilpiRach 622ba2d
Added option to exclude dashboard and moved contributor identity to d…
ShilpiR c0cca3a
Added appsetting to suppress unsecured warning
ShilpiR 45968a4
Merge branch 'main' into shilpirach/appsvc_dashboard
ShilpiRach a669727
Fixed failing unit tests
ShilpiR 77aa4a1
Merge branch 'shilpirach/appsvc_dashboard' of https://github.com/Shil…
ShilpiR a554e77
Made parameter dashboardUri conditional in web app bicep templates
ShilpiR d1eac7c
Publishing DashboardUri paramater only when dashboard is enabled
ShilpiR df38b1c
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironment…
ShilpiRach 26793ea
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironment…
ShilpiRach ae6fec2
Handled PR feedback and added support to log dashboard Uri
ShilpiR 884857c
Updated a comment
ShilpiR da816ef
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironment…
davidfowl ab80970
Merge branch 'dotnet:main' into shilpirach/appsvc_dashboard
ShilpiRach e43750e
Handled scenario where there are multiple Aspire environments in a si…
ShilpiR 5f553ef
Merge from aspire repo (main)
ShilpiR 9d3200b
Added Reader role assignment to managed identity for dashboard
ShilpiR 378a9d7
Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteCont…
ShilpiRach c39fac6
Taking a nit change
ShilpiR 96f5683
Merge branch 'shilpirach/appsvc_dashboard' of https://github.com/Shil…
ShilpiR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentUtility.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Azure.Core; | ||
| using Azure.Provisioning; | ||
| using Azure.Provisioning.AppService; | ||
| using Azure.Provisioning.Authorization; | ||
| using Azure.Provisioning.Expressions; | ||
| using Azure.Provisioning.Resources; | ||
| using Azure.Provisioning.Roles; | ||
|
|
||
| namespace Aspire.Hosting.Azure.AppService; | ||
|
|
||
| internal static class AzureAppServiceEnvironmentUtility | ||
| { | ||
| internal const string ResourceName = "aspiredashboard"; | ||
|
|
||
| public static BicepValue<string> GetDashboardHostName(string aspireResourceName) | ||
| { | ||
| return BicepFunction.Take( | ||
| BicepFunction.Interpolate($"{BicepFunction.ToLower(aspireResourceName)}-{BicepFunction.ToLower(ResourceName)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}"), 60); | ||
| } | ||
|
|
||
| public static WebSite AddDashboard(AzureResourceInfrastructure infra, | ||
| UserAssignedIdentity otelIdentity, | ||
| BicepValue<ResourceIdentifier> appServicePlanId) | ||
| { | ||
| // This ACR identity is used by the dashboard to authorize the telemetry data | ||
| // coming from the dotnet web apps. This identity is being assigned to every web app | ||
| // in the aspire project and can be safely reused for authorization in the dashboard. | ||
| var otelClientId = otelIdentity.ClientId; | ||
| var prefix = infra.AspireResource.Name; | ||
| var contributorIdentity = new UserAssignedIdentity(Infrastructure.NormalizeBicepIdentifier($"{prefix}-contributor-mi")); | ||
|
|
||
| infra.Add(contributorIdentity); | ||
|
|
||
| // Add Reader role assignment | ||
| var rgRaId = BicepFunction.GetSubscriptionResourceId( | ||
| "Microsoft.Authorization/roleDefinitions", | ||
| "acdd72a7-3385-48ef-bd42-f606fba81ae7"); | ||
| var rgRaName = BicepFunction.CreateGuid(BicepFunction.GetResourceGroup().Id, contributorIdentity.Id, rgRaId); | ||
|
|
||
| var rgRa = new RoleAssignment(Infrastructure.NormalizeBicepIdentifier($"{prefix}_ra")) | ||
| { | ||
| Name = rgRaName, | ||
| PrincipalType = RoleManagementPrincipalType.ServicePrincipal, | ||
| PrincipalId = contributorIdentity.PrincipalId, | ||
| RoleDefinitionId = rgRaId | ||
| }; | ||
|
|
||
| infra.Add(rgRa); | ||
|
|
||
| var dashboard = new WebSite("dashboard") | ||
| { | ||
| // Use the host name as the name of the web app | ||
| Name = GetDashboardHostName(infra.AspireResource.Name), | ||
| AppServicePlanId = appServicePlanId, | ||
| // Aspire dashboards are created with a new kind aspiredashboard | ||
| Kind = "app,linux,aspiredashboard", | ||
| SiteConfig = new SiteConfigProperties() | ||
| { | ||
| LinuxFxVersion = "ASPIREDASHBOARD|1.0", | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| AcrUserManagedIdentityId = otelClientId, | ||
| UseManagedIdentityCreds = true, | ||
| IsHttp20Enabled = true, | ||
| Http20ProxyFlag = 1, | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Setting NumberOfWorkers to 1 to ensure dashboard runs on 1 instance | ||
| NumberOfWorkers = 1, | ||
| // IsAlwaysOn set to true ensures the app is always running | ||
| IsAlwaysOn = true, | ||
| AppSettings = [] | ||
| }, | ||
| Identity = new ManagedServiceIdentity() | ||
| { | ||
| ManagedServiceIdentityType = ManagedServiceIdentityType.UserAssigned, | ||
| UserAssignedIdentities = [] | ||
| } | ||
| }; | ||
|
|
||
| var contributorMid = BicepFunction.Interpolate($"{contributorIdentity.Id}").Compile().ToString(); | ||
| dashboard.Identity.UserAssignedIdentities[contributorMid] = new UserAssignedIdentityDetails(); | ||
|
|
||
| // Security is handled by app service platform | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Frontend__AuthMode", Value = "Unsecured" }); | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Otlp__AuthMode", Value = "Unsecured" }); | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Otlp__SuppressUnsecuredTelemetryMessage", Value = "true" }); | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__ResourceServiceClient__AuthMode", Value = "Unsecured" }); | ||
| // Dashboard ports | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITES_PORT", Value = "5000" }); | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "HTTP20_ONLY_PORT", Value = "4317" }); | ||
| // Enable SCM preloading to ensure dashboard is always available | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITE_START_SCM_WITH_PRELOAD", Value = "true" }); | ||
| // Appsettings related to managed identity for auth | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "AZURE_CLIENT_ID", Value = contributorIdentity.ClientId }); | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ALLOWED_MANAGED_IDENTITIES", Value = otelClientId }); | ||
| // Added appsetting to identify the resources in a specific aspire environment | ||
| dashboard.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ASPIRE_ENVIRONMENT_NAME", Value = infra.AspireResource.Name }); | ||
|
|
||
| infra.Add(dashboard); | ||
|
|
||
| // Outputs needed by the app service environment | ||
| // This identity needs website contributor access on the websites for resource server to work | ||
| infra.Add(new ProvisioningOutput("AZURE_WEBSITE_CONTRIBUTOR_MANAGED_IDENTITY_ID", typeof(string)) | ||
| { | ||
| Value = contributorIdentity.Id | ||
| }); | ||
|
|
||
| infra.Add(new ProvisioningOutput("AZURE_WEBSITE_CONTRIBUTOR_MANAGED_IDENTITY_PRINCIPAL_ID", typeof(string)) | ||
| { | ||
| Value = contributorIdentity.PrincipalId | ||
| }); | ||
|
|
||
| return dashboard; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| using Aspire.Hosting.ApplicationModel; | ||
| using Azure.Provisioning; | ||
| using Azure.Provisioning.AppService; | ||
| using Azure.Provisioning.Authorization; | ||
| using Azure.Provisioning.Expressions; | ||
| using Azure.Provisioning.Resources; | ||
|
|
||
|
|
@@ -212,7 +213,7 @@ public void BuildWebSite(AzureResourceInfrastructure infra) | |
| var acrMidParameter = environmentContext.Environment.ContainerRegistryManagedIdentityId.AsProvisioningParameter(infra); | ||
| var acrClientIdParameter = environmentContext.Environment.ContainerRegistryClientId.AsProvisioningParameter(infra); | ||
| var containerImage = AllocateParameter(new ContainerImageReference(Resource)); | ||
|
|
||
| var webSite = new WebSite("webapp") | ||
| { | ||
| // Use the host name as the name of the web app | ||
|
|
@@ -224,6 +225,12 @@ public void BuildWebSite(AzureResourceInfrastructure infra) | |
| LinuxFxVersion = "SITECONTAINERS", | ||
| AcrUserManagedIdentityId = acrClientIdParameter, | ||
| UseManagedIdentityCreds = true, | ||
| // Setting NumberOfWorkers to maximum allowed value for Premium SKU | ||
| // https://learn.microsoft.com/en-us/azure/app-service/manage-scale-up | ||
| // This is required due to use of feature PerSiteScaling for the App Service plan | ||
| // We want the web apps to scale normally as defined for the app service plan | ||
| // so setting the maximum number of workers to the maximum allowed for Premium V2 SKU. | ||
| NumberOfWorkers = 30, | ||
|
Comment on lines
+228
to
+233
|
||
| AppSettings = [] | ||
| }, | ||
| Identity = new ManagedServiceIdentity() | ||
|
|
@@ -306,6 +313,9 @@ static FunctionCallExpression Join(BicepExpression args, string delimeter) => | |
| }); | ||
| } | ||
|
|
||
| // Added appsetting to identify the resource in a specific aspire environment | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ASPIRE_ENVIRONMENT_NAME", Value = environmentContext.Environment.Name }); | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Probes | ||
| #pragma warning disable ASPIREPROBES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
| if (resource.TryGetAnnotationsOfType<ProbeAnnotation>(out var probeAnnotations)) | ||
|
|
@@ -323,7 +333,17 @@ static FunctionCallExpression Join(BicepExpression args, string delimeter) => | |
| } | ||
| #pragma warning restore ASPIREPROBES001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. | ||
|
|
||
| RoleAssignment? webSiteRa = null; | ||
| if (environmentContext.Environment.EnableDashboard) | ||
| { | ||
| webSiteRa = AddDashboardPermissionAndSettings(webSite, acrClientIdParameter); | ||
| } | ||
|
|
||
| infra.Add(webSite); | ||
| if (webSiteRa is not null) | ||
| { | ||
| infra.Add(webSiteRa); | ||
| } | ||
|
|
||
| // Allow users to customize the web app here | ||
| if (resource.TryGetAnnotationsOfType<AzureAppServiceWebsiteCustomizationAnnotation>(out var customizeWebSiteAnnotations)) | ||
|
|
@@ -363,6 +383,36 @@ private ProvisioningParameter AllocateParameter(IManifestExpressionProvider para | |
| return parameter.AsProvisioningParameter(Infra, isSecure: secretType == SecretType.Normal); | ||
| } | ||
|
|
||
| private RoleAssignment AddDashboardPermissionAndSettings(WebSite webSite, ProvisioningParameter acrClientIdParameter) | ||
| { | ||
| var dashboardUri = environmentContext.Environment.DashboardUriReference.AsProvisioningParameter(Infra); | ||
| var contributorId = environmentContext.Environment.WebsiteContributorManagedIdentityId.AsProvisioningParameter(Infra); | ||
| var contributorPrincipalId = environmentContext.Environment.WebsiteContributorManagedIdentityPrincipalId.AsProvisioningParameter(Infra); | ||
|
|
||
| // Add the appsettings specific to sending telemetry data to dashboard | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "OTEL_SERVICE_NAME", Value = resource.Name }); | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "OTEL_EXPORTER_OTLP_PROTOCOL", Value = "grpc" }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "OTEL_EXPORTER_OTLP_ENDPOINT", Value = "http://localhost:6001" }); | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITE_ENABLE_ASPIRE_OTEL_SIDECAR", Value = "true" }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "OTEL_COLLECTOR_URL", Value = dashboardUri }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "OTEL_CLIENT_ID", Value = acrClientIdParameter }); | ||
|
|
||
| // Add Website Contributor role assignment to dashboard's managed identity for this webapp | ||
| var websiteRaId = BicepFunction.GetSubscriptionResourceId( | ||
| "Microsoft.Authorization/roleDefinitions", | ||
| "de139f84-1756-47ae-9be6-808fbbe84772"); | ||
| var websiteRaName = BicepFunction.CreateGuid(webSite.Id, contributorId, websiteRaId); | ||
|
|
||
| return new RoleAssignment(Infrastructure.NormalizeBicepIdentifier($"{Infra.AspireResource.Name}_ra")) | ||
| { | ||
| Name = websiteRaName, | ||
| Scope = new IdentifierExpression(webSite.BicepIdentifier), | ||
| PrincipalType = RoleManagementPrincipalType.ServicePrincipal, | ||
| PrincipalId = contributorPrincipalId, | ||
| RoleDefinitionId = websiteRaId, | ||
| }; | ||
| } | ||
|
|
||
| enum SecretType | ||
| { | ||
| None, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.