Skip to content

Commit d5fef2f

Browse files
committed
toc
1 parent 5f066a5 commit d5fef2f

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

docs/azure/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
href: ./sdk/authentication/additional-methods.md
7676
- name: Credential chains
7777
href: ./sdk/authentication/credential-chains.md
78+
- name: Azure Identity library best practices
79+
href: ./sdk/authentication/authentication-best-practices.md
7880
- name: ASP.NET Core guidance
7981
href: ./sdk/aspnetcore-guidance.md
8082
- name: Resource management

docs/azure/sdk/authentication/best-practices.md renamed to docs/azure/sdk/authentication/authentication-best-practices.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ This article offers guidelines to help you maximize the performance and reliabil
1515

1616
## Reuse credential instances
1717

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.
1922
2023
In an ASP.NET Core app, implement credential reuse through the `UseCredential` method of `Microsoft.Extensions.Azure`:
2124

@@ -35,8 +38,8 @@ The Azure Identity library for .NET allows you to authenticate via managed ident
3538
- No retries are attempted when token acquisition fails.
3639
- When used via any other approach, such as `ChainedTokenCredential` or `ManagedIdentityCredential` directly:
3740
- 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.
4043
- 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:
4144

4245
:::code language="csharp" source="../snippets/auth-best-practices/Program.cs" id="snippet_retries" highlight="5-9":::

docs/azure/sdk/includes/default-azure-credential-usage.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ For example, consider the following hypothetical sequence of events:
55

66
1. An organization's security team mandates all apps use managed identity to authenticate to Azure resources.
77
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.
1010
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.
1212

1313
`DefaultAzureCredential` also introduces the following challenges in some scenarios:
1414

1515
- **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.
1717

1818
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:
1919

@@ -27,3 +27,5 @@ For example, consider the following `DefaultAzureCredential` configuration:
2727
Replace the preceding code with the following `ChainedTokenCredential` implementation to intentionally specify your desired credentials:
2828

2929
:::code language="csharp" source="../snippets/authentication/credential-chains/Program.cs" id="snippet_Ctc" highlight="6-8":::
30+
31+
In this example, `ManagedIdentityCredential` would be automatically discovered in production, while `VisualStudioCredential` would work in local development environments.

0 commit comments

Comments
 (0)