CosmosDB 4.0.0-preview1 always throws an exception when AAD authentication is configured
See original GitHub issueWhenever I set up and run CosmosDBTrigger
or CosmosDB
to use AAD authentication, it throws a NullReferenceException
and fails to start.
I checked and found that AzureComponentFactory
is always passed null for DefaultCosmosDBServiceFactory
. The root cause seems to be that AddAzureClientsCore
is not registered in the DI.
Example (Service Bus Extension) : https://github.com/Azure/azure-sdk-for-net/blob/4162f6fa2445b2127468b9cfd080f01c9da88eba/sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Config/ServiceBusHostBuilderExtensions.cs#L91-L93
Repro steps
- Create new function (v3) project
- Add
CosmosDBTrigger
function - Update
Microsoft.Azure.WebJobs.Extensions.CosmosDB
version4.0.0-preview1
- Setup RBAC and connection string
- Run function app
Expected behavior
An error always occurs when starting Function.
[2021-09-01T15:07:18.499Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function2'.
Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create container information for TodoItem in database SampleDB with lease leases in database SampleDB : Object reference not set to an instance of an object.
Microsoft.Azure.WebJobs.Extensions.CosmosDB: Object reference not set to an instance of an object.
[2021-09-01T15:07:18.536Z] Error indexing method 'Function2'
Actual behavior
CosmosDBTrigger
and Managed Identity can be used without any errors.
Known workarounds
- Install
Microsoft.Azure.WebJobs.Extensions.Storage
(At the same time,AddAzureClientsCore
is added to the DI, so)
Related information
Microsoft.Azure.WebJobs.Extensions.CosmosDB
:4.0.0-preview1
- https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions.CosmosDB/Config/CosmosDBWebJobsBuilderExtensions.cs#L21-L38
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Troubleshoot Azure Cosmos DB forbidden exceptions
If the request came to Azure Cosmos DB via the expected path, request was blocked because the source network identity was not configured...
Read more >Azure Cosmos DB extension for Azure Functions update with ...
... Azure Cosmos DB extension for Azure Functions uses the latest Azure Cosmos DB .NET SDK to add support for Azure AD authentication....
Read more >Spring Cloud Azure - Reference Documentation
Starter for using Azure Cosmos DB and Spring Data Cosmos DB ... To configure how to authenticate with Azure Active Directory for one...
Read more >Azure Cosmos DB (SQL API)
Azure Active Directory (Azure AD) authentication. The Azure Cosmos DB state store component supports authentication using all Azure Active Directory mechanisms.
Read more >Azure Cosmos DB client throws "HttpRequestException
HttpRequestException : An attempt was made to access a socket in a way forbidden by its access permissions. I use following configuration:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed in preview2 release
@shibayan sent a PR with the fix, thanks for reporting