question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to skip SSL authentication when connecting to Emulator running in Linux Docker Container

See original GitHub issue

Hi there I am developing a C# .NET Core app (on windows) and want to connect to the cosmos emulator running in a linux docker container on docker desktop for windows. I don’t want to use SSL authentication so I try to make use of the most recent CosmosClient of Microsoft.Azure.Cosmos package. However, this doesn’t seem to work.

Steps to reproduce:

On a windows machine, pull the most recent image of the cosmos emulator

docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

Start up a new emulator container

docker run -p 8081:8081 -p 10251:10251 -p 10252:10252 -p 10253:10253 -p 10254:10254 -m 3g --cpus=2.0 --name=test-linux-emulator -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=true -it mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator

Navigate to _https://localhost:8081/_explorer/index.html_ and download the sample app for C# .NET Core.

Open the sample app in Visual Studio and update the Nuget package Microsoft.Azure.Cosmos to Version 3.20.1.

Open the class Program.cs and change the method GetStartedDemoAsync to skip SSL authentication:

public async Task GetStartedDemoAsync()
{
   CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
   {
       HttpClientFactory = () =>
       {
           HttpMessageHandler httpMessageHandler = new HttpClientHandler()
           {
               ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
           };
           return new HttpClient(httpMessageHandler);
       },
       ConnectionMode = ConnectionMode.Gateway
   };

   // Create a new instance of the Cosmos Client
   this.cosmosClient = new CosmosClient(EndpointUri, PrimaryKey, cosmosClientOptions);
   await this.CreateDatabaseAsync();
   await this.CreateContainerAsync();
   await this.ScaleContainerAsync();
   await this.AddItemsToContainerAsync();
   await this.QueryItemsAsync();
   await this.ReplaceFamilyItemAsync();
   await this.DeleteFamilyItemAsync();
   await this.DeleteDatabaseAndCleanupAsync();
}

Then hit F5 to run the program.

Expected result The program runs successfully.

Actual result The program hangs in this.CreateDatabaseAsync();, never returning and never creating a database.

PS: I posted this also on the emulator github project but I think here its the better place…

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
worldspawncommented, Mar 3, 2023
var addresses = Dns.GetHostAddresses("host.docker.internal");
.WithEnvironment("AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE", addresses[0].ToString())

Low and behold the solution has been available this whole time. But because there is no kind of reference documentation for the docker image (just a bunch of learn articles) no one knows wtf all the env variables are or what they do. Waste of a morning.

2reactions
davidguidalicommented, Sep 8, 2021

You’re right, I also think now it might be an issue with the emulator, since the official page only describes how to use the linux emulator on a linux host but not on a windows host. I will raise an issue to the emulator team. However, it still is strange that theres no error coming, even if I run it outside of VS as you suggested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to skip SSL authentication when connecting ...
I am developing a C# .NET Core app (on windows) and want to connect to the cosmos emulator running in a linux docker...
Read more >
How to bypass SSL and access cosmosDb emulator ...
I'm attempting to connect to the cosmosDb emulator installed locally on my windows machine via a docker container running a .net core webapi ......
Read more >
Run the Azure Cosmos DB Emulator on Docker for Linux
Learn how to run and use the Azure Cosmos DB Linux Emulator on Linux ... Optionally, you can disable TLS/SSL validation on your...
Read more >
Test an insecure registry
With insecure registries enabled, Docker goes through the following steps: First, try using HTTPS. If HTTPS is available but the certificate is invalid,...
Read more >
How to Fix the NET::ERR_CERT_AUTHORITY_INVALID ...
The NET::ERR_CERT_AUTHORITY_INVALID error occurs when a website's SSL certificate isn't trusted by the browser. Learn what's causing it and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found