I try to grant permission for create resource group to service principal in my UWP C# project. I use Azure SDK for .NET to create confidential application registration and acquire access token. It is worked with my extension methods, to prevent platform check. But when I try to get role assignments for service principal, I receive Azure.RequestFailedException 0x80131500, "The subscription 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' could not be found".
ResourceIdentifier scope = new ResourceIdentifier($"/subscriptions/{MyTenantId}");
ConfidentialClientCredential credential = new ConfidentialClientCredential(MyConfidentialClientApplication);
ArmClient armClient = new ArmClient(credential);
RoleAssignmentCollection roleAssignmentCollection = AuthorizationExtensions.GetRoleAssignments(armClient, scope);
IEnumerable<RoleAssignmentResource> roleAssignments = roleAssignmentCollection?.GetAll($"$filter=atScope()+and+assignedTo('{strServicePrincipalId}')");
if(roleAssignments != null)
{
AuthorizationRoleDefinitionResource roleDefinition = null;
foreach(RoleAssignmentResource curRoleAssignment in roleAssignments) // <-- exception throws there
{
if(curRoleAssignment?.HasData == true && !string.IsNullOrWhiteSpace(curRoleAssignment.Data.RoleDefinitionId?.Name))
{
roleDefinition = await AuthorizationExtensions.GetAuthorizationRoleDefinitionAsync(armClient, scope, curRoleAssignment.Data.RoleDefinitionId);
}
}
}
I'm using my tenant ID here as my subscription ID because it was returned by the Azure CLI command:
az account show --query "id"
I guess that AAD RBAC can be used for this purpose, but I haven't found suitable AD permission.
Is there any way to grant permission for create resource group in my case?