Azure Roles

Setting up azure roles on subscriptions:


# Log out and clear
az logout
az account clear

# Login as your global/high-privileged account to start creating service principals
az login

# Set base variables so we can create RBAC
export ROLE="owner" # this is overly privileged, so you should choose something more specific for your needs
export SP_NAME="your-service-principal-name"
export SUBSCRIPTION_ID="your-subscription-id"

az ad sp create-for-rbac \
  --name $SP_NAME \
  --role $ROLE \
  --scopes /subscriptions/$SUBSCRIPTION_ID

# Export variables to environment so the programmatic user can be used
export AZURE_SUBSCRIPTION_ID=$SUBSCRIPTION_ID
export AZURE_TENANT_ID='your-tenant-id'
export AZURE_CLIENT_ID='qwerty' # appId from create-for-rbac step
export AZURE_CLIENT_SECRET='qwerty' # password from create-for-rbac step


export SP_ROLE_ID="some-app-id" # appId from create-for-rbac step
export ROLE="owner" # this is overly privileged, so you should choose something more specific for your needs
export SUBSCRIPTION_ID="your-subscription-id"

Create Role Assignment Manually

Using script to Get user assignments:

Get Role Assignemnts

Last updated

Was this helpful?