Understand and use Azure Key Vault Easily (Most Secured Secrets Storage)
Tags: azure, security, keyvault
Published: 2021-05-09 06:34:11

Now a days the term *security* becoming the must follow topic for all the organizations to have a good brand name.
To secure your credentials or secrets in your web application is a big challenge when we deploy our application to the public internet.
And also once your code is deployed and secrets are revealed then one need to redeploy the code with updated secrets to secure the application. As the application grows bigger and bigger this will be cumbersome to manage the application.

To solve this issue we can use [**Azure Key Vault**](https://azure.microsoft.com/en-in/services/key-vault/) resource.
Azure Key Vault is a Microsoft cloud service to store and access data and secrets securely. Which controls below tasks,
1. Securely store the keys, secrets and certificates.
2. Only authorized user can access the key vault.
3. Frequently rotate the secrets, keys.
4. Automatically renew the certificates.
5. Centralized storage for all keys, secrets and certificates.

Azure Key Vault can be used in many services, here I will be showing how to use it in Azure app service.

**Prerequisites:**
- Active Azure Subscription [Account](https://azure.microsoft.com/en-us/)
- Visual Studio [Code](https://code.visualstudio.com/)

We can create Azure Key Vault using Azure CLI or Azure Portal.
In this blog we will look at how to do in Azure Portal.

#### Create Azure Key Vault using Azure Portal

**Create an Azure resource**
1. Login to Azure Portal.
2. Click on create a resource.
![createresource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hyr2xbjqtd5x40k7vpos.png)

3. Search for Key Vault. Select and create it.
![KeyVault-Search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tzz3wworqlwv55dgt30.png)
![KeyVault-Create-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/st06036s889q1udtsej1.png)

4. Fill details and create the resource.

**Resource Group**: Select existing resource group or create a new one

**Key vault name**: Enter globally Unique name for your key vault. This is access from the application.

**Region**: Select location the one near to you.

**Pricing tier**: Select *Standard*.

![KeyVault-Create-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov8hgilrhabb3b9jbx3r.png)
  
5. **Review + create** and then **create**.

6. Go to Key vault resource created.
![KeyVault-Secrets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfnj7zi5j1378ryx6wvm.png)
 
7. Let's create some secrets in the key vault which will be accessed from our application.
Click on **Generate/Import** to add new secret.
![KeyVault-Secrets-Generate](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxjtkbl2glqk9xed2v8m.png)
 
Fill the details and add it.
**Name**: name of the secret to be created.
**value**: Value to store in this secret. 
We can set when this secret can be activated and deactivated.
As of now we can leave default, meaning immediate activate and never expires.
![KeyVault-Secrets-Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b4o4mt58ux2ermh632b9.png)

8. After the secret is added go the secret which looks like this.
![KeyVault-Secrets-Details-Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3a1a3ikccugkenxj9gzu.png)

Our secret is successfully created in Azure Key Vault. Now we have to access it from our code.
To access the secrets, valid permissions (like who can access) must be added to the keyvault.
Let's learn how to add the authentication in next part of this series.