azure-webjobs-sdk-extensions: Cosmos DB trigger is not connecting to CosmosDB Emulator
Hi Azure Functions Team, I have an Azure Functions App consisting of HttpTrigger Functions and CosmosDbTrigger Functions. Both kind of functions work fine and can connect against an actual CosmosDB instance. Unfortunately, when running against the CosmosDB emulator the CosmosDBTrigger Functions fail to connect against the CosmosDB emulator. The errors that I receive are of the following form:
[2022-01-15T18:17:06.601Z] Error indexing method 'Functions.feed'
[2022-01-15T18:17:06.601Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.feed'. Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection Information for Article in database ##-db with lease leases in database ##-db : The SSL connection could not be established, see inner exception. System.Net.Http: The SSL connection could not be established, see inner exception. System.Private.CoreLib: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch.
The settings of the app look like below:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=###;AccountKey=###;EndpointSuffix=core.windows.net",
"FUNCTIONS_WORKER_RUNTIME": "node",
"DATABASE_CONNECTION_STRING": "AccountEndpoint=https://##.###.###.###:8081/;AccountKey=<DEFAULT_PRIMARY_KEY>"
}
}
Though, the remaining HttpTrigger functions can communicate with the CosmosDB emulator via the SDK’s CosmosClient. For this to work NODE_TLS_REJECT_UNAUTHORIZED=0 is set. But as the error looks like coming form the .NET functions tool itself not from any of our node application, it looks like this setting is not helping.
The CosmosDB emulator is setup as lined out in an answer to #1232 with the deviation that the local development is done on OSX, which is why the certificate import is different. And it looks like the imported certificate is ignored by .NET.
I believe a similar, if not same question was raised in #2024 was closed, but not solved. At least nothing I can find there helps me in resolving the described issues.
I’m not sure what else to try and would really appreciate any help at all 😃
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (11 by maintainers)
Do you build the Functions mostly on C#? I think that a solution like the second one (add a config as a boolean value) could be the one that tackles this problem across languages.
With Extension 4.5.0 now you can use the ConnectionString to the emulator with the added flag to disable SSL.
Example:
@ealsur yes that is absolutely true, but how does this differ or add value when I can bypass SSL when using the same cosmosdb in the same solution with my web APIs(because the CosmosClient here exposes this possibility to us Devs)?
Meanwhile in the same solution I can spawn a SQL server container in a similar way and connect to it without being forced to use SSL(yes, different persistence tech but it’s still people from Microsoft following the same security guidelines while producing it, right?).
It seems to me that forcing SSL in the emulator, only in the cosmosdb + az function combo, causes more harm than anything else…
I can agree that it’s a good thing to be secure by default, but I think we should be able to disable SSL here as we can do in other cases(API-cosmosdb connection).
I’m trying my best to demonstrate my team and bosses that “developing in Linux containers is the best thing ever, as well as the future” but if I can’t get our most used services to work together I doubt I will be able to convince them 😃
Thank you again for your precious time, if you read me
If you decide not to modify the trigger, I’d really like some guidance on how to get this part to work together with an actual example, and I’d be happy to help contributing to the docs if you need any help!
Hi @ealsur “But really the point is that disabling SSL is just a shortcut to avoid dealing with installing the certificate” Yes, indeed. Because when I move in production, i don’t expect to have the need to install a certificate while pointing to an actual instance of cosmosdb, so why should I do it in my local env?
Also I understand that I could probably get everything to work spinning up the emu container or the actual program via a script if I was on my windows machine, but the point is that I’m using codespaces so I would have to do something like: Spin up cosmos container
Either rebuild and download/trust the generated cert or build an image that starts with a bash script that only spins up my function after downloading the emulator cert and trusting it.
This seems overly complicated to me to do something that I’m not expected to be doing in an actual environment, but I’m open to suggestions.
I understand it’s more a problem with the emulator forcing me to use the Https endpoint and not this trigger fault but I find strange that something this simple is becoming so hard ahah
Thank you anyway for your help!
Hi @ealsur I understand what you mean, just a question: do you think I have a way to override the default CosmosClient used by your implementation of “CosmosDBTrigger” through dependency injection?
Because if i could, i would be able to use the HttpFactoryOptions like i did here to ignore the certificate: https://github.com/MACEL94/advanced-azure-microservices-with-dotnet-for-developers/blob/9-manage-to-make-everything-work-locally-with-just-a-docker-compose-up/src/WisdomPetMedicine.Hospital.Infrastructure/PatientAggregateStore.cs#L27
thank you again for your time
Hi @ealsur @michaelpeng36
i’m developing a simple but complex enough example to really try to understand how developing in containers would really be for me and my team in next projects. I’m really finding it hard to solve this simple thing of triggering my azfunction
i’m using everything with the latest packages and everything is public beside the secret i was required to create(not my choice) to be able to use azure service bus.
if you want to repro this bug i believe i can help, if you want to take a look here: https://github.com/MACEL94/advanced-azure-microservices-with-dotnet-for-developers/tree/9-manage-to-make-everything-work-locally-with-just-a-docker-compose-up
everything is on linux as i’m trying to develop on codespaces
thank you anyway for your help