-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[FEATURE REQ] Add Token Caching support for AzureCliCredential and other Azure TokenCredential where possible #32579
Comments
//cc: @christothes |
Thank you for your feedback. Tagging and routing to the team member best able to assist. |
I'm surprised this caching is not in place after using other auth libraries from Microsoft with it in. At the moment I'm resorting to putting my own cache in place in front of this library. Example setup: https://devblogs.microsoft.com/azure-sdk/azure-identity-with-sql-graph-ef/ |
Hi @lukeskinner - The process-based development time credentials, such as |
@christothes Thanks for the clarification on the reasons behind the cache implementation discrepancy. But if you consider that it was Microsoft's decision to ultimately switch us from Many of us have fully functional production apps out there using When we were told to migrate to We do know that a simple, basic cache wouldn't take more than a couple of dozens of lines of codes to write ourselves in our own codes. But we didn't want to mess with any edge cases along with things like retries and exception handlings etc, again, just to connect to Azure. Now with #25361 being resolved, we can at least confidently go to production with However, if you think about this setup: we now look at the environment, and if it's dev, we get/set token from this custom cache. Otherwise, we call Meanwhile, those who don't bother doing this would be just spamming the Microsoft/Azure AD token endpoints repeatedly during dev, for no good reasons. Then if you look at the doc for the
Compare that to the new 1.8.0 version on
Don't you think all these discrepancies can be confusing to new Azure developers who would be coming to the library? So far, I have not even seen new tutorials/docs out there that address this issue. Imagine if you were to write a new "how-to" guide for token-based authentication to Azure PaaS services, do you really want to mention "cache"? If you don't though, the developers will be baffled on why their apps are so laggy when running locally till they realize that they're spamming the token endpoints with every query against Azure SQL. I can see that the But maybe if you'd consider adding a "general purpose", in-class cache that can cover most of the use cases for these process-based credentials for development (don't have to be complicated because it's dev after all), similar to how |
I agree with @mikequ-taggysoft. We have solved that issue with a custom |
Thanks for the detailed feedback @mikequ-taggysoft ! Although we still do not plan to implement a cache specific to Azure.Identity , we'll track this as a documentation issue here #32857 Just as a side note, The Azure SDK clients do utilize a token cache, but this scenario is much simpler because the token will exist for only a specific identity and scope. Arbitrary token caching is very complex to do correctly, which is why we delegate this to MSAL. |
@christothes can you give examples for what is to consider on arbitrary token caching? There are use cases where the token is not used by an Azure SDK client and therefore there is also no token cache. E.g. when you want to use the token for a PostgreSQL connection: https://learn.microsoft.com/en-us/azure/postgresql/single-server/how-to-connect-with-managed-identity#connecting-using-managed-identity-in-c |
@PSanetra Yeah the fundamental issue with both #25361 and this one is the fact that no dedicated Azure SDKs (which do have caching) exist for or apply to certain Azure services (such as the PaaS database ones).
However, Microsoft wants to switch the To put it in another way: when we connect to Azure services with SDKs, such as the Azure storage and messaging related SDKs, that build upon When we actually need to retrieve the tokens, it implies that we're not using some other Azure SDK, and obviously we always want caching and lifetime management due to the nature of OAuth2 tokens. @christothes Since currently For example, what about just copying the setup from As for "identity and scope", just make it one cache entry for each |
Hi @mikequ-taggysoft |
I came across this issue after following the docs on Azure AD authentication for Application Insights which recommend to use DefaultAzureCredential for local development. For every log that was getting sent out, their library was requesting a new token and it completely bogged down my application. It looks like they're under the impression that Azure.Identity was shipping a caching solution (see comment in microsoft/ApplicationInsights-dotnet/issues/2539). @christothes from your statement about what Azure.Identity supports, it seems like this is something the AppInsights team needs to make the decision on - whether they want to implement it themselves or push the problem on to their customers. However, it seems like there's an opportunity here for a common solution for caching these credentials that can be used across libraries Microsoft ships. |
Pushing responsibility of caching to the caller has no doubt resulted in engineers across many different organisations creating token caching implementations. Caching oauth tokens is a requirement for us all, so it's surprising it's been left out. I can understand there's a complexity you'd rather not deal with and simply provide the raw functionality for acquiring the tokens, but it's exactly because of that complexity it would've been nice to solve it once, centrally, in the official supported SDK |
Library name
Azure.Identity
Please describe the feature.
Azure.Identity
release 1.8.0 finally added token cache forManagedIdentityCredential
, closing out feature request #25361 which has been long awaited by many. @christothesBut as I finally started to migrate from
AppAuthentication
toAzure.Identity
, I realized that the implemented cache seemed to only apply toManagedIdentityCredential
, which is great for production in Azure, but not for local dev.Many Azure developers who utilize managed identities also naturally utilize credentials such as
AzureCliCrendential
andVisualStudioCredential
(I personally prefer the former as it seems to be faster and more reliable for me) for local dev environments.Previously,
AppAuthentication
would just cache everything and the experience is completely seamless.Now that
AzureCliCrendential
is not cached, every request for token results in a HTTP call. That makes the dev experience laggier and less pleasant.The symptom is especially noticeable when using an Azure managed database product such as Azure PostgreSQL or Azure SQL. The connection strings to these services include the access token (such as via EF Core interceptors), and the token is requested on every single connection. Without the cache, every DB request results in a new HTTP token request.
Given that
ManagedIdentityCredential
has got the fancy token cache implementation (borrowed from MSAL I believe), I'd imagine it should not be much work to extend the feature to other Azure credentials such asAzureCliCredential
, which will makeAzure.Identity
truly a flawless replacement forAppAuthentication
.The text was updated successfully, but these errors were encountered: