Skip to content

CawaMS/aspnetcore-msi-keyvault

 
 

Repository files navigation

How to use Managed Service Identity to access Azure Key Vault from ASP.NET Core

Overview

This sample demonstrates how to securely access an Azure resource such as Key Vault using Visual Studio sign-in identity during development, and using Managed Service Identity on Azure.

Pre-requisites to run this sample

How to debug this application locally

  1. Deploy the following resources to your Azure subscription by clicking the button below

    Deploy to Azure

  2. Go to your Key Vault resource on Azure portal. Browse to Access policies. Grant yourself Secret Get and List permissions.

Add Access Policy

Select User

Select Policy

Save the access policy by clicking Save on the top left corner in the menu bar of current blade.

  1. Obtain the Key Vault URL from Azure portal. Save it in the environment variable section in launchsettings.json file, under a profile in the profiles section. If you only save it under one profile, for example, the aspnetcore-msi-keyvault profile, you will need to choose this profile when running in debug.

        "KEYVAULT_ENDPOINT": "https://[NameOfYourKeyVault].vault.azure.net/"
    

Add Key Vault URL to your app

select the right debug profile

  1. (Optional) If you need to use an account that is different from the Personalization account in the top right corner of Visual Studio, to go to Tools | Options | Azure Service Authentication | Account Selection

Select an account in Visual Studio

  1. Press F5 or select Debug | Start Debugging from tool bar in Visual Studio. The app should display the secrets from Key Vault.

How did the app access Key Vault during debugging session

During startup the app uses Visual Studio sign-in identity to access Key Vault and pulls secret settings to the process memory so the app runs successfully.

access key vault from visual studio

The Azure Services Authentication Extension allows the app to access Azure Key Vault using Visual Studio sign-in identity

How to deploy this application to Azure

  1. In Azure portal, navigate to the App Services you created earlier. Select App Settings and add the Key Vault URL

Add app setting for Key Vault

  1. Right click the project and launch the publish dialog. Deploy the web app to the your App Services resource created earlier.

Learn more about securely developing Azure applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%