R Wood
R Wood

Reputation: 167

Can I create an Azure role assignment with wild card access?

I would like to have a service principal that can regenerate keys for service buses. Unfortunately, my organization is over their limit for custom role creation. I was hoping to give "Contributor" access to all service buses in the subscription, but I can't find a way to do it. Is there a way to accomplish this with something like wild cards? Like this:

az role assignment create --assignee (service-principal) --role Contributor --scope "/subscriptions/(subscription)/resourceGroups/\*/providers/Microsoft.ServiceBus/namespaces/\*"

I can't find a built-in role related to service buses like there is for storage accounts with the "Storage Account Key Operator Service Role".

Any help would be appreciated. Thanks!

Upvotes: 2

Views: 1392

Answers (1)

Joy Wang
Joy Wang

Reputation: 42063

The Azure CLI seems not to support wildcard in --scope, if you want to give your service principal a Contributor role for all the service buses in the subscription, my workaround is to do that via Azure Powershell, you could refer to the command below, it works fine on my side.

$ResourceId = (Get-AzureRmResource -ResourceType Microsoft.ServiceBus/namespaces).ResourceId
foreach($rid in $ResourceId){
    New-AzureRmRoleAssignment -ObjectId <Service Principal ObjectId> -Scope $rid -RoleDefinitionName Contributor
}

Upvotes: 2

Related Questions