Creating a service principal using the Azure CLI
Step 1.
First log into the Azure CLI
az login --use-device-code
Next lets get our <subscriptionId> guid:
az account show --query id --output tsv
Result:
EG: 929133e1-d1d4-4af3-a15d-f935b119ded9
Step 2.
We need to create a service principal that will do the deployments as we test in VS code.
az ad sp create-for-rbac --name <displayName> --skip-assignment
Result:
{
"appId": <appId>,
"displayName": <displayName>,
"password": <password>,
"tenant": <tenantId>
}
Step 3.
Lets assign some roles using the <appId> and the <subscriptionId> retrieved in the previous command.
# Assign the Contributor role
az role assignment create --assignee <appId> --role "Contributor" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Reader
az role assignment create --assignee <appId> --role "Reader" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Contributor
az role assignment create --assignee <appId> --role "Key Vault Contributor" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Crypto Officer
az role assignment create --assignee <appId> --role "Key Vault Crypto Officer" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Reader
az role assignment create --assignee <appId> --role "Key Vault Reader" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Secrets User
az role assignment create --assignee <appId> --role "Key Vault Secrets User" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Certificates Officer
az role assignment create --assignee <appId> --role "Key Vault Certificates Officer" --scope "/subscriptions/<subscriptionId>"
# Assign another role, e.g., Key Vault Administrator
az role assignment create --assignee <appId> --role "Key Vault Administrator" --scope "/subscriptions/<subscriptionId>"
Step 4.
On your development machine, log in as a service principal you just created.
az login
--service-principal
--username <appId>
--password <password>
--tenant <tenantId>
Step 5.
Verify your role assignments
az role assignment list --assignee <appId>
Comments
Post a Comment