Reputation: 319
I am not able to understand what's the benefit of the azure key vault if I am storing ClientId and client secret in web/App Config. Passing the base URI or the complete URL for getting the values.
I am not securing the application instead I am bypassing the things to directly read. But anybody can read the values from key vault if they can read the value from web config.
Just need to copy ClientId and ClientSecret from the web config, Paste the values in your console application and get the values by just passing the URI.
I am running my Web API(c#) in Virtual Machine(IIS). I need to implement KeyVault without providing any values in the web config.
Upvotes: 3
Views: 8476
Reputation: 5296
Architecturally speaking , azure key vaults provide easy way to store the configuration settings for your application. As you might have seen in the example docs that for accessing the key vault , we store the client id and client secret in web.config which is not as per the secure design:
Here is something which you can do :
In this way do don't need to expose the client id and secret of you application.
Additionally , we create a service principal account in Azure AD and provide the access to read the data from Key vault. Later we store the bearer token after calling the Azure AD authentication API and use this token to access key vault.
**Managed identity**
as pointed by @JackJia , Managed identity will be considered as trusted resource, and can get token from specific endpoint without any additional configuration. You can read the above answer for details.let me know if you want to discuss further , would be happy to help you.
Upvotes: 4
Reputation: 5559
If you do not want to store client id and client secret in your web.config, then you can use Azure Managed Identity to get authorized to use Azure Key Vault.
Here is an official tutorial: Use a Windows VM system-assigned managed identity to access Azure Key Vault
In this tutorial, it explains how the managed identity works and how to acquire a token for calling Azure Key Vault API.
And, in fact, you can directly use 'Microsoft.Azure.Services.AppAuthentication' package in your c# application. And then create KeyVaultClient
and get secret as following:
var azureServiceTokenProvider = new AzureServiceTokenProvider();
KeyVaultClient kvc = new KeyVaultClient(azureServiceTokenProvider.KeyVaultTokenCallback);
SecretBundle secret = kvc.GetSecretAsync(baseUrl, "testSecret").Result;
Console.WriteLine(secret.Value);
With Azure managed identity, you can add role assignment or access policy to it. Then, your Azure resource (VM or web app) with managed identity will be considered as trusted resource, and can get token from specific endpoint without any additional configuration.
Upvotes: 3