Azure Keyvault to access resources from different azure subscriptions - azure

I am trying to use azure keyvault in my MVC application to get storage account keys. This MVC application is hosted in different azure subscriptions with storage accounts belonging to those subscriptions. Is it possible to have a one Azure Keyvault resource in any subscription and serve keys for storage accounts residing in different subscriptions?

Yes it is possible.
You will need to make identities for the apps using the Key Vault in the Azure AD tenant where the Key Vault's subscription is. And then assign permissions to access the vault to those service principals.
Then you can put the client id, client secret and tenant id to the apps that need to access the Key Vault. They should then be able to call it, since they have an identity that is allowed access. Key Vault uses an HTTP API so whether the apps and the vault are in the same subscription/data center/cloud provider is irrelevant.

Hi you can use below to do via azure CLI
az webapp config ssl import -n 'webappname' -g 'webappresourcegroup' --key-vault "/subscriptions/[provide subscriptionID]/resourceGroups/[Provide resource group Name]/providers/Microsoft.KeyVault/vaults/[Provide Vault Name] --key-vault-certificate 'Provide certificate Name'

Related

How to Access Azure Data Factory if we disable public access for keyvault

So how we can fetch the secrets or keys for Azure Data Factory , logic apps, Azure Synapse and Azure DataBricks if we disable the public access for keyvault.
I found a solution for AppServices and FunctionApps by using outbound IP Addresses and i need a solution for accessing the ADF,synapse,logicapps and databricks if we disable public access for keyvault.
I tried using Service Principal and grant permissions but its not working.
Please help me with the solution.
Even if you disable public access, you can still leave "Allow trusted Microsoft services to bypass this firewall" on, and so allow the MS services you mention to have access.
You can also create a private endpoint, and so add the key vault to your private Vnet.
All of this is related to networking - not being blocked by a firewall. You also need to grant permission to the service you use to access key vault, for example, with service principle or managed identity.
I tried to reproduce the same in my environment to access Azure key Vault with Private Endpoint:
I have created Vnet with required configuration.
Subnet and AddressSpace
Azure Portal > Virtual networks > Create
Create key-vault with private endpoint.
Azure Portal > Key vaults > Create a key vault
Note under Network section uncheck public access.
once create the Keyvault, check the private endpoint provisioning status, like below.
If you are trying to access the Azure Keyvault from public internet, you will get unauthorized error, like below.
Azure Keyvault is accessible with private network, like below.
For accessing Azure Datafactory using Azure keyvault, Assign service principal.
Required Role: Key Vault Reader
Keyvault access policy is assigned to ADF managed Identity.
Ex: hellotestdata
You can add Azure Key vault as a linked service in the Azure Data factory. the managed identity of the ADF that has access to key vault can be used for connecting ADF to Azure Key vault like below.
Azure Key Vault is successfully linked to ADF.
Reference:
Store credentials in Azure Key Vault

Unable to import key vault certificate to app service - Failed to get App Service Service principal details

I have a SSL cert in my Azure key vault that I am trying to import to the correct App Service.
I am the owner of the Azure subscription and I have given the App Service GET and LIST permissions for certificates on the vault.
On my App Service I click TLS/SSL settings > Private Key Certificates (.pfx) > Import Key Vault Certificate
This is the message I receive
Another owner on the subscription is able to complete this process successfully. So I am not sure why I am not able to when we both have owner roles on the subscription?
Is anyone able to offer any suggestions please?
When you are trying the operation from Azure Portal and you are a Owner of the Subscription, then Azure by default adds a access policy for the Azure APP Service Resource Provider and you do not further require to add the any access policies for the Web App.
Example:
I created a Web App with system managed identity and a Key vault with the below added Access Policies. I am an Owner of the Subscription and a User in the Azure Active Directory.
When , I perform the import certificate operation in the TLS/SSL Settings, the access policy get automatically updated with the Azure App Service Service Principal Credential.
In your case its not able to find the details of the Resource Provider Service Principal. As a Solution you can try adding Microsoft.Azure.CertificateRegistration (i.e. ObjectId : ed47c2a1-bd23-4341-b39c-f4fd69138dd3) , Microsoft Azure App Service (Internal) (i.e. ObjectId : 505e3754-d8a9-4f8b-97b6-c3e48ac7a543) & Microsoft Azure App Service (i.e. ObjectId : f8daea97-62e7-4026-becf-13c2ea98e8b4) in access policy for key vault.
Note: If the Issue is still not resolved , Please reach out to Azure Support for better assistance.

How to access Azure storage account Via Azure Key Vault by service principal

I have an external web application which has the option to access a storage account using the service principal.
I want to access Azure storage account/blob by the external application loading the data directly into the datalake account.
So here is what I am trying to do:
Set up a service principal (using Azure AD app registration)
Create a Storage account and store the access key in Azure Key Vault.
Add the service principal secret to the same key vault.
Create a policy within Key vault for the service principal to have access to read Keys and Secrets within Key Vault.
Also create a policy within Key Vault for service principal to have contributor role to access storage account.
Also grant access to storage account container to service principal.
But I cannot connect, and I am unable to authorize the connection.
I am confused on which steps I am missing to resolve this.
As you want to access the storage account using service principal, you do not need to store the storage account access in the key vault.
The steps you can follow up to access storage account by service principal:
Create a service principal (Azure AD App Registration)
Create a storage account
Assign Storage Blob Data Contributor role to the service principal
Now you would be able to access the Azure Storage Blob data using your service principal
Note: You do not need to store the service principal client secret in the key vault. Because you need the client secret again to access the key vault first.
Thanks #RamaraoAdapa-MT
This works
Finally, I setup like you said,,
SAS -> service principle -> permission to storage account -> storage account.
In this case, no need for Key vault.
Thanks you Guys,
Anupam Chand, RamaraoAdapa-MT

How to use managed identity to access key vault on different subscription of same tenant?

Have my Azure VM scale set on subscription1 of tenantA & assigned user managed identity which also belongs to subscription1 of tenantA.
Now I have keyvault on subscription2 of tenantA(same tenant). The keyvault hold secrets which the apps on Azure VM scale set on subscription1 needs to access.
It is possible to add managed identity Azure VM scale set on subscription1 to the access policy of the keyvault on subscription2 of same tenant as per the below answer.
Is it possible to add managed identity Azure VM scale set on subscription1 to the access policy of the keyvault on subscription2 of different directory/tenant?
Yes.
A Managed Identity creates a service principal in the Azure AD tenant of its subscription.
That service principal can be granted access to anything within that Azure AD tenant, including all subscriptions linked to it.

Azure Application Gateway, how to link to SSL Cert on a different Azure Subscription?

I have an Azure Application Gateway in subscription A and a wildcard ssl cert in a Keyvault in subscription B, both under the same tenant. Is it possible to link this certificate to this application gateway?
Continuing on from #andriy-bilous, creating a Managed Identity for an Azure Application Gateway so you can draw down certificates from your Azure Key Vault is pretty simple.
Create the Managed Identity:
Go to Azure Portal.
Select the search bar at the top, then search for and select "Managed Identities".
Select Create.
Enter your new managed identity the relivant Resource Group and Region, and a unique Name.
Now, Review + create, then Create.
Assign the rights to the Managed Identity in your Key Vault:
Go to your Key Vault.
Under Settings, select Access policies.
Select + Add Access Policy.
Under the Secret permissions dropdown, select Get.
Next to Select principal, select None selected.
Search for the Managed Indentity you just created, and Select.
Finally, click Add and you're done.
Head on over to your Application Gateway, and there will be a Managed Idenity for the Key Vault and setup your HTTPS certificates.
Also, as you've aleady got a VNET setup, adding your Key Vault to the VNET via a Private Endpoint is a great idea.
Yes it is possible.
Application Gateway integration with Key Vault requires a three-step configuration process:
Create a user-assigned managed identity
Configure your key vault
Configure the application gateway
https://learn.microsoft.com/en-us/azure/application-gateway/key-vault-certs#how-integration-works
We ran into the same issue. As of Nov 2021, based on the documentation, the Key Vault instance must be in the same subscription as Application Gateway.
Azure Application Gateway currently supports only Key Vault accounts in the same subscription as the Application Gateway resource. Choosing a key vault under a different subscription than your Application Gateway will result in a failure.

Resources