|
1 | 1 |
|
2 | | -`DefaultAzureCredential` is the easiest way to get started with the Azure Identity library, but with that convenience comes certain tradeoffs. Perhaps the most significant tradeoff is the credential chain's indeterministic behavior - that is, the specific credential in the [chain](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet) that will succeed and be used for request authentication can't be guaranteed ahead of time. In a production environment, this unpredictability can introduce significant and sometimes subtle problems. Once you deploy your app to Azure, you should understand the app's authentication requirements. |
| 2 | +`DefaultAzureCredential` is the most approachable way to get started with the Azure Identity library, but that convenience also introduces certain tradeoffs. For example, the specific credential in the [chain](/dotnet/api/azure.identity.defaultazurecredential?view=azure-dotnet) that will succeed and be used for request authentication can't be guaranteed ahead of time. In a production environment, this unpredictability can introduce significant and sometimes subtle problems. |
3 | 3 |
|
4 | 4 | For example, consider the following hypothetical sequence of events: |
5 | 5 |
|
6 | | -1. An organization's security team mandates that all apps use managed identity to authenticate to Azure resources. |
| 6 | +1. An organization's security team mandates all apps use managed identity to authenticate to Azure resources. |
7 | 7 | 1. For months, a .NET app hosted on an Azure Virtual Machine (VM) successfully uses `DefaultAzureCredential` to authenticate via managed identity. |
8 | 8 | 1. Unbeknownst to the support team, a developer installs the Azure CLI on that VM and runs the `az login` command to sign-in to Azure. |
9 | | -1. Authentication via the original managed identity unexpectedly begins to fail due to changes in the Azure environment. |
10 | | -1. `DefaultAzureCredential` skips `ManagedIdentityCredential` and searches for the next available credential, which is the Azure CLI credentials. |
| 9 | +1. Due to a change in the Azure environment, Authentication via the original managed identity unexpectedly begins to fail. |
| 10 | +1. `DefaultAzureCredential` skips the failed `ManagedIdentityCredential` and searches for the next available credential, which is the Azure CLI credentials. |
11 | 11 | 1. Because logging is disabled by default, nobody is aware of this failure, as `DefaultAzureCredential` recovers gracefully. |
12 | 12 |
|
13 | | -`DefaultAzureCredential` can also introduce the following challenges: |
| 13 | +`DefaultAzureCredential` also introduces the following challenges in some scenarios: |
14 | 14 |
|
15 | | -- **Debugging challenges**: When authentication fails, it can be challenging to debug and identify the offending credential. You must enable logging to see the progression from one credential to the next and the success/failure status of each. For more information, see [Debug a chained credential](/dotnet/azure/sdk/authentication/credential-chains?tabs=dac#debug-a-chained-credential). |
16 | | -- **Performance overhead**: The process of sequentially trying multiple credentials can introduce performance overhead. For example, when running on a local development machine, managed identity is unavailable. Consequently, `ManagedIdentityCredential` always fails in the local development environment, unless explicitly disabled via its corresponding `Exclude`-prefixed property. |
| 15 | +- **Debugging challenges**: When authentication fails, it can be difficult to debug and identify the offending credential. You must enable logging to see the progression from one credential to the next and the success or failure status of each. For more information, see [Debug a chained credential](/dotnet/azure/sdk/authentication/credential-chains?tabs=dac#debug-a-chained-credential). |
| 16 | +- **Performance overhead**: Sequentially attempting multiple credentials can introduce performance overhead. For example, when running on a local development machine, managed identity is unavailable. Consequently, `ManagedIdentityCredential` always fails in the local development environment, unless explicitly disabled via its corresponding `Exclude`-prefixed property. |
17 | 17 |
|
18 | | -To prevent these types of subtle issues or silent failures in production apps, strongly consider moving from `DefaultAzureCredential` to one of the following solutions: |
| 18 | +To prevent these types of subtle issues or silent failures in production apps, strongly consider moving from `DefaultAzureCredential` to one of the following deterministic solutions: |
19 | 19 |
|
20 | 20 | - A specific `TokenCredential` implementation, such as `ManagedIdentityCredential`. See the [**Derived** list](/dotnet/api/azure.core.tokencredential?view=azure-dotnet&preserve-view=true#definition) for options. |
21 | 21 | - A pared-down `ChainedTokenCredential` implementation optimized for the Azure environment in which your app runs. `ChainedTokenCredential` essentially creates a specific allow-list of acceptable credential options, such as `ManagedIdentity` for production and `VisualStudioCredential` for development. |
22 | 22 |
|
23 | | -Consider the following `DefaultAzureCredential` example: |
| 23 | +For example, consider the following `DefaultAzureCredential` configuration: |
24 | 24 |
|
25 | | -:::code language="csharp" source="../snippets/authentication/credential-chains/Program.cs" id="snippet_Dac" highlight="6"::: |
| 25 | +:::code language="csharp" source="../snippets/authentication/credential-chains/Program.cs" id="snippet_Dac" highlight="6,7"::: |
26 | 26 |
|
27 | | -Replace the preceding code with the following `ChainedTokenCredential` implementation, specifying your desired credentials: |
| 27 | +Replace the preceding code with the following `ChainedTokenCredential` implementation to intentionally specify your desired credentials: |
28 | 28 |
|
29 | | -:::code language="csharp" source="../snippets/authentication/credential-chains/Program.cs" id="snippet_Dac" highlight="snippet_Ctc"::: |
| 29 | +:::code language="csharp" source="../snippets/authentication/credential-chains/Program.cs" id="snippet_Ctc" highlight="6-8"::: |
0 commit comments