-
Create your App Service, Key Vault, and Application Insights
- Copy the Key Vault's "Vault URI" for later
- Copy the Application Insights' "Connection String" for later
-
In the App Service's "Identity", turn the "System assigned" "Status" to "On"
-
In the App Service's "Configuration", create a "New application setting" with value "KeyVaultURI", and value of the "Vault URI" you copied in step 1
-
In the Key Vault's "Access control (IAM)", "Add > Add role assignment", add two things:
- Under "Job function roles", find "Key Vault Administrator"; under "Members", find yourself
- Under "Job function roles", find "Key Vault Secrets User" ; under "Members" find the "Managed identity" that is your App Service
-
In the Key Vault's "Secrets", add a secret with name "ApplicationInsights--ConnectionString" and value of the Application Insights' "Connection String" you copied in step 1
-
In your .NET Core application, add the following to
Program.cs
:// for prod, expected to be set in App Service's environment variables: if (builder.Configuration["KeyVaultURI"] is { } keyVaultURI) { builder.Configuration.AddAzureKeyVault( new Uri(keyVaultURI), new DefaultAzureCredential(), new DoubleDashSecretManager() ); } builder.Services.AddApplicationInsightsTelemetry();
-
Create the
DoubleDashSecretManager
class as follows:public class DoubleDashSecretManager: KeyVaultSecretManager { public override string GetKey(KeyVaultSecret secret) => secret.Name.Replace("--", ConfigurationPath.KeyDelimiter); }
-
Ya done!
Created
November 15, 2023 16:30
-
-
Save BenMakesGames/a05ed33ba67ef57c45f0212eab73db7e to your computer and use it in GitHub Desktop.
A walkthrough for how to create a basic .NET Core 8 app for App Service w/ Key Vault & Application Insights
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment