Skip to content

Commit c67e6f6

Browse files
authored
Add troubleshooting guide (Azure#23771)
* Add troubleshooting guide
1 parent 3de82e9 commit c67e6f6

File tree

2 files changed

+282
-0
lines changed

2 files changed

+282
-0
lines changed

sdk/identity/Azure.Identity/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ client secret and certificate are both present, the client secret will be used.
203203

204204
## Troubleshooting
205205

206+
See the [troubleshooting guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/troubleshooting.md) for details on how to diagnose various failure scenarios.
207+
206208
### Error Handling
207209
Errors arising from authentication can be raised on any service client method which makes a request to the service. This is because the first time the token is requested from the credential is on the first call to the service, and any subsequent calls might need to refresh the token. In order to distinguish these failures from failures in the service client Azure Identity classes raise the `AuthenticationFailedException` with details to the source of the error in the exception message as well as possibly the error message. Depending on the application these errors may or may not be recoverable.
208210

@@ -252,6 +254,17 @@ DefaultAzureCredentialOptions options = new DefaultAzureCredentialOptions()
252254

253255
> CAUTION: Requests and responses in the Azure Identity library contain sensitive information. Precaution must be taken to protect logs when customizing the output to avoid compromising account security.
254256
257+
### Thread safety
258+
We guarantee that all credential instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)).
259+
This ensures that the recommendation of reusing credential instances is always safe, even across threads.
260+
261+
### Additional concepts
262+
[Client options](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
263+
[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
264+
[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md) |
265+
[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#mocking) |
266+
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
267+
255268
## Next steps
256269

257270
### Client libraries supporting authentication with Azure Identity
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
## Troubleshooting Azure Identity Authentication Issues
2+
3+
The Azure Identity SDK offers various `TokenCredential` implementations. The most common exceptions observed for failure scenarios
4+
are `CredentialUnavailableException`
5+
and `AuthenticationFailedException`.
6+
7+
- `CredentialUnavailableException` indicates that the credential cannot execute in the current environment setup due to lack of required configuration.
8+
- `AuthenticationFailedException` indicates that the credential was able to run/execute but ran into an authentication issue from the server's end. This can happen
9+
due to invalid configuration/details passed in to the credential at construction time.
10+
11+
This troubleshooting guide covers mitigation steps to resolve these exceptions thrown by various `TokenCredential` implementations in the Azure Identity .NET client
12+
library.
13+
14+
## Table of contents
15+
16+
- [Troubleshooting Default Azure Credential Authentication Issues](#troubleshooting-default-azure-credential-authentication-issues)
17+
- [Troubleshooting Environment Credential Authentication Issues](#troubleshooting-environment-credential-authentication-issues)
18+
- [Troubleshooting Service Principal Authentication Issues](#troubleshooting-service-principal-authentication-issues)
19+
- [Troubleshooting Username Password Authentication Issues](#troubleshooting-username-password-authentication-issues)
20+
- [Troubleshooting Mananged Identity Authenticaiton Issues](#troubleshooting-mananged-identity-authenticaiton-issues)
21+
- [Troubleshooting Visual Studio Code Authenticaiton Issues](#troubleshooting-visual-studio-code-authenticaiton-issues)
22+
- [Troubleshooting Visual Studio Authenticaiton Issues](#troubleshooting-visual-studio-authenticaiton-issues)
23+
- [Troubleshooting Azure CLI Authenticaiton Issues](#troubleshooting-azure-cli-authenticaiton-issues)
24+
- [Troubleshooting Azure Powershell Authenticaiton Issues](#troubleshooting-azure-powershell-authenticaiton-issues)
25+
26+
## Troubleshooting Default Azure Credential Authentication Issues.
27+
28+
### Credential Unavailable Exception
29+
30+
The first time `DefaultAzureCredential` attempts to retrieve an access token it does so by sequentially invoking a chain of credentials.
31+
The `CredentialUnavailableException` in this scenario signifies that all the credentials in the chain failed to retrieve the token in the current environment
32+
setup/configuration. You need to follow the configuration instructions for the respective credential you're looking to use via `DefaultAzureCredential` chain, so
33+
that the credential can work in your environment.
34+
35+
Please follow the configuration instructions in the `Credential Unvavailable` section of hte troubleshooting guidelines below for the respective
36+
credential/authentication type you're looking to use via `DefaultAzureCredential`:
37+
38+
| Credential Type | Troubleshooting Guide |
39+
| --- | --- |
40+
| Environment Credential | [Environment Credential Troubleshooting Guide](#troubleshooting-environment-credential-authentication-issues) |
41+
| Managed Identity Credential | [Managed Identity Troubleshooting Guide](#troubleshooting-managed-identity-authentication-issues) |
42+
| Visual Studio Code Credential | [Visual Studio Code Troubleshooting Guide](#troubleshooting-visual-studio-code-authenticaiton-issues) |
43+
| Visual Studio Credential | [Visual Studio Troubleshooting Guide](#troubleshooting-visual-studio-authenticaiton-issues) |
44+
| Azure CLI Credential | [Azure CLI Troubleshooting Guide](#troubleshooting-azure-cli-authenticaiton-issues) |
45+
| Azure Powershell Credential | [Azure Powershell Troubleshooting Guide](#troubleshooting-azure-powershell-authentication-issues) |
46+
47+
## Troubleshooting Environment Credential Authentication Issues.
48+
49+
### Credential Unavailable Exception
50+
51+
#### Environment variables not configured
52+
53+
The `EnvironmentCredential` supports Service Principal authentication and Username + Password Authentication. It requires that the environment variables below are
54+
properly configured and available to the application. This can mean that an application or its execution environment needs to be restarted to pick up changes to the
55+
environment.
56+
57+
##### Service principal with secret
58+
59+
| Variable Name | Value |
60+
| --- | --- |
61+
AZURE_CLIENT_ID | ID of an Azure Active Directory application. |
62+
AZURE_TENANT_ID |ID of the application's Azure Active Directory tenant. |
63+
AZURE_CLIENT_SECRET | One of the application's client secrets. |
64+
65+
##### Service principal with certificate
66+
67+
| Variable name | Value |
68+
| --- | --- |
69+
AZURE_CLIENT_ID | ID of an Azure Active Directory application. |
70+
AZURE_TENANT_ID | ID of the application's Azure Active Directory tenant. |
71+
AZURE_CLIENT_CERTIFICATE_PATH | Path to a PEM-encoded certificate file including private key (must be without password protection). |
72+
73+
##### Username and password
74+
75+
| Variable name | Value |
76+
| --- | --- |
77+
AZURE_CLIENT_ID | ID of an Azure Active Directory application. |
78+
AZURE_USERNAME | A username (usually an email address). |
79+
AZURE_PASSWORD | The associated password for the given username. |
80+
81+
### Client Authentication Exception
82+
83+
The `EnvironmentCredential` supports Service Principal authentication and Username + Password Authentication. Please follow the troubleshooting guidelines below for
84+
the respective authentication method.
85+
86+
| Authentication Type | Trobuleshoot Guide |
87+
| --- | --- |
88+
| Service Principal | [Service Principal Auth Troubleshooting Guide](#troubleshooting-username-password-authentication-issues) |
89+
| Username Password | [Username Password Auth Troubleshooting Guide](#troubleshooting-username-password-authentication-issues) |
90+
91+
## Troubleshooting Username Password Authentication Issues
92+
93+
### Two Factor Authentication Required Error
94+
95+
The `UsernamePassword` credential works only for users whose two factor authentication has been disabled in Azure Active Directory. You can change the multi-factor
96+
authentication requirements in Azure Portal by following the
97+
steps [here](https://docs.microsoft.com/azure/active-directory/authentication/howto-mfa-userstates#change-the-status-for-a-user).
98+
99+
## Troubleshooting Service Principal Authentication Issues
100+
101+
### Invalid Argument Issues
102+
103+
#### Client Id
104+
105+
The Client Id is the application Id of the registered application / service principal in Azure Active Directory. It is a required parameter
106+
for `ClientSecretCredential` and `ClientCertificateCredential`. If you have already created your service principal then you can retrieve the client/app id by
107+
following the
108+
instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#get-tenant-and-app-id-values-for-signing-in). .
109+
110+
#### Tenant Id
111+
112+
The tenant id is a Globally Unique Identifier (GUID) that identifies your organization. It is a required parameter for `ClientSecretCredential`
113+
and `ClientCertificateCredential`. If you have already created your service principal then you can retrieve the client or application id by following the
114+
instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#get-tenant-and-app-id-values-for-signing-in). .
115+
116+
### Client Secret Credential Issues
117+
118+
#### Client Secret Argument
119+
120+
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
121+
password. If you have already created a service principal you can follow the
122+
instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#option-2-create-a-new-application-secret)
123+
to get the client secret for your application.
124+
125+
### Client Certificate Credential Issues
126+
127+
#### Client Certificate Argument
128+
129+
The `Client Certificate Credential` accepts a `pfx` or `pem` certificate which is associated with your registered application/service principal. To create and
130+
associate a certificate with your registered app. please follow the
131+
instructions [here](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal#option-1-upload-a-certificate).
132+
133+
### Create a new service principal
134+
135+
Follow tne instructions [here](https://docs.microsoft.com/cli/azure/create-an-azure-service-principal-azure-cli) to create a new service principal.
136+
137+
## Troubleshooting Managed Identity Authentication Issues
138+
139+
### Credential Unavailable
140+
141+
#### Connection Timed Out / Connection could not be established / Target Environment could not be determined.
142+
143+
The endpoints required to support the Managed Identity credential are only available on Azure Hosted machines/servers. So ensure that you are running your
144+
application on an Azure Hosted resource. Currently Azure Identity SDK
145+
supports [Managed Identity Authentication](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview)
146+
in the below listed Azure Services. Ensure you're running your application in one of these environments and have enabled a Managed Identity on them by following the
147+
instructions at their configuration links below.
148+
149+
Azure Service | Managed Identity Configuration
150+
--- | --- |
151+
[Azure Virtual Machines](https://docs.microsoft.com/azure/virtual-machines/) | [Configuration Instructions](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm)
152+
[Azure App Service](https://docs.microsoft.com/azure/app-service/overview) | [Configuration Instructions](https://docs.microsoft.com/azure/app-service/overview-managed-identity)
153+
[Azure Kubernetes Service](https://docs.microsoft.com/azure/aks) | [Configuration Instructions](https://docs.microsoft.com/azure/aks/use-managed-identity)
154+
[Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell) | [Configuration Instructions](https://docs.microsoft.com/azure/cloud-shell/msi-authorization) |
155+
[Azure Arc](https://docs.microsoft.com/azure/azure-arc/) | [Configuration Instructions](https://docs.microsoft.com/azure/azure-arc/servers/security-overview#using-a-managed-identity-with-arc-enabled-servers)
156+
[Azure Service Fabric](https://docs.microsoft.com/azure/service-fabric) | [Configuration Instructions](https://docs.microsoft.com/azure/service-fabric/configure-existing-cluster-enable-managed-identity-token-service)
157+
158+
## Troubleshooting Visual Studio Code Authentication Issues
159+
160+
### Credential Unavailable
161+
162+
#### Failed To Read VS Code Credentials / Authenticate via Azure Tools plugin in VS Code.
163+
164+
The `VisualStudioCodeCredential` failed to read the credential details from the cache.
165+
166+
The Visual Studio Code authentication is handled by an integration with the Azure Account extension. To use this form of authentication, ensure that you have
167+
installed the Azure Account extension, then use **View > Command Palette** to execute the **Azure: Sign In** command. This command opens a browser window and
168+
displays a page that allows you to sign in to Azure. After you've completed the login process, you can close the browser as directed. Running your application
169+
(either in the debugger or anywhere on the development machine) will use the credential from your sign-in.
170+
171+
If you already had the Azure Account extension installed and had logged in to your account, try logging out and logging in again as that will re-populate the cache
172+
on the disk and potentially mitigate the error you're getting.
173+
174+
#### Msal Interaction Required Error
175+
176+
The `VisualStudioCodeCredential` was able to read the cached credentials from the cache but the cached token is likely expired. Log into the Azure Account extension
177+
via **View > Command Palette** to execute the **Azure: Sign In** command in the VS Code IDE.
178+
179+
#### ADFS Tenant Not Supported
180+
181+
The ADFS Tenants are not supported via the Azure Account extension in VS Code currently. The supported clouds are:
182+
183+
Azure Cloud | Cloud Authority Host
184+
--- | --- |
185+
AZURE PUBLIC CLOUD | https://login.microsoftonline.com/
186+
AZURE GERMANY | https://login.microsoftonline.de/
187+
AZURE CHINA | https://login.chinacloudapi.cn/
188+
AZURE GOVERNMENT | https://login.microsoftonline.us/
189+
190+
## Troubleshooting Visual Studio Authentication Issues
191+
192+
### Credential Unavailable
193+
194+
#### Failed To Read Credentials / Authenticate via Azure Service Authentication
195+
196+
The `VisualStudioCredential` failed to read the credential details from the cache.
197+
198+
The Visual Studio authentication is handled by helper utility called Microsoft.Asal.TokenService.exe. To use this form of authentication, ensure that you have signed
199+
in to your Azure account. To do so, select the `Tools > Options` menu to launch the Options dialog. Then navigate to the `Azure Service Authentication` options to
200+
sign in with your Azure Active Directory account. Running your application (either in the debugger or anywhere on the development machine) will use the credential
201+
from your sign-in.
202+
203+
If you already had logged in to your account previously, try logging out and logging in again as that will re-populate the cache on the disk and potentially mitigate
204+
the error you're getting.
205+
206+
#### Msal Interaction Required Error
207+
208+
The `VisualStudioCredential` was able to read the cached credentials from the cache but the cached token is likely expired. Log into the Azure Account extension
209+
via **View > Command Palette** to execute the **Azure: Sign In** command in the VS Code IDE.
210+
211+
#### ADFS Tenant Not Supported
212+
213+
The ADFS Tenants are not supported via the Azure Account extension in VS Code currently. The supported clouds are:
214+
215+
Azure Cloud | Cloud Authority Host
216+
--- | --- |
217+
AZURE PUBLIC CLOUD | https://login.microsoftonline.com/
218+
AZURE GERMANY | https://login.microsoftonline.de/
219+
AZURE CHINA | https://login.chinacloudapi.cn/
220+
AZURE GOVERNMENT | https://login.microsoftonline.us/
221+
222+
## Troubleshooting Azure CLI Authentication Issues
223+
224+
### Credential Unavailable
225+
226+
#### Azure CLI Not Installed.
227+
228+
The `AzureCliCredential` failed to execute as Azure CLI command line tool is not installed. To use Azure CLI credential, the Azure CLI needs to be installed, please
229+
follow the instructions [here](https://docs.microsoft.com/cli/azure/install-azure-cli) to install it for your platform and then try running the credential again.
230+
231+
#### Azure account not logged in.
232+
233+
The `AzureCliCredential` utilizes the current logged in Azure user in Azure CLI to fetch an access token. You need to login to your account in Azure CLI
234+
via `az login` command. You can further read instructions to [Sign in with Azure CLI](https://docs.microsoft.com/cli/azure/authenticate-azure-cli). Once logged in
235+
try running the credential again.
236+
237+
## Troubleshooting Azure Powershell Authenticaiton Issues
238+
239+
### Credential Unavailable
240+
241+
#### Powershell not installed.
242+
243+
The `AzurePowerShellCredential` utilizes the locally installed `Powershell` command line tool to fetch an access token. Please ensure it is installed on your
244+
platform by following the instructions [here](https://docs.microsoft.com/powershell/scripting/install/installing-powershell) and then run the
245+
credential again.
246+
247+
#### Azure Az Module Not Installed.
248+
249+
The `AzurePowerShellCredential` failed to execute as Azure az module is not installed. To use Azure Powershell credential, the Azure az module needs to be
250+
installed, please follow the instructions [here](https://docs.microsoft.com/powershell/azure/install-az-ps)
251+
to install it for your platform and then try running the credential again.
252+
253+
#### Azure account not logged in.
254+
255+
The `AzurePowerShellCredential` utilizes the current logged in Azure user in Azure Powershell to fetch an access token. You need to login to your account in Azure
256+
Powershell via `Connect-AzAccount` command. You can further read instructions
257+
to [Sign in with Azure Powershell](https://docs.microsoft.com/powershell/azure/authenticate-azureps). Once logged in try running the credential again.
258+
259+
#### Deserialization error.
260+
261+
The `AzurePowerShellCredential` was able to retrieve a response from the Azure Powershell when attempting to get an access token but failed to parse that response.
262+
In your local powershell window, run the following command to ensure that Azure PowerShell is returning an access token in correct format.
263+
264+
```pwsh
265+
Get-AzAccessToken -ResourceUrl "<Scopes-Url>"
266+
```
267+
268+
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
269+
again.

0 commit comments

Comments
 (0)