|
| 1 | +param webAppPrincipalId string |
| 2 | +param apiAppPrincipalId string |
| 3 | +param keyVaultName string |
| 4 | +param cosmosDbAccountName string |
| 5 | +param appConfigName string |
| 6 | + |
| 7 | +// --------------------------------------------------------------------------- |
| 8 | +// Role definition IDs (built-in) |
| 9 | +// --------------------------------------------------------------------------- |
| 10 | + |
| 11 | +var keyVaultSecretsUserRoleId = '4633458b-17de-408a-b874-0445c86b69e0' |
| 12 | +var appConfigDataReaderRoleId = '516239f1-63e1-4d78-a4de-a74fb236a071' |
| 13 | + |
| 14 | +// Cosmos DB Built-in Data Contributor is a Cosmos DB SQL role, not a standard |
| 15 | +// Azure RBAC role — its ID is a well-known constant. |
| 16 | +var cosmosBuiltinDataContributorRoleId = '00000000-0000-0000-0000-000000000002' |
| 17 | + |
| 18 | +// --------------------------------------------------------------------------- |
| 19 | +// Existing resource references |
| 20 | +// --------------------------------------------------------------------------- |
| 21 | + |
| 22 | +resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' existing = { |
| 23 | + name: keyVaultName |
| 24 | +} |
| 25 | + |
| 26 | +resource cosmosDbAccount 'Microsoft.DocumentDB/databaseAccounts@2024-05-15' existing = { |
| 27 | + name: cosmosDbAccountName |
| 28 | +} |
| 29 | + |
| 30 | +resource appConfigStore 'Microsoft.AppConfiguration/configurationStores@2023-03-01' existing = { |
| 31 | + name: appConfigName |
| 32 | +} |
| 33 | + |
| 34 | +// --------------------------------------------------------------------------- |
| 35 | +// Key Vault — Secrets User for both apps |
| 36 | +// --------------------------------------------------------------------------- |
| 37 | + |
| 38 | +resource webAppKeyVaultRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 39 | + name: guid(webAppPrincipalId, keyVaultSecretsUserRoleId, keyVault.id) |
| 40 | + scope: keyVault |
| 41 | + properties: { |
| 42 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', keyVaultSecretsUserRoleId) |
| 43 | + principalId: webAppPrincipalId |
| 44 | + principalType: 'ServicePrincipal' |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +resource apiAppKeyVaultRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 49 | + name: guid(apiAppPrincipalId, keyVaultSecretsUserRoleId, keyVault.id) |
| 50 | + scope: keyVault |
| 51 | + properties: { |
| 52 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', keyVaultSecretsUserRoleId) |
| 53 | + principalId: apiAppPrincipalId |
| 54 | + principalType: 'ServicePrincipal' |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// --------------------------------------------------------------------------- |
| 59 | +// App Configuration — Data Reader for both apps |
| 60 | +// --------------------------------------------------------------------------- |
| 61 | + |
| 62 | +resource webAppConfigRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 63 | + name: guid(webAppPrincipalId, appConfigDataReaderRoleId, appConfigStore.id) |
| 64 | + scope: appConfigStore |
| 65 | + properties: { |
| 66 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', appConfigDataReaderRoleId) |
| 67 | + principalId: webAppPrincipalId |
| 68 | + principalType: 'ServicePrincipal' |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +resource apiAppConfigRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = { |
| 73 | + name: guid(apiAppPrincipalId, appConfigDataReaderRoleId, appConfigStore.id) |
| 74 | + scope: appConfigStore |
| 75 | + properties: { |
| 76 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', appConfigDataReaderRoleId) |
| 77 | + principalId: apiAppPrincipalId |
| 78 | + principalType: 'ServicePrincipal' |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// --------------------------------------------------------------------------- |
| 83 | +// Cosmos DB — Built-in Data Contributor for API only |
| 84 | +// (Blazor is a frontend and talks to the API via HTTP, not Cosmos DB directly) |
| 85 | +// --------------------------------------------------------------------------- |
| 86 | + |
| 87 | +resource apiCosmosRole 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2024-05-15' = { |
| 88 | + parent: cosmosDbAccount |
| 89 | + name: guid(apiAppPrincipalId, cosmosDbAccount.id, cosmosBuiltinDataContributorRoleId) |
| 90 | + properties: { |
| 91 | + roleDefinitionId: '${cosmosDbAccount.id}/sqlRoleDefinitions/${cosmosBuiltinDataContributorRoleId}' |
| 92 | + principalId: apiAppPrincipalId |
| 93 | + scope: '/' |
| 94 | + } |
| 95 | +} |
0 commit comments