Skip to content

Instantly share code, notes, and snippets.

@thepaulmacca
Last active September 24, 2024 17:53
Show Gist options
  • Save thepaulmacca/40c6916bebc1dee00e414615edef37d8 to your computer and use it in GitHub Desktop.
Save thepaulmacca/40c6916bebc1dee00e414615edef37d8 to your computer and use it in GitHub Desktop.
Bicep - Key Vault Secret User RBAC Role Assignment - App Service Identity
resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' existing = {
name: keyVaultName
}
@description('This is the built-in Key Vault Secret User role. See https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#key-vault-secrets-user')
resource keyVaultSecretUserRoleRoleDefinition 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
scope: subscription()
name: '4633458b-17de-408a-b874-0445c86b69e6'
}
@description('Grant the app service identity with key vault secret user role permissions over the key vault. This allows reading secret contents')
resource keyVaultSecretUserRoleAssignment 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = {
scope: keyVault
name: guid(resourceGroup().id, appService.id, keyVaultSecretUserRoleRoleDefinition.id)
properties: {
roleDefinitionId: keyVaultSecretUserRoleRoleDefinition.id
principalId: appService.identity.principalId
principalType: 'ServicePrincipal'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment