Skip to content

Commit 81c6aa0

Browse files
xiangyan99mccoypchlowell
authored
add troubleshoot doc (#20684)
* add troubleshoot doc * fix typo * update * update * update * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: McCoy Patiño <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update sdk/identity/azure-identity/Troubleshoot.md Co-authored-by: Charles Lowell <[email protected]> * Update Troubleshoot.md * update error log Co-authored-by: McCoy Patiño <[email protected]> Co-authored-by: Charles Lowell <[email protected]>
1 parent 87e0f99 commit 81c6aa0

File tree

11 files changed

+262
-11
lines changed

11 files changed

+262
-11
lines changed
Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
# Troubleshooting Azure Identity Authentication Issues
2+
3+
The Azure Identity SDK offers various `TokenCredential` implementations. These implementations typically throw `CredentialUnavailableError` and `ClientAuthenticationError` exceptions.
4+
The `CredentialUnavailableError` indicates that the credential cannot execute in the current environment setup due to lack of required configuration.
5+
The `ClientAuthenticationError` indicates that the credential was able to run/execute but ran into an authentication issue from the server's end. This can happen due to invalid configuration/details passed in to the credential at construction time.
6+
This troubleshooting guide covers mitigation steps to resolve these exceptions thrown by various `TokenCredential` implementations in the Azure Identity Python client library.
7+
8+
## Table of contents
9+
10+
- [Troubleshooting Default Azure Credential Authentication Issues](#troubleshooting-default-azure-credential-authentication-issues)
11+
- [Troubleshooting Environment Credential Authentication Issues](#troubleshooting-environment-credential-authentication-issues)
12+
- [Troubleshooting Service Principal Authentication Issues](#troubleshooting-service-principal-authentication-issues)
13+
- [Troubleshooting Username Password Authentication Issues](#troubleshooting-username-password-authentication-issues)
14+
- [Troubleshooting Managed Identity Authentication Issues](#troubleshooting-managed-identity-authentication-issues)
15+
- [Troubleshooting Visual Studio Code Authentication Issues](#troubleshooting-visual-studio-code-authentication-issues)
16+
- [Troubleshooting Azure CLI Authentication Issues](#troubleshooting-azure-cli-authentication-issues)
17+
- [Troubleshooting Azure Powershell Authentication Issues](#troubleshooting-azure-powershell-authentication-issues)
18+
19+
## Troubleshooting Default Azure Credential Authentication Issues
20+
21+
### Credential Unavailable Error
22+
23+
The `DefaultAzureCredential` attempts to retrieve an access token by sequentially invoking a chain of credentials. The `ClientAuthenticationError` in this scenario signifies that all the credentials in the chain failed to retrieve the token in the current environment setup/configuration. You need to follow the configuration instructions for the respective credential you're looking to use via `DefaultAzureCredential` chain, so that the credential can work in your environment.
24+
25+
Please follow the configuration instructions in the `Credential Unavailable Error` section of the troubleshooting guidelines below for the respective credential/authentication type you want to use via `DefaultAzureCredential`:
26+
27+
| Credential Type | Troubleshoot Guide |
28+
| --- | --- |
29+
| Environment Credential | [Environment Credential Troubleshooting Guide](#troubleshooting-environment-credential-authentication-issues) |
30+
| Managed Identity Credential | [Managed Identity Troubleshooting Guide](#troubleshooting-managed-identity-authentication-issues) |
31+
| Visual Studio Code Credential | [Visual Studio Code Troubleshooting Guide](#troubleshooting-visual-studio-code-authentication-issues) |
32+
| Azure CLI Credential | [Azure CLI Troubleshooting Guide](#troubleshooting-azure-cli-authentication-issues) |
33+
| Azure Powershell Credential | [Azure Powershell Troubleshooting Guide](#troubleshooting-azure-powershell-authentication-issues) |
34+
35+
## Troubleshooting Environment Credential Authentication Issues
36+
37+
### Credential Unavailable Error
38+
39+
#### Environment variables not configured
40+
41+
The `EnvironmentCredential` supports Service Principal authentication and Username + Password authentication. To utilize the desired way of authentication via `EnvironmentCredential`, you need to ensure the environment variables below are configured properly and the application is able to read them.
42+
43+
##### Service principal with secret
44+
45+
| Variable Name | Value |
46+
| --- | --- |
47+
AZURE_CLIENT_ID | ID of an Azure Active Directory application. |
48+
AZURE_TENANT_ID |ID of the application's Azure Active Directory tenant. |
49+
AZURE_CLIENT_SECRET | One of the application's client secrets. |
50+
51+
##### Service principal with certificate
52+
53+
| Variable name | Value |
54+
| --- | --- |
55+
AZURE_CLIENT_ID |ID of an Azure Active Directory application. |
56+
AZURE_TENANT_ID | ID of the application's Azure Active Directory tenant. |
57+
AZURE_CLIENT_CERTIFICATE_PATH | Path to a PEM-encoded or PKCS12 certificate file including private key (without password protection). |
58+
59+
##### Username and password
60+
61+
| Variable name | Value |
62+
| --- | --- |
63+
AZURE_CLIENT_ID | ID of an Azure Active Directory application. |
64+
AZURE_USERNAME | A username (usually an email address). |
65+
AZURE_PASSWORD | The associated password for the given username. |
66+
67+
### Client Authentication Error
68+
69+
The `EnvironmentCredential` supports Service Principal authentication and Username + Password authentication.
70+
Please follow the troubleshooting guidelines below for the respective authentication which you tried and failed.
71+
72+
| Authentication Type | Troubleshoot Guide |
73+
| --- | --- |
74+
| Service Principal | [Service Principal Auth Troubleshooting Guide](#troubleshooting-username-password-authentication-issues) |
75+
| Username Password | [Username Password Auth Troubleshooting Guide](#troubleshooting-username-password-authentication-issues) |
76+
77+
## Troubleshooting Username Password Authentication Issues
78+
79+
### Two Factor Authentication Required Error
80+
81+
The `UsernamePassword` credential works only for users whose two factor authentication has been disabled in Azure Active Directory. You can change the Multi Factor Authentication in Azure Portal by following the steps [here](https://docs.microsoft.com/azure/active-directory/authentication/howto-mfa-userstates#change-the-status-for-a-user).
82+
83+
## Troubleshooting Service Principal Authentication Issues
84+
85+
### Illegal/Invalid Argument Issues
86+
87+
#### Client Id
88+
89+
The Client Id is the application Id of the registered application / service principal in Azure Active Directory.
90+
It is a required parameter for `ClientSecretCredential` and `ClientCertificateCredential`. If you have already created your service principal
91+
then you can retrieve the client/app id by following the instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#get-tenant-and-app-id-values-for-signing-in).
92+
93+
#### Tenant Id
94+
95+
The tenant id is te Global Unique Identifier (GUID) that identifies your organization. It is a required parameter for
96+
`ClientSecretCredential` and `ClientCertificateCredential`. If you have already created your service principal
97+
then you can retrieve the client/app id by following the instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#get-tenant-and-app-id-values-for-signing-in).
98+
99+
### Client Secret Credential Issues
100+
101+
#### Client Secret Argument
102+
103+
The client secret is the secret string that the application uses to prove its identity when requesting a token; this can also can be referred to as an application password.
104+
If you have already created a service principal you can follow the instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#option-2-create-a-new-application-secret) to create a client secret for your application.
105+
106+
### Client Certificate Credential Issues
107+
108+
#### Client Certificate Argument
109+
110+
The `Client Certificate Credential` accepts `pfx` and `pem` certificates. The certificate needs to be associated with your registered application/service principal. To create and associate a certificate with your registered app, please follow the instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#option-1-upload-a-certificate).
111+
112+
### Create a new service principal
113+
114+
Please follow the instructions [here](https://docs.microsoft.com/cli/azure/create-an-azure-service-principal-azure-cli) to create a new service principal.
115+
116+
## Troubleshooting Managed Identity Authentication Issues
117+
118+
### Credential Unavailable Error
119+
120+
#### Connection Timed Out / Connection could not be established / Target Environment could not be determined
121+
122+
Currently azure-identity supports [managed identity authentication](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview)
123+
in the below listed Azure services; ensure you're running your application on one of these resources and have enabled the Managed Identity on
124+
them by following the instructions at their configuration links below.
125+
126+
Azure Service | Managed Identity Configuration
127+
--- | --- |
128+
[Azure Virtual Machines](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token) | [Configuration Instructions](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm)
129+
[Azure App Service](https://docs.microsoft.com/azure/app-service/overview-managed-identity?tabs=python) | [Configuration Instructions](https://docs.microsoft.com/azure/app-service/overview-managed-identity?tabs=python)
130+
[Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/use-managed-identity) | [Configuration Instructions](https://docs.microsoft.com/azure/aks/use-managed-identity)
131+
[Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell/msi-authorization) | |
132+
[Azure Arc](https://docs.microsoft.com/azure/azure-arc/servers/managed-identity-authentication) | [Configuration Instructions](https://docs.microsoft.com/azure/azure-arc/servers/security-overview#using-a-managed-identity-with-arc-enabled-servers)
133+
[Azure Service Fabric](https://docs.microsoft.com/azure/service-fabric/concepts-managed-identity) | [Configuration Instructions](https://docs.microsoft.com/azure/service-fabric/configure-existing-cluster-enable-managed-identity-token-service)
134+
135+
## Troubleshooting Visual Studio Code Authentication Issues
136+
137+
### Credential Unavailable Error
138+
139+
#### Failed To Read VS Code Credentials / Authenticate via Azure Tools plugin in VS Code
140+
141+
THe `VS Code Credential` failed to read the credential details from the cache.
142+
143+
The Visual Studio Code authentication is handled by an integration with the Azure Account extension.
144+
To use this form of authentication, ensure that you have installed the Azure Account extension,
145+
then use View > Command Palette to execute the Azure: Sign In command. This command opens a browser window and displays a page that allows you
146+
to sign in to Azure. After you've completed the login process, you can close the browser as directed. Running your application
147+
(either in the debugger or anywhere on the development machine) will use the credential from your sign-in.
148+
149+
If you already had the Azure Account extension installed and had logged in to your account. Then try logging out and logging in again, as
150+
that will re-populate the cache on the disk and potentially mitigate the error you're getting.
151+
152+
#### Msal Interaction Required Error
153+
154+
THe `VS Code Credential` was able to read the cached credentials from the cache but the cached token is likely expired.
155+
Log into the Azure Account extension by via View > Command Palette to execute the Azure: Sign In command in the VS Code IDE.
156+
157+
#### ADFS Tenant Not Supported
158+
159+
The ADFS Tenants are not supported via the Azure Account extension in VS Code currently.
160+
The supported clouds are:
161+
162+
Azure Cloud | Cloud Authority Host
163+
--- | --- |
164+
AZURE PUBLIC CLOUD | https://login.microsoftonline.com/
165+
AZURE GERMANY | https://login.microsoftonline.de/
166+
AZURE CHINA | https://login.chinacloudapi.cn/
167+
AZURE GOVERNMENT | https://login.microsoftonline.us/
168+
169+
## Troubleshooting Azure CLI Authentication Issues
170+
171+
### Credential Unavailable Error
172+
173+
#### Azure CLI Not Installed
174+
175+
To use Azure CLI credential, the Azure CLI needs to be installed, please follow the instructions [here](https://docs.microsoft.com/cli/azure/install-azure-cli)
176+
to install it for your platform and then try running the credential again.
177+
178+
#### Azure account not logged in
179+
180+
`AzureCliCredential` authenticates as the identity currently logged in to Azure CLI.
181+
You need to login to your account in Azure CLI via `az login` command. You can further read instructions to [Sign in with Azure CLI](https://docs.microsoft.com/cli/azure/authenticate-azure-cli).
182+
Once logged in try running the credential again.
183+
184+
### Illegal State
185+
186+
#### Safe Working Directory Not Located
187+
188+
The `Azure CLI Credential` was not able to locate a value for System Environment property `SystemRoot` to execute in.
189+
Please ensure the `SystemRoot` environment variable is configured to a safe working directory and then try running the credential again.
190+
191+
## Troubleshooting Azure Powershell Authentication Issues
192+
193+
### Credential Unavailable Error
194+
195+
#### Powershell not installed
196+
197+
Please ensure PowerShell is installed on your platform by following the instructions [here](https://docs.microsoft.com/powershell/scripting/install/installing-powershell?view=powershell-7.1).
198+
199+
#### Azure Az Module Not Installed
200+
201+
Please follow the instructions [here](https://docs.microsoft.com/powershell/azure/install-az-ps)
202+
to install the Azure Az PowerShell module.
203+
204+
#### Azure account not logged in
205+
206+
Log in via the `Connect-AzAccount` command. See [Sign in with Azure Powershell](https://docs.microsoft.com/powershell/azure/authenticate-azureps) for more information.
207+
208+
#### Deserialization error
209+
210+
The `Azure Powershell Credential` was able to retrieve a response from the Azure Powershell when attempting to get an access token but failed
211+
to parse that response.
212+
In your local powershell window, run the following command to ensure that Azure Powershell is returning an access token in correct format.
213+
214+
```pwsh
215+
Get-AzAccessToken -ResourceUrl "<Scopes-Url>"
216+
```
217+
218+
In the event above command is not working properly, follow the instructions to resolve the Azure Powershell issue being faced and then try running the credential again.

sdk/identity/azure-identity/azure/identity/_credentials/azure_cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ def get_token(self, *scopes, **kwargs):
8383
token = parse_token(output)
8484
if not token:
8585
sanitized_output = sanitize_output(output)
86-
raise ClientAuthenticationError(message="Unexpected output from Azure CLI: '{}'".format(sanitized_output))
86+
raise ClientAuthenticationError(
87+
message="Unexpected output from Azure CLI: '{}'. \n"
88+
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
89+
"https://aka.ms/azsdk/python/identity/azclicredential/troubleshoot.".format(sanitized_output))
8790

8891
return token
8992

sdk/identity/azure-identity/azure/identity/_credentials/azure_powershell.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def run_command_line(command_line):
119119
# (handling Exception here because subprocess.SubprocessError and .TimeoutExpired were added in 3.3)
120120
if proc and not proc.returncode:
121121
proc.kill()
122-
error = CredentialUnavailableError(message="Failed to invoke PowerShell")
122+
error = CredentialUnavailableError(
123+
message="Failed to invoke PowerShell.\n"
124+
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
125+
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.")
123126
six.raise_from(error, ex)
124127

125128
raise_for_error(proc.returncode, stdout, stderr)

sdk/identity/azure-identity/azure/identity/_credentials/chained.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
101101

102102
within_credential_chain.set(False)
103103
attempts = _get_error_message(history)
104-
message = self.__class__.__name__ + " failed to retrieve a token from the included credentials." + attempts
104+
message = self.__class__.__name__ + " failed to retrieve a token from the included credentials." + attempts \
105+
+ "\nTo mitigate this issue, please refer to the troubleshooting guidelines here at " \
106+
"https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot."
105107
_LOGGER.warning(message)
106108
raise ClientAuthenticationError(message=message)

sdk/identity/azure-identity/azure/identity/_credentials/environment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def get_token(self, *scopes, **kwargs): # pylint:disable=unused-argument
132132
"""
133133
if not self._credential:
134134
message = (
135-
"EnvironmentCredential authentication unavailable. Environment variables are not fully configured."
135+
"EnvironmentCredential authentication unavailable. Environment variables are not fully configured.\n"
136+
"Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot."
137+
"this issue."
136138
)
137139
raise CredentialUnavailableError(message=message)
138140
return self._credential.get_token(*scopes, **kwargs)

sdk/identity/azure-identity/azure/identity/_credentials/managed_identity.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,10 @@ def get_token(self, *scopes, **kwargs):
110110
"""
111111

112112
if not self._credential:
113-
raise CredentialUnavailableError(message="No managed identity endpoint found.")
113+
raise CredentialUnavailableError(
114+
message="No managed identity endpoint found. \n"
115+
"The Target Azure platform could not be determined from environment variables. \n"
116+
"Visit https://aka.ms/azsdk/python/identity/managedidentitycredential/troubleshoot to "
117+
"troubleshoot this issue."
118+
)
114119
return self._credential.get_token(*scopes, **kwargs)

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
7171
token = parse_token(output)
7272
if not token:
7373
sanitized_output = sanitize_output(output)
74-
raise ClientAuthenticationError(message="Unexpected output from Azure CLI: '{}'".format(sanitized_output))
74+
raise ClientAuthenticationError(
75+
message="Unexpected output from Azure CLI: '{}'. \n"
76+
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
77+
"https://aka.ms/azsdk/python/identity/azclicredential/troubleshoot.".format(sanitized_output))
7578

7679
return token
7780

sdk/identity/azure-identity/azure/identity/aio/_credentials/azure_powershell.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ async def run_command_line(command_line: "List[str]") -> str:
8383

8484
except OSError as ex:
8585
# failed to execute "cmd" or "/bin/sh"; Azure PowerShell may or may not be installed
86-
error = CredentialUnavailableError(message='Failed to execute "{}"'.format(command_line[0]))
86+
error = CredentialUnavailableError(
87+
message='Failed to execute "{}".\n'
88+
'To mitigate this issue, please refer to the troubleshooting guidelines here at '
89+
'https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.'.format(command_line[0]))
8790
raise error from ex
8891
except asyncio.TimeoutError as ex:
8992
proc.kill()
90-
raise CredentialUnavailableError(message="Timed out waiting for Azure PowerShell") from ex
93+
raise CredentialUnavailableError(
94+
message="Timed out waiting for Azure PowerShell.\n"
95+
"To mitigate this issue, please refer to the troubleshooting guidelines here at "
96+
"https://aka.ms/azsdk/python/identity/powershellcredential/troubleshoot.") from ex
9197

9298
decoded_stdout = stdout.decode()
9399

sdk/identity/azure-identity/azure/identity/aio/_credentials/chained.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
7878

7979
within_credential_chain.set(False)
8080
attempts = _get_error_message(history)
81-
message = self.__class__.__name__ + " failed to retrieve a token from the included credentials." + attempts
81+
message = self.__class__.__name__ + " failed to retrieve a token from the included credentials." + attempts \
82+
+ "\nTo mitigate this issue, please refer to the troubleshooting guidelines here at " \
83+
"https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot."
8284
raise ClientAuthenticationError(message=message)

0 commit comments

Comments
 (0)