How do I grant acrPull access to AKS using bicep? #3181
-
I have an existing ACR instance and am creating a new AKS resource via Bicep that I want to assign the acrPull role to. The role assignment happens but AKS gets auth errors trying to pull images. If instead I grant ACR access via "az aks update --attach-acr" everything works fine. I'm using two modules, one to create the AKS resource and one to assign the role:
The end result is ACR has a role assignment to my AKS cluster, showing in the Portal as type "App", which I believe means Managed Identity, but AKS can't pull images. If I set this all up via "az aks update --attach-acr" everything works fine, with the visible difference being that the role assignment it creates is for my AKS agentpool managed identity as opposed to AKS cluster's identity. The agentpool is part of an AKS nodes resource group that's created alongside my AKS resource group, and I don't understand how to reference that from bicep. Any idea what I'm doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
This is the docs... https://docs.microsoft.com/en-us/azure/aks/use-managed-identity#summary-of-managed-identities It's the Kublet identity that needs the role assignment against ACR. . . you can also BYO User assigned identity here as well, that way you can perform the Role assignment prior to deploying the AKS cluster. This should be helpful to get the principal identity that you are looking for // using this as an exampple, you already have your template for this
resource myAKS 'Microsoft.ContainerService/managedClusters@2021-03-01' existing = {
name: 'aksapp01'
}
// I don't have a cluster up right now to test if you need 'properties there' ... so I am not sure if that path is accurate, however it should be close.
output principalID2 string = myAKS.properties.identityProfile.kubeletidentity.objectId
// this is another way, that i decompiled from working JSON, however could be turned to more 'bicep' as above to simplify, i added this because i know the path is correct in this case.
output principalID1 string = reference('Microsoft.ContainerService/managedClusters/myaks', '2020-12-01').identityProfile.kubeletidentity.objectId I believe you example was using the identity of the system assigned managed identity of the cluster itself? You can also BYO with that one as well, via user assigned identity, however that is besides the point here. |
Beta Was this translation helpful? Give feedback.
-
What is the value of |
Beta Was this translation helpful? Give feedback.
-
I saw another example here , I think it is for assigning a rbac role at the subscription level (scope) using subscriptionresourceid function. |
Beta Was this translation helpful? Give feedback.
This is the docs...
https://docs.microsoft.com/en-us/azure/aks/use-managed-identity#summary-of-managed-identities
It's the Kublet identity that needs the role assignment against ACR. . . you can also BYO User assigned identity here as well, that way you can perform the Role assignment prior to deploying the AKS cluster.
This should be helpful to get the principal identity that you are looking for