-
Notifications
You must be signed in to change notification settings - Fork 721
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
dotnet:main
from
ShilpiRach:shilpirach/appsvc_dashboard
Oct 7, 2025
Merged
Changes from 9 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
112 changes: 112 additions & 0 deletions
112
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,112 @@ | ||
| // 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 | ||
| { | ||
| const string ResourceName = "dashboard"; | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static BicepValue<string> DashboardHostName => BicepFunction.Take( | ||
| BicepFunction.Interpolate($"{BicepFunction.ToLower(ResourceName)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}"), 60); | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public static WebSite AddDashboard(AzureResourceInfrastructure infra, | ||
| UserAssignedIdentity otelIdentity, | ||
| BicepValue<ResourceIdentifier> appServicePlanId) | ||
| { | ||
| var acrClientIdParameter = otelIdentity.ClientId; | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var prefix = infra.AspireResource.Name; | ||
| var contributorIdentity = new UserAssignedIdentity(Infrastructure.NormalizeBicepIdentifier($"{prefix}-contributor-mi")); | ||
|
|
||
| var contributorMidParameter = contributorIdentity.Id; | ||
| var contributorClientIdParameter = contributorIdentity.ClientId; | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| infra.Add(contributorIdentity); | ||
|
|
||
| // Add Website Contributor role assignment | ||
| var rgRaId = BicepFunction.GetSubscriptionResourceId( | ||
| "Microsoft.Authorization/roleDefinitions", | ||
| "de139f84-1756-47ae-9be6-808fbbe84772"); | ||
| var rgRaName = BicepFunction.CreateGuid(BicepFunction.GetResourceGroup().Id, contributorIdentity.Id, rgRaId); | ||
| var rgRa = new RoleAssignment(Infrastructure.NormalizeBicepIdentifier($"{prefix}_ra")) | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| Name = rgRaName, | ||
| PrincipalType = RoleManagementPrincipalType.ServicePrincipal, | ||
| PrincipalId = contributorIdentity.PrincipalId, | ||
| RoleDefinitionId = rgRaId, | ||
| }; | ||
|
|
||
| infra.Add(rgRa); | ||
|
|
||
| // Add Reader role assignment | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var rgRaId2 = BicepFunction.GetSubscriptionResourceId( | ||
| "Microsoft.Authorization/roleDefinitions", | ||
| "acdd72a7-3385-48ef-bd42-f606fba81ae7"); | ||
| var rgRaName2 = BicepFunction.CreateGuid(BicepFunction.GetResourceGroup().Id, contributorIdentity.Id, rgRaId2); | ||
|
|
||
| var rgRa2 = new RoleAssignment(Infrastructure.NormalizeBicepIdentifier($"{prefix}_ra2")) | ||
| { | ||
| Name = rgRaName2, | ||
| PrincipalType = RoleManagementPrincipalType.ServicePrincipal, | ||
| PrincipalId = contributorIdentity.PrincipalId, | ||
| RoleDefinitionId = rgRaId2 | ||
| }; | ||
|
|
||
| infra.Add(rgRa2); | ||
|
|
||
| var webSite = new WebSite("webapp") | ||
davidfowl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| // Use the host name as the name of the web app | ||
| Name = DashboardHostName, | ||
| 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 = acrClientIdParameter, | ||
| UseManagedIdentityCreds = true, | ||
| IsHttp20Enabled = true, | ||
| Http20ProxyFlag = 1, | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Setting NumberOfWorkers to 1 to ensure dashboard runs of 1 instance | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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($"{contributorMidParameter}").Compile().ToString(); | ||
| webSite.Identity.UserAssignedIdentities[contributorMid] = new UserAssignedIdentityDetails(); | ||
|
|
||
| // Security is handled by app service platform | ||
ShilpiRach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Frontend__AuthMode", Value = "Unsecured" }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Otlp__AuthMode", Value = "Unsecured" }); | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__Otlp__SuppressUnsecuredTelemetryMessage", Value = "true" }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "Dashboard__ResourceServiceClient__AuthMode", Value = "Unsecured" }); | ||
| // Dashboard ports | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITES_PORT", Value = "5000" }); | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "HTTP20_ONLY_PORT", Value = "4317" }); | ||
| // Enable SCM preloading to ensure dashboard is always available | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "WEBSITE_START_SCM_WITH_PRELOAD", Value = "true" }); | ||
| // Appsettings related to managed identity for auth | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "AZURE_CLIENT_ID", Value = contributorClientIdParameter }); | ||
| webSite.SiteConfig.AppSettings.Add(new AppServiceNameValuePair { Name = "ALLOWED_MANAGED_IDENTITIES", Value = acrClientIdParameter }); | ||
| infra.Add(webSite); | ||
|
|
||
| return webSite; | ||
| } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -212,6 +212,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 dashboardUri = environmentContext.Environment.DashboardUriReference.AsProvisioningParameter(infra); | ||
ShilpiRach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var webSite = new WebSite("webapp") | ||
| { | ||
|
|
@@ -224,6 +225,9 @@ 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 | ||
| NumberOfWorkers = 30, | ||
|
Comment on lines
228
to
233
|
||
| AppSettings = [] | ||
| }, | ||
| Identity = new ManagedServiceIdentity() | ||
|
|
@@ -323,6 +327,11 @@ 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. | ||
|
|
||
| if (environmentContext.Environment.EnableDashboard) | ||
| { | ||
| AddDashboardSettings(webSite, acrClientIdParameter, dashboardUri); | ||
| } | ||
|
|
||
| infra.Add(webSite); | ||
|
|
||
| // Allow users to customize the web app here | ||
|
|
@@ -362,6 +371,15 @@ private ProvisioningParameter AllocateParameter(IManifestExpressionProvider para | |
| { | ||
| return parameter.AsProvisioningParameter(Infra, isSecure: secretType == SecretType.Normal); | ||
| } | ||
| private void AddDashboardSettings(WebSite webSite, ProvisioningParameter acrClientIdParameter, ProvisioningParameter dashboardUri) | ||
| { | ||
| 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 }); | ||
| } | ||
|
|
||
| enum SecretType | ||
| { | ||
|
|
||
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
61 changes: 61 additions & 0 deletions
61
...rviceTests.AddAppServiceEnvironmentWithoutDashboardAddsEnvironmentResource.verified.bicep
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,61 @@ | ||
| @description('The location for the resource(s) to be deployed.') | ||
| param location string = resourceGroup().location | ||
|
|
||
| param userPrincipalId string = '' | ||
|
|
||
| param tags object = { } | ||
|
|
||
| resource env_mi 'Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30' = { | ||
| name: take('env_mi-${uniqueString(resourceGroup().id)}', 128) | ||
| location: location | ||
| tags: tags | ||
| } | ||
|
|
||
| resource env_acr 'Microsoft.ContainerRegistry/registries@2025-04-01' = { | ||
| name: take('envacr${uniqueString(resourceGroup().id)}', 50) | ||
| location: location | ||
| sku: { | ||
| name: 'Basic' | ||
| } | ||
| tags: tags | ||
| } | ||
|
|
||
| resource env_acr_env_mi_AcrPull 'Microsoft.Authorization/roleAssignments@2022-04-01' = { | ||
| name: guid(env_acr.id, env_mi.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')) | ||
| properties: { | ||
| principalId: env_mi.properties.principalId | ||
| roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d') | ||
| principalType: 'ServicePrincipal' | ||
| } | ||
| scope: env_acr | ||
| } | ||
|
|
||
| resource env_asplan 'Microsoft.Web/serverfarms@2024-11-01' = { | ||
| name: take('envasplan-${uniqueString(resourceGroup().id)}', 60) | ||
| location: location | ||
| properties: { | ||
| perSiteScaling: true | ||
| reserved: true | ||
| } | ||
| kind: 'Linux' | ||
| sku: { | ||
| name: 'P0V3' | ||
| tier: 'Premium' | ||
| } | ||
| } | ||
|
|
||
| output name string = env_asplan.name | ||
|
|
||
| output planId string = env_asplan.id | ||
|
|
||
| output AZURE_CONTAINER_REGISTRY_NAME string = env_acr.name | ||
|
|
||
| output AZURE_CONTAINER_REGISTRY_ENDPOINT string = env_acr.properties.loginServer | ||
|
|
||
| output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID string = env_mi.id | ||
|
|
||
| output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_CLIENT_ID string = env_mi.properties.clientId | ||
|
|
||
| output AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_NAME string = env_mi.name | ||
|
|
||
| output DASHBOARD_URI string = 'https://${take('${toLower('dashboard')}-${uniqueString(resourceGroup().id)}', 60)}.azurewebsites.net' |
7 changes: 7 additions & 0 deletions
7
...erviceTests.AddAppServiceEnvironmentWithoutDashboardAddsEnvironmentResource.verified.json
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,7 @@ | ||
| { | ||
| "type": "azure.bicep.v0", | ||
| "path": "env.module.bicep", | ||
| "params": { | ||
| "userPrincipalId": "" | ||
| } | ||
| } |
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.