I am building an Azure Managed Application for deployment via the Azure Marketplace into customer tenants. The managed resource group includes both a Key Vault and an App Service. In the Key Vault, an SSL certificate is stored that I need to bind to the App Service.
I have assigned a user-assigned managed identity to the App Service and granted it access in the Key Vault's access policy. However, I also need to grant 'get' permissions for certificates and secrets to the service principal of the Microsoft Azure App Service resource provider (documentation here: https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate?tabs=apex%2Caccesspolicy#import-a-certificate-from-key-vault).
The challenge is that the required objectId for the access policy must be that of the service principal, and this objectId differs in every customer tenant. I only have the well-known applicationId (abfa0a7c-a6b6-4736-8310-5855508787cd) for the resource provider, which is constant across Azure. How can I dynamically obtain or reference the correct objectId for each tenant?
resource keyVault 'Microsoft.KeyVault/vaults@2023-02-01' = {
name: keyVaultName
location: location
properties: {
enabledForDeployment: false
enabledForDiskEncryption: false
enabledForTemplateDeployment: true
enableRbacAuthorization: false
tenantId: tenantId
enableSoftDelete: true
softDeleteRetentionInDays: 90
sku: keyVaultSku
networkAcls: {
defaultAction: 'Allow'
bypass: 'AzureServices'
}
accessPolicies:[
{
objectId: keyVaultReferenceIdentity.properties.principalId
permissions: {
certificates: [
'get', 'list', 'getissuers', 'listissuers', 'update', 'create', 'import'
]
keys: [
'get', 'list', 'decrypt', 'unwrapKey', 'verify', 'getrotationpolicy', 'update', 'create', 'import'
]
secrets: [
'get', 'list', 'set'
]
}
tenantId: tenantId
}
{
objectId: //what can I put here for the Microsoft Azure App Service resource provider?
permissions:{
certificates: ['get']
secrets:['get']
}
tenantId: tenantId
}
]
}
}
resource keyVaultReferenceIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
name: keyVaultReferenceIdentityName
location: location
}