Service principal role assignment fails with "can't find" error
Describe the bug When attempting to assign permissions to my AKS service principal, it fails with "Cannot find user or service principal in graph database for 'msi'. If the assignee is an appId, make sure the corresponding service principal is created with 'az ad sp create --id msi'" - even though I have confirmed that this is the correct service principal ID.
To Reproduce Run the following: CLIENT_ID=$(az aks show --resource-group aks-rg-name --name aks-name --query "servicePrincipalProfile.clientId" --output tsv) echo $CLIENT_ID #to make sure the above command worked az role assignment create --assignee $CLIENT_ID --role "Network Contributor" --scope /subscriptions/mysubID/resourceGroups/rg-name/providers/Microsoft.Network/virtualNetworks/myvnetname
Expected behavior The role assignment to complete.
Environment summary Running PowerShell on Windows with latest CLI version (2.11).
Additional context I'm attempting to assign Network Contributor permissions to my Azure CNI configured AKS cluster so I can create an internal load balancer, as documented here https://docs.microsoft.com/en-us/azure/aks/internal-lb#use-private-networks
@tdevopsottawa Why is this closed? I encountered the same issue, apparently the servicePrincipalProfile.clientId is not even registered in AAD App registrations!
using this cmd as instructed in lab...
aks create --resource-group akshandsonlab --name
Experiencing the same. @tdevopsottawa why did you close the issue?
Same issue, why is this closed?
Same issue, why is this closed?
@tdevopsottawa
I just had this same error. You could try reversing the order and create the ACR First, then attach it to the AKS on creation as shown here: https://docs.microsoft.com/en-us/azure/aks/cluster-container-registry-integration
The set of the principle still errs out, but you should be able to then leverage the acr from your aks cluster.
I have this same error, attempting
az ad sp create-for-rbac -n "my-service-principle-name-svp" --role="Contributor" --scopes="$(az group show --name my-rg-northcentralus --query id -o tsv)"
az role assignment create --assignee "$(az ad sp list --display-name "my-service-principle-name-svp" --query '[0].appId')" --role "Contributor" --scope "$(az group show --name other-rg-northcentralus --query id -o tsv)"
Cannot find user or service principal in graph database for '"7b5fddf2-722c-4186-bd3c-110ae5a4569b"'. If the assignee is an appId, make sure the corresponding service principal is created with 'az ad sp create --id "7b5fddf2-722c-4186-bd3c-110ae5a4569b"'.
7b5fddf2-722c-4186-bd3c-110ae5a4569b is "my-service-principle-name-svp", it does exist I was able make the role assignment successfully using Azure portal but want CLI for this
I'm running into the same problem: I want to create a role assignment via a yaml pipeline.
When creating the role assignment, or querying for the id of the principal using az ad sp show --id thename I get this error, although the pipeline has just created a resource (Azure Function) with the name 'thename'.
Same.
This appears to be a timing issue ... when I try the same command from the command line, about a minute or so after I get the error, the command runs successfully.
I'd rather not live with a sleep 60 in my script, so I'd be interested in a solution.
I had the same problem when using the normal login email address (like [email protected]) as the CLIENT_ID or AAD-ENTITY-ID for --assignee parameter. After using user principal name (like demo_email.com#EXT#@demoemail.onmicrosoft.com) it was successful. You can find the user principal name in azure portal in the users list.
Why is this closed? I am consistently experiencing the same issue when trying to assign a role directly after creating an App Registration and its Service Principal using the Azure CLI.
Is there possibly any way to wait until the Service Principal of the App Registration is available for role assignments or comparable actions?
@blgorman
Thanks I also had the same issue until I put all the role assignments after
subscriptionId=$(az account show --query id --output tsv) echo subscriptionId: $subscriptionId
subscriptionName=$(az account show --query name --output tsv) echo subscriptionName: $subscriptionName
tenantId=$(az account show --query tenantId --output tsv) echo tenantId: $tenantId
DO ROLE ASSIGNMENT HERE NOT BEFORE THE ABOVE
az role assignment create --assignee $PRINCIPAL --role "AcrPull" --resource-group $ResourceGroupName
az role assignment create --assignee $PRINCIPAL --role "AcrPush" --resource-group $ResourceGroupName
I just had this same error. You could try reversing the order and create the ACR First, then attach it to the AKS on creation as shown here: https://docs.microsoft.com/en-us/azure/aks/cluster-container-registry-integration
The set of the principle still errs out, but you should be able to then leverage the acr from your aks cluster.