Azure KeyVault with Key Rotation - azure

Our application doesn't use keyvault until now. We are thinking of using Azure KeyVault to enforce security for keys, secrets and certificates. I read microsoft documentation on this Link. It's not clear that Azure KeyVault works with identity providers other than Azure AD. Because we are not using Azure AD but we are using Azure app service and storage account. we also want to implement key rotation with 1 hour expiry.
My questions are
Should the web app be registered with Azure AD to use KeyVault ?
While creating an azure keyvault i didn't see any option about key rotation. Am i looking in the wrong place?
Any sample code would be helpful.

When you create a key vault in an Azure subscription, it is automatically associated with the subscription's Azure Active Directory tenant. All callers (users and applications) must be registered in this tenant to access this key vault. That means to access the keys and secrets stored inside the key vault, the requesting applications have to be added in Azure active directory and it also needs to have permissions to read keys and secrets in azure key vault.
Related tutorials below are for your reference :
Get started with Azure Key Vault
How to set up Key Vault with end to end key rotation and auditing -
This walks through how to set up key rotation and auditing with Azure
Key Vault.
Azure Key Vault Developer's Guide
Use Azure Key Vault from a Web Application

Related

How to auto renew Service Principals secrets in Azure

I have an issue how to auto renew Service Principals secrets in Key Vault Azure?
In short - you can't.
Azure KeyVault only provides the option to auto rotate keys. This feature enables end-to-end zero-touch key rotation for Azure services data encryption with customer-managed key (CMK) stored in Azure Key Vault.
https://azure.microsoft.com/en-us/updates/automated-key-rotation-in-azure-key-vault-is-now-available/
What you are trying to achieve is different. Azure AD Service principals are managed by Azure AD. So, you need some sort of automation which generates a new secret there and updates it in keyvault.
A better way (if possible) would be managed identity. Managed Identities can be used like service principals but a fully managed and the secrets are managed behind the scenes for you.
https://azure.microsoft.com/en-us/updates/automated-key-rotation-in-azure-key-vault-is-now-available/

Azure Key Vault Accessibility from different Azure subscriptions

Say if I have 2 different azure subscriptions individually and I create an azure vault and store a private key in it's HSM backed azure key vault container of the 1st subscription AND from different azure subscription I want to access the private key for signing an application..
Would that be possible?
In short, manage and store HSM backed key in one azure subscription and sign or validate an application with that private key from another azure subscription... is it possible?
Yes, It is possible when both the subscriptions are present on a Single tenant. So that you can assign required permissions on Management Plane and Data plane for the users or managed identities. As Managed HSM uses Azure AD authentication both the Subscriptions need to be in the same AzureAD tenant.
Reference:
Secure access to your managed HSMs Microsoft Documentation
Control Access to your managed HSM

Use Azure Key Vault from external web app

is it possible to use Azure Key Vault for web app, which is hosted somewhere else? I'm looking for the most cost-effective way, how to do that, so ideally I would like to use really just the Key Vault. I can allow external IP in Key vault -> Networking, but I don't see any possibilities how to set up access policy for external web app in the Key vault -> Access Policies.
Any experiences or ideas how to do that?
Thanks!
but I don't see any possibilities how to set up access policy for
external web app in the Key vault -> Access Policies.
One possible way to accomplish this would be to create a Service Principal in your Azure AD and give it access to your Key Vault (under Access Policies). Then you would use this Service Principal in your "external" web app to connect to the Key Vault.

Why don't azure portal has Azure Key Vault feature anymore while granting permissions to AD application?

I am trying to grant permissions to my Web App/API type application in Azure directory to use Azure Key Vault.
When I Required Permissions> Add API Access > Select an API, then there I can't find Azure Key Vault. I remember it was there before but not now. Where I can find it?
Image:
https://ibb.co/dswdXq
Behavior shown in your image - Azure Key Vault missing from "Select an API" blade
I have seen the behavior your image shows for a new Azure subscription, only when there were no Key Vaults so far in the Azure subscription linked to that Azure Active Directory.
Once you create a new Key Vault (you don't even need to add any keys), "Azure Key Vault" shows up while adding permissions to your app registrations in Azure AD (same steps as your image). At least, that's how it worked in my case.
Special case worth mention
You can create multiple Azure AD's in your Azure subscription and register your applications in any of them. Azure Key Vault although works in a special way and is linked to only one Azure AD, this is the Azure AD that your Azure subscription trusts (Azure Subscription also trusts only one Azure AD). So you could also run into the behavior shown in your image if you're registering application in a different Azure AD than the one your Azure subscription trusts.
Granting permissions to your Web App/API to use Key Vault
In most cases it's not even required to do the steps you're showing in your image, just for a web application to be able to access key vault since that is controlled by Azure Key Vault access policies. #junnas has already explained this part very well so you can refer to that.
You can go to your Key Vault -> Access Policies -> Add, and create a new policy for the app.
Select the app as the principal, and give it the access you want.
You don't need to touch the Authorized application option.
You should then be able to acquire tokens for Key Vault using the client id and secret (or certificate).
Key Vault does not require that you assign it to an app, unless you wanted to do delegated access.
In fact any app can acquire a token for any API that exists as a service principal in your tenant (and Key Vault does).
Of course the token itself won't contain any permissions, but Key Vault has their own access management (access policies).

how to assign key vault secrets only to that particular web app?

Assign secrets only to specific web app created in Azure. For Example: I have created one azure web app with MSI, created key vault with secrets for that app and I have given access to that app to get secrets. Now I have created another azure wep app with MSI, for this also I have created secrets and given key vault access. Now both the app can able to get secrets. But problem is, both app can access both secrets. I need to create app specific secrets. How to do in key vault ?
Create two Key Vaults.
You can't limit which secrets the app can access,
so having two vaults is the only way to isolate them.
You can check out pricing for Key Vault from here: https://azure.microsoft.com/en-us/pricing/details/key-vault/.
Billing for secrets is based on the amount of operations, so while two vaults won't use them as efficiently, the cost should not jump up in significant amounts.

Resources