Set up an Azure Key Vault connection in Microsoft Foundry
This article refers to the Microsoft Foundry (new) portal.
Prerequisites
- An Azure subscription.
- A Foundry resource with no existing connections at the resource or project level.
- An Azure Key Vault in your subscription, or permissions to create one.
- One of the following Azure RBAC roles on your Key Vault:
- Key Vault Secrets Officer (minimal permissions)
- Key Vault Contributor
- Key Vault Administrator
Limitations
Create Azure Key Vault connections only when you need them. If you bring your own Azure Key Vault, review these limitations:- Limit Azure Key Vault connections to one per Foundry resource. Delete an Azure Key Vault connection only if no other connections exist at the Foundry resource or project level.
- Foundry doesn’t support secret migration. Remove and recreate connections yourself.
- Deleting the underlying Azure Key Vault breaks the Foundry resource. Azure Key Vault stores secrets for connections that don’t use Microsoft Entra ID. Any Foundry feature that depends on those connections stops working.
- Deleting connection secrets that your Foundry resource stores in your bring your own (BYO) Azure Key Vault can break connections to other services.
Use a Bicep template
Deploy a Key Vault connection by using Azure Bicep. The following template creates a connection between your Foundry resource and an existing Azure Key Vault, and assigns the Key Vault Secrets Officer role to the Foundry resource’s managed identity.Reference
- Microsoft.CognitiveServices/accounts/connections
- Microsoft.Authorization/roleAssignments
- Key Vault Secrets Officer role
Key Vault connection management
Creation
Make sure no other connections exist at the Foundry resource or project level. The service blocks Key Vault connection creation if other connections exist. If the UI doesn’t show a Key Vault connection category when you choose a connection, this problem might be the reason. Delete other connections, and then try again. When you create a Key Vault connection, the service doesn’t use the managed Key Vault in Azure.Deletion
Before you delete an Azure Key Vault connection from Foundry, remove all other connections. After you remove all other connections at the Foundry resource and project levels, delete the Key Vault connection. Foundry doesn’t support secret migration.Update or change
To switch from Azure Key Vault 1 to Azure Key Vault 2, delete the Azure Key Vault 1 connection, and then create the Azure Key Vault 2 connection. Follow the deletion and creation steps, and manually recreate any connection secrets.Key Vault secret lifecycle
When you delete connections from your managed Key Vault, the corresponding secrets are deleted. Deleting a Key Vault connection also deletes its secrets.Granting Foundry access to your key vault
Depending on how your key vault is provisioned, you might need to apply additional permissions. Check whether your Azure Key Vault uses role-based access control (RBAC) or access policies, and then continue.Role-based access control (RBAC)
After you create the Key Vault connection, assign an appropriate RBAC role in the Azure portal. Key Vault Contributor and Key Vault Administrator are two roles that work. For minimal permissions, use the Key Vault Secrets Officer.Access policies
Similar to RBAC roles, assign the appropriate key vault access policy (if applicable) to the Foundry resource’s managed identity.Infrastructure as code templates
As a best practice, when setting up ARM, Bicep, or Terraform templates to create resources, make sure the Azure Key Vault connection is the first connection you create, and make all other connections depend on the Key Vault connection succeeding. This order helps reduce Key Vault connection failures. If you don’t follow this best practice, your templates can encounter race conditions across your connections. As a result, deployments can work sometimes and fail at other times because Foundry doesn’t support secret migration. After you create the Foundry resource and the Key Vault connection, assign the appropriate RBAC roles to the Foundry resource. Make all other connections depend on this role assignment succeeding. The same applies if your Key Vault uses access policies instead of RBAC.Follow this order in your infrastructure as code templates
- Create the Foundry resource.
- Create a Foundry project.
- Create the Azure Key Vault connection.
- Assign the appropriate RBAC role on the Key Vault for the Foundry resource.
- (Optional) Validate that the RBAC role takes effect.
- Create any other connections at the resource or project level, and set the
dependsOnfield for steps 3 and 4.
Deletion
For cleanup, if you automate resource deletion by using templates, follow the creation steps in reverse order:- Delete all connections at the Foundry resource or project level.
- Delete the Azure Key Vault connection.
- Delete all Foundry projects.
- Delete the Foundry resource.