Azure Managed Application Publisher / ISV Access to Azure Key Vault in Managed Resource Group in Customer Subscription

In this article, we look at a scenario where Azure Managed Application publisher (aka Independent Software Vendor or ISV) needs to be able to use their publisher identity to create/delete secrets (e.g. connection string) in Azure Key Vault that is in the Managed Resource Group (MRG) in the customer’s Azure subscription so that other resources (e.g. Web Apps, VMs) running in the MRG can use these secrets.

Image for post
Image for post

Challenge

Azure Key Vault resource and its data-plane access policies are tied to a specific Azure Active Directory tenant (i.e. there is a tenantId property in Azure Key Vault resource) and resources deployed in the managed resource group in the customer subscription need to be able to use the secrets in Azure Key Vault. Therefore, Azure Key Vault must be tied to the customer’s tenant.

This means that publisher identity is not able to perform Azure Key Vault data-plane operations like create/delete/list/read secrets.

It is a bit of a “catch 22” situation:

  • Customer cannot access the Key Vault in the Managed Resource Group (MRG) in their subscription because Azure Managed Application has a Deny assignment on the MRG (which is the correct default behavior)
  • Publisher cannot access the Key Vault in the Managed Resource Group because the Key Vault is tied to the customer’s Azure AAD tenant (this is the challenge)

Potential Approaches

Publisher can “proxy” access to the Azure Key Vault data-plane API in the Managed Resource Group (MRG) through either of:

Publisher can also set secrets in the end-customer’s Azure Key Vault using ARM control-plane APIs by using Microsoft.KeyVault/vaults/secrets write action which publisher’s identity can perform via ARM if it has “Contributor” or “Key Vault Contributor” role on the Azure Key Vault resource. This create-key-vault-secret ARM template shows how publisher (or Azure Lighthouse provider) can create the secret using ARM template deployment

Pseudocode for data-plane Managed Identity “proxy” approach

Below is the pseudocode of the “proxy” approach using Managed Application identity.

Step 1: In createUiDefinition.json add a step with Microsoft.ManagedIdentity.IdentitySelector control and have it always select “System Assigned = On” (example)

Step 2: After the application deploys, use publisher identity to get the principalId of the Managed Application’s System-Assigned Identity

Step 3: Use publisher identity to modify Azure Key Vault access policies by adding the principalId of the Managed Application identity to the allowed list (including only the permissions that the publisher needs — e.g. set)

Step 4: Use publisher identity to get Managed Application access token (as described here) for calling Azure Key Vault data-plane REST API

Step 5: Use Azure Key Vault data-plane REST API to set/get/list tokens by passing the access token obtained above in the Authorization header

Currently, steps 2 and 3 cannot be performed in the mainTemplate.json of the Managed Application itself because we cannot get its identity.principalId via the reference() function since reference() implies a dependsOn and causes a deadlock on itself. Therefore, steps 2 and 3 show how to obtain the principalId and change the Key Vault access policy imperatively after the deployment completes (i.e. publisher can configure web hook notification for managed apps).

Thank you!

Please leave feedback and questions below or on Twitter https://twitter.com/ArsenVlad

Written by

Principal Engineer / Architect, FastTrack for Azure at Microsoft

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store