|
1 | 1 | ---
|
2 |
| -title: Service principal cleanup and troubleshooting using Azure CLI | Microsoft Docs |
3 |
| -description: Learn how to cleanup and troubleshoot service principals. |
4 |
| -ms.date: 09/19/2024 |
| 2 | +title: Cleanup & troubleshoot service principals using Azure CLI |
| 3 | +description: Learn how to clean up service principal resources and troubleshoot common Azure CLI errors, including permission, tenant, and authentication issues. |
5 | 4 | ms.service: azure-cli
|
6 | 5 | ms.custom: devx-track-azurecli
|
7 | 6 | keywords: azure service principal, create service principal azure, create service principal azure cli
|
8 | 7 | ---
|
9 | 8 |
|
10 | 9 | # Cleanup & troubleshoot service principals
|
11 | 10 |
|
12 |
| -Congratulations! You learned how to create, retrieve, and work with service principals! Now that you have completed the tutorial, it's time to clean up the created service principal resources. |
| 11 | +You learned how to create, retrieve, and work with service principals. Now that you completed the |
| 12 | +tutorial, it's time to clean up the created service principal resources. |
13 | 13 |
|
14 | 14 | ## Cleanup service principal resources
|
15 | 15 |
|
16 |
| -The safest way to remove all resources used in this tutorial is to use [az group delete](/cli/azure/group#az-group-delete). The `--no-wait` parameter keeps the CLI from blocking while the deletion takes place. |
| 16 | +The safest way to remove all resources used in this tutorial is to use [az group delete][08]. The |
| 17 | +`--no-wait` parameter keeps the CLI from blocking while the deletion takes place. |
17 | 18 |
|
18 | 19 | ```azurecli-interactive
|
19 | 20 | az group delete --name myResourceGroup --no-wait
|
20 | 21 | ```
|
21 | 22 |
|
22 |
| -If you prefer, delete individual service principals with the [az ad sp delete](/cli/azure/ad/sp#az-ad-sp-delete) command. |
| 23 | +If you prefer, delete individual service principals with the [az ad sp delete][07] command. |
23 | 24 |
|
24 | 25 | ```azurecli-interactive
|
25 | 26 | az ad sp delete --id myServicePrincipalID
|
26 | 27 | ```
|
27 | 28 |
|
28 | 29 | ## Troubleshoot service principals
|
29 | 30 |
|
30 |
| -Although you have completed the tutorial, you may still have questions regarding service principals that can be answered in this section. |
| 31 | +Although you completed the tutorial, you might still have questions regarding service principals |
| 32 | +that can be answered in this section. |
31 | 33 |
|
32 | 34 | ### Insufficient privileges
|
33 | 35 |
|
34 |
| -If your account doesn't have permission to create a service principal, `az ad sp create-for-rbac` returns an error message containing "Insufficient privileges to complete the operation." Contact your Microsoft Entra administrator to obtain `User Access Administrator` or `Role Based Access Control Administrator` permissions. |
| 36 | +If your account doesn't have permission to create a service principal, `az ad sp create-for-rbac` |
| 37 | +returns an error message containing "Insufficient privileges to complete the operation." Contact |
| 38 | +your Microsoft Entra administrator to obtain `User Access Administrator` or |
| 39 | +`Role Based Access Control Administrator` permissions. |
35 | 40 |
|
36 | 41 | ### Invalid tenant
|
37 | 42 |
|
38 |
| -If you have specified an invalid subscription ID, you see the error message "The request didn't have a subscription or a valid tenant level resource provider." If using variables, use the Bash `echo` command to see the value being passed to the reference command. Use [az account set](/cli/azure/account#az-account-set) to change your subscription or learn [How to manage Azure subscriptions with the Azure CLI](./manage-azure-subscriptions-azure-cli.md). |
| 43 | +If you specified an invalid subscription ID, you see the error message "The request didn't have a |
| 44 | +subscription or a valid tenant level resource provider." If using variables, use the Bash `echo` |
| 45 | +command to see the value being passed to the reference command. Use [az account set][06] to change |
| 46 | +your subscription or learn [How to manage Azure subscriptions with the Azure CLI][02]. |
39 | 47 |
|
40 | 48 | ### Resource group not found
|
41 | 49 |
|
42 |
| -If you have specified an invalid resource group name, you see the error message "Resource group 'name' couldn't be found." If using variables, use the Bash `echo` command to see the value being passed to both the subscription and reference commands. Use [az group list](/cli/azure/group#az-group-list) to see the resource groups for the current subscription, or learn [How to manage Azure resource groups with the Azure CLI](./manage-azure-groups-azure-cli.md). |
| 50 | +If you specified an invalid resource group name, you see the error message "Resource group 'name' |
| 51 | +couldn't be found." If using variables, use the Bash `echo` command to see the value being passed to |
| 52 | +both the subscription and reference commands. Use [az group list][09] to see the resource groups for |
| 53 | +the current subscription, or learn [How to manage Azure resource groups with the Azure CLI][01]. |
43 | 54 |
|
44 | 55 | ### Authorization to perform action
|
45 | 56 |
|
46 |
| -If your account doesn't have permission to assign a role, you see an error message that your account "does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write'." Contact your Microsoft Entra administrator to manage roles. |
| 57 | +If your account doesn't have permission to assign a role, you see an error message that your account |
| 58 | +"doesn't have authorization to perform action 'Microsoft.Authorization/roleAssignments/write'." |
| 59 | +Contact your Microsoft Entra administrator to manage roles. |
47 | 60 |
|
48 | 61 | ### Interactive authentication is needed
|
49 | 62 |
|
50 |
| - When signing in with password authentication, error message "...Interactive authentication is needed..." occurs if your organization requires multifactor authentication. Switch to certificate-based authentication, or consider using [managed identities](/azure/active-directory/managed-identities-azure-resources/overview). |
| 63 | +When signing in with password authentication, error message "...Interactive authentication is |
| 64 | +needed..." occurs if your organization requires multifactor authentication. Switch to |
| 65 | +certificate-based authentication, or consider using [managed identities][05]. |
51 | 66 |
|
52 | 67 | ### Compliant device required
|
53 | 68 |
|
54 |
| -If you try to create a service principal using a device that is not compliant with your organizations access policies, you will receive message "...Conditional Access policy requires a compliant device...". Switch to a computer that meets your organization's access policies. |
| 69 | +If you try to create a service principal using a device that's not compliant with your |
| 70 | +organization's access policies, you receive the message "...Conditional Access policy requires a |
| 71 | +compliant device...". Switch to a computer that meets your organization's access policies. |
55 | 72 |
|
56 | 73 | ## See also
|
57 | 74 |
|
58 |
| -* [Application and service principal objects in Microsoft Entra ID](/azure/active-directory/develop/app-objects-and-service-principals) |
59 |
| -* [Create a service principal using the Azure portal](/azure/active-directory/develop/howto-create-service-principal-portal) |
60 |
| -* [Create an Azure service principal with Azure PowerShell](/powershell/azure/create-azure-service-principal-azureps) |
| 75 | +- [Application and service principal objects in Microsoft Entra ID][03] |
| 76 | +- [Create a service principal using the Azure portal][04] |
| 77 | +- [Create an Azure service principal with Azure PowerShell][10] |
| 78 | + |
| 79 | +<!-- link references --> |
| 80 | + |
| 81 | +[01]: ./manage-azure-groups-azure-cli.md |
| 82 | +[02]: ./manage-azure-subscriptions-azure-cli.md |
| 83 | +[03]: /azure/active-directory/develop/app-objects-and-service-principals |
| 84 | +[04]: /azure/active-directory/develop/howto-create-service-principal-portal |
| 85 | +[05]: /azure/active-directory/managed-identities-azure-resources/overview |
| 86 | +[06]: /cli/azure/account#az-account-set |
| 87 | +[07]: /cli/azure/ad/sp#az-ad-sp-delete |
| 88 | +[08]: /cli/azure/group#az-group-delete |
| 89 | +[09]: /cli/azure/group#az-group-list |
| 90 | +[10]: /powershell/azure/create-azure-service-principal-azureps |
0 commit comments