I have an Azure Durable function, that runs some PowerShell code.
The code takes the Application Id from a newly created Application Account and grants it Contributor access on a resource group.
The code looks like this:
$param = @{
ApplicationId = $SpnAppId
RoleDefinitionName = 'Contributor'
ResourceGroupName = $ResourceGroupName
ErrorAction = 'Stop'
}
New-AzRoleAssignment @param
I have the code running in 2 different tenants. In both tenants I can run an interactive PowerShell console with the credentials of the Application account running the function session and add the newly created Application Account as Contributor on the resource group. Both Application Accounts tunning the functions have Directory.Read.All(Application) and Owner on the subscriptions containing the resource groups.
The strange thing is, that in one tenant the function grants the Contributor role to the Application Account on the resource group as expected, when running the function, in the other tenant it does not.
What could cause a function to fail with ERROR: Insufficient privileges to complete the operation
in one tenant and not in the other, given that the operation succeeds in both tenants when run interactively?