AzureSearch Oauth with ManagedIdentity using DefaultCredentials fallback results in a 403 #26595
Open
5 tasks done
Labels
Ɑ: vector store
Related to vector store module
Checked other resources
Example Code
When running in an AppService configured with a User assigned managed identity which has a number of permissions assinged I am unable to use the
AzureSearch
class.As noted in #26216 explicitly passing an access token fails.
However the workaround to of supplying
None
also does not work when trying to use ManagedIdentity rather than a less secure option like Service Principal based auth.Error Message and Stack Trace (if applicable)
Here are the logs from our AppService, I've redacted a few things but the important things are still here.
Description
In
azuresearch.py
the function_get_search_client
uses fallback logic if the value forkey
andazure_ad_access_token
areNone
then the logic on line 141 to build the SeachIndexClient looks like this:I believe that this is the cause of the failure as digging deeper into the internal logic of the Azure library there is logic that will try to read an
audience
from the kwargs. When the SearchClient is using a TokenCredential this value is used to generate the scope for the underlying token request.I believe that the fix for this issue is to modify the constructor call to pass the audience string for Azure search like this:
System Info
Running those commands on my dev machine results in failure, but I build a container image based on
python:3.12.5-slim-bookworm
that install following packaged via requirements,txtThe text was updated successfully, but these errors were encountered: