Assign RBAC role to Key Vault in other Resource Group (same subscription) #4793
-
I have a key vault containing certificates in another resource group, in the same subscription. I need to assign the This is what I have so far: roleAssignments.bicep param appGatewayFrontendIdentityName string
param ingressControllerPodIdentityName string
param keyVaultName string
param keyVaultResourceGroup string
resource appGatewayFrontendIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: appGatewayFrontendIdentityName
}
resource ingressControllerPodIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' existing = {
name: ingressControllerPodIdentityName
}
// Get existing key vault that contains the app gateway and ingress certificates
resource keyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = {
name: keyVaultName
scope: resourceGroup(keyVaultResourceGroup)
}
// Assign the Key Vault Secrets User Role to the App Gateway Frontend Managed Identity
resource appGatewayFrontendIdentityRoleAssignment 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = {
name: guid('Key Vault Secrets User', appGatewayFrontendIdentity.id, subscription().subscriptionId)
scope: keyVault
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
principalId: appGatewayFrontendIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
}
// Assign the Key Vault Secrets User role to the ingress controller pod managed identity, this allows our ingress controller to pull certificates
resource ingressControllerPodIdentityRoleAssignment 'Microsoft.Authorization/roleAssignments@2020-08-01-preview' = {
name: guid('Key Vault Secrets User', ingressControllerPodIdentity.id, subscription().subscriptionId)
scope: keyVault
properties: {
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
principalId: ingressControllerPodIdentity.properties.principalId
principalType: 'ServicePrincipal'
}
} main.bicep module keyVaultRoleAssignments 'modules/keyVaultRoleAssignments.bicep' = {
name: 'keyvault-roleassignments-${environmentName}-${resourceNameSuffix}'
scope: resourceGroup(keyVaultResourceGroup)
params: {
appGatewayFrontendIdentityName: appGatewayFrontendIdentityName
ingressControllerPodIdentityName: ingressControllerPodIdentityName
}
} It doesn't like the Can anyone assist please? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
given that your Module is already going to be executing this deployment in the 'keyVaultResourceGroup', you can remove that line with the // Get existing key vault that contains the app gateway and ingress certificates
resource keyVault 'Microsoft.KeyVault/vaults@2021-06-01-preview' existing = {
name: keyVaultName
// scope: resourceGroup(keyVaultResourceGroup)
} |
Beta Was this translation helpful? Give feedback.
-
I see, did you try adding the scope to the Another way to get the objectId that you need is to pull it directly from AKS.
|
Beta Was this translation helpful? Give feedback.
I see, did you try adding the scope to the
userAssignedIdentities
existing resource reference?Another way to get the objectId that you need is to pull it directly from AKS.
https://github.com/brwilkinson/AzureDeploymentFramework/blob/53492685ef6b86070d97cc46d40efb7946f95508/ADF/bicep/AKS-AKS-RBAC.bicep#L44
AKS.properties.addonProfiles.IngressApplicationGateway.identity.objectId