Unable to skip SSL authentication when connecting to Emulator running in Linux Docker Container
See original GitHub issueHi 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:
- Created 2 years ago
- Comments:15 (6 by maintainers)
Top GitHub Comments
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.
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.