[FEATURE REQ] Allow Microsoft.Extensions.Azure to select more TokenCredentials #47927
Labels
Client
This issue points to a problem in the data-plane of the library.
Extensions
ASP.NET Core extensions
feature-request
This issue requires a new behavior in the product in order be resolved.
Milestone
Library name
Microsoft.Extensions.Azure
Please describe the feature.
Problem statement
Some users encounter issues when running in environments where there is a mix of identities, and
DefaultAzureCredential
probing creates a surprise. For example:When setting up
DefaultAzureCredential
imperatively, we can useDefaultAzureCredentialOptions.ExcludeManagedIdentityCredential
, but this is not available when only using the configuration-based approach. This notably occurs when configuring Azure Functions triggers and bindings through the WebJobs extensions found in this repo.Proposed feature
One of the simplest options is probably to leverage the behavior already in place to use configuration to select between a few
TokenCredential
options inMicrosoft.Extensions.Azure
. For example, thecredential
property can be set to "managedidentity" to shift the behavior fromDefaultAzureCredential
toManagedIdentityCredential
:azure-sdk-for-net/sdk/extensions/Microsoft.Extensions.Azure/src/Internal/ClientFactory.cs
Line 116 in 6d8cf4a
There is also a variant for
WorkloadIdentityCredential
. The proposal would be to introduce additional options:credential
valueTokenCrednetial
implementationVisualStudioCredential
AzureCliCredential
There may be other TokenCredentials of interest as well, but these would help with the scenarios where I've been encountering more issues with Functions customers.
AzureCliCredential
is specifically included based on patterns I've seen for ADO pipelines. Users will perform a CLI login through the service connection and then leverageAzureCliCredential
(from code where they had imperative options), which has a simple setup process from within code. That of course can also be leveraged even throughDefaultAzureCredential
ifExcludeManagedIdentityCredential
is set. This seems to be preferable to setting upAzurePipelinesCredential
in many cases, especially when you still want to leverage flexibility of local development workflows offered byDefaultAzureCredential
.Alternatives considered
In some ways it might be simpler to introduce a new configuration option to represent
ExcludeManagedIdentityCredential
. However, I don't think we want to map that through for all of theExclude*
options. Leveraging the existingcredential
property feels like a more bounded scope.It may also make sense to set up an
AzurePipelinesCredential
option, but I see its constructor takes a few additional properties beyondclientId
andtenantId
, which are already defined. I don't know how cleanly those can be mapped into configuration. In particularsystemAccessToken
gives me pause. It looks like that might have a defined environment variable that should be used already, but samples show that being captured in user code and passed into the constructor. This would need evaluation by someone before being undertaken.The text was updated successfully, but these errors were encountered: