Terraform Azure Service Principal into AKV - azure

I have an App in Azure with A client secret. The secret should be synced to an azure key vault. Since I don't want to have the spn secret as plain text i wondered if there was any better solution?

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/

Windows VM system-assigned managed identity to access Azure Key Vault in Typescript?

How we can get the Access to Azure key vault secrets from Typescript app.
We have access to the VM on which the application is running.
What are the steps and code we need to place in Type script react application to get azure key vault access?
It is not possible and not recommended to use Azure key vault in Typescript app. It is a security risk, as anyone can see your KeyVault connection details from browser console and access your secrets.
You should not access secured resources directly from client code.
https://www.npmjs.com/package/#azure/keyvault-secrets
Angular - Azure Key Vault Managing Vault Access secrets
https://learn.microsoft.com/en-us/answers/questions/318983/is-it-possible-to-use-key-vault-in-static-web-appl.html

Use Azure KeyVault in the B2C Custom Policy Config

We are using the email invite flow to get our users created in our Azure B2C. Currently we are reviewing our management of secrets in code and config, coming out of this work we are now using an Azure KeyVault.
Our ASP.Net website that previously had the cert loaded directly into the App Service is now referencing one in the key vault.
At the Azure B2C "Identity Experience Framework" end of the arrangement we have the “B2C_1A_IdTokenHintCert” policy key and that was created when we uploaded the certificate into Azure B2C. This breaks the approach of centralising the management of our certificates with KeyVault.
Is there a way of using KeyVault for the Custom Policy configuration?
In your particular scenario, you can expose your own metadata endpoint for id token hint validation in your App. That is what the sample does by default:
https://github.com/azure-ad-b2c/id-token-builder
You might then look for a way to reference the cert via key vault instead of uploading the cert to the app service. Eg reading the cert in your app via keyvault api.
https://learn.microsoft.com/en-us/rest/api/keyvault/#certificate-operations

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.

Azure KeyVault with Key Rotation

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

Resources