You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/azure/sdk/authentication/authentication-best-practices.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,10 @@ This article offers guidelines to help you maximize the performance and reliabil
15
15
16
16
## Reuse credential instances
17
17
18
-
To improve app resilience, reuse credential instances when possible. When a credential is reused, fewer access token requests are issued to Microsoft Entra ID. Instead, an attempt is made to fetch a token from the app token cache managed by the underlying MSAL dependency. For more information, see [Token caching in the Azure Identity client library](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/samples/TokenCache.md). A high-volume app that doesn't reuse credentials may encounter HTTP 429 throttling responses from Microsoft Entra ID, which can lead to app outages.
18
+
To improve app resilience, reuse credential instances when possible to reduce the number of access token requests issued to Microsoft Entra ID. When a credential is reused, an attempt is made to fetch a token from the app token cache managed by the underlying MSAL dependency. For more information, see [Token caching in the Azure Identity client library](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/samples/TokenCache.md).
19
+
20
+
> [!NOTE]
21
+
> A high-volume app that doesn't reuse credentials may encounter HTTP 429 throttling responses from Microsoft Entra ID, which can lead to app outages.
19
22
20
23
In an ASP.NET Core app, implement credential reuse through the `UseCredential` method of `Microsoft.Extensions.Azure`:
21
24
@@ -35,8 +38,8 @@ The Azure Identity library for .NET allows you to authenticate via managed ident
35
38
- No retries are attempted when token acquisition fails.
36
39
- When used via any other approach, such as `ChainedTokenCredential` or `ManagedIdentityCredential` directly:
37
40
- The time interval between retries starts at 0.8 seconds, and a maximum of five retries are attempted.
38
-
-When the Azure service to which you're authenticating provides a `Retry-After` response header, the next retry is delayed by the duration specified in that header's value.
39
-
-When the service doesn't provide a `Retry-After` header, the maximum permissible delay between retries is 1 minute.
41
+
-If the Azure service to which you're authenticating provides a `Retry-After` response header, the next retry is delayed by the duration specified in that header's value.
42
+
-If the service doesn't provide a `Retry-After` header, the maximum permissible delay between retries is 1 minute.
40
43
- To change any of the default retry settings, use the `Retry` property on `ManagedIdentityCredentialOptions`. For example, retry a maximum of three times, with a starting interval of 0.5 seconds:
Copy file name to clipboardExpand all lines: docs/azure/sdk/includes/default-azure-credential-usage.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,15 @@ For example, consider the following hypothetical sequence of events:
5
5
6
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
-
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. Due to a change in the Azure environment, Authentication via the original managed identity unexpectedly begins to fail.
8
+
1.Without telling 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. Due to a separate configuration change in the Azure environment, Authentication via the original managed identity unexpectedly begins to fail.
10
10
1.`DefaultAzureCredential` skips the failed `ManagedIdentityCredential` and searches for the next available credential, which is the Azure CLI credentials.
11
-
1. Because logging is disabled by default, nobody is aware of this failure, as `DefaultAzureCredential` recovers gracefully.
11
+
1. Because logging is disabled by default, the team is unaware of this silent authentication failure.
12
12
13
13
`DefaultAzureCredential` also introduces the following challenges in some scenarios:
14
14
15
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.
16
+
-**Performance overhead**: Sequentially attempting multiple credentials can introduce performance overhead. For example, on a local development machine, managed identity is unavailable. Consequently, `ManagedIdentityCredential` always fails locally, unless explicitly disabled via its corresponding `Exclude`-prefixed property.
17
17
18
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
@@ -27,3 +27,5 @@ For example, consider the following `DefaultAzureCredential` configuration:
27
27
Replace the preceding code with the following `ChainedTokenCredential` implementation to intentionally specify your desired credentials:
In this example, `ManagedIdentityCredential` would be automatically discovered in production, while `VisualStudioCredential` would work in local development environments.
0 commit comments