Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EES-5382 use key vault RBAC for public api #5144

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,12 @@ var keyVaultPrincipalIds = userAssignedManagedIdentityParams != null
? [userAssignedManagedIdentityParams!.principalId]
: [functionApp.identity.principalId, stagingSlot.identity.principalId]

module functionAppKeyVaultAccessPolicy 'keyVaultAccessPolicy.bicep' = {
name: '${functionAppName}FunctionAppKeyVaultAccessPolicy'
module functionAppKeyVaultRoleAssignments 'keyVaultRoleAssignment.bicep' = {
name: '${functionAppName}FunctionAppKeyVaultRoleAssignment'
params: {
keyVaultName: keyVaultName
principalIds: keyVaultPrincipalIds
role: 'Secrets User'
}
}

Expand Down Expand Up @@ -457,7 +458,7 @@ module functionAppSlotSettings 'appServiceSlotConfig.bicep' = {
azureFileShares: azureFileShares
}
dependsOn: [
functionAppKeyVaultAccessPolicy
functionAppKeyVaultRoleAssignments
slot1FileShare
slot2FileShare
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@description('Specifies the name of the Key Vault.')
param keyVaultName string

@description('Specifies the id of the service principals that should inherit this Key Vault policy')
param principalIds string[]

@description('Specifies the Key Vault role to assign to the service principals. See https://docs.microsoft.com/azure/role-based-access-control/built-in-roles for possible roles to support here.')
@allowed([
'Secrets User'
])
param role string

@description('See https://docs.microsoft.com/azure/role-based-access-control/built-in-roles for possible roles to support here.')
var roleIds = {

'Secrets User': '4633458b-17de-408a-b874-0445c86b69e6'
}

resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' existing = {
name: keyVaultName
}

@description('Look up the built-in role definition')
resource roleDefinition 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {
scope: subscription()
name: roleIds[role]
}

@description('Grant the service principals the key vault role')
resource keyVaultSecretUserRoleAssignment 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = [for principalId in principalIds: {
scope: keyVault
name: guid(resourceGroup().id, principalId, roleDefinition.id)
properties: {
roleDefinitionId: roleDefinition.id
principalId: principalId
principalType: 'ServicePrincipal'
}
}]
Loading
Loading