-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of AAD authentication with Microsoft.Extensions.Azure can cause continuous trace loop due to lack of token caching #2539
Comments
Hello @maskati, Thank you for the details. I'll need more time to investigate Regarding caching, the fix is not expected to come from this library. |
@TimothyMothra my underatanding is that Azure.Identity does not currently implement caching, rather some credential providers happen to do so (e.g. MSAL based ones) Azure/azure-sdk-for-net#24045 (comment):
Azure.Identity might at some point implement general caching if MSAL exposes such implementation Azure/azure-sdk-for-net#25361:
The issue is that App Insights generates a large volume of authenticated requests, with each request acquiring a new token. In the case of managed identity this hits the MSI endpoint with a token request for each telemetry item. Most Azure SDK clients (Storage, App Config etc.) implement token cache, for example using BearerAuthenticationTokenPolicy. Is there a reason App Insights is different? |
The Azure SDKs share a common implementation for HttpClient. Adopting this is out of scope for this repo. The recommendation is to wait for Azure.Identity to deliver caching. Please upvote these issues on their repo to help them prioritize this.
|
Ok thanks for the update on token caching @TimothyMothra. It might be useful to document that when using AAD authentication you should limit logging of Regarding the original issue of trace loops due to token acquisition, how does App Insights currently prevent telemetry transmission over http from triggering traces on the telemetry transmission itself (http transmission trace loops)? |
All of our outbound HTTP calls are wrapped with ApplicationInsights-dotnet/BASE/src/ServerTelemetryChannel/Implementation/TransmissionSender.cs Lines 194 to 196 in 87c2019
|
@TimothyMothra the ManagedIdentityCredential uses caching since Azure.Identity 1.8.0. It would be great if you can move to this dependency for 1.22.0. |
Microsoft.ApplicationInsights doesn't depend on Azure.Identity. It relies on a TokenCredential passed by the application. The burden, therefore, is on the application to provide a TokenCredential with caching. |
Would this be resolved by a documentation update e.g. ”when using Application Insights with AAD authentication it is recommended to provide a TokenCredential implementing caching. For ManagedIdentityCredential this can be achieved by using Azure.Identity version 1.8.0 or greater.”? |
@TimothyMothra, what do you think of #2720 to address this in code? |
Ok I this. My issue in fact is that the App Insights lib + Az.Identity one installed in the Azure functions are using 1.5.0 so its really a mess when you have a lot of logs to send using AAD auth since there is no cache. I will therefore open a ticket on the Az function Git referencing this issue. Thanks. |
This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. |
NuGet packages:
Runtime version: net6.0
Hosting environment: Azure Web App with managed identity and associated Application Insights
Describe the bug
Application Insights trace logs are filling up with the following four traces when using AAD authenticated configuration in combination with with Microsoft.Extensions.Azure for dependency injection of Azure SDK clients:
It seems that the Application Insights SDK is actually requesting a new token from
TokenCredential
for every telemetry transmission, and is also logging the logs related to requesting this token. This is resulting in a continuous loop of transmitting token acquisition trace logs related to the previous transmission of token acquisition trace logs. This is caused byAzureEventSourceLogForwarder
in Microsoft.Extensions.Azure forwarding Azure SDK logs to .NET logs and Application Insights.A related but somewhat separate issue is that the current implementation does no token caching, which places unnecessary pressure on the application and managed identity infrastructure. The original feature request #2190 states:
However the most common scenario of using managed identities does not implement caching. See for example Azure/azure-sdk-for-net#24046 or ManagedIdentityCredential.GetToken:
Azure SDK client libraries mostly cache tokens through the common request pipeline. For example App Configuration uses BearerTokenAuthenticationPolicy which implements caching.
To Reproduce
Program.cs
The text was updated successfully, but these errors were encountered: