Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK v3 does not works locally with CosmosDB Emulator and Docker like SDK v2 does. #1551

Closed
FVilevski opened this issue May 21, 2020 · 21 comments

Comments

@FVilevski
Copy link

Describe the bug
We have some issues regarding working locally with CosmosDB Emulator and Docker itself.

We are trying to make a connection between CosmosDB Emulator that is installed on the host itself and Core API that is started inside Linux container on the same developer machine.

The problem is related to the SSL certificate that is intended for the localhost on the host itself, but not for the Linux container. We have checked everything on Microsoft docs pages for emulator, containers and SSL, Cosmos DB SDKs, and whatnot, but nothing has helped us. There is no case that solves this issue. There are topics for extracting SSL on pages, but we could not manage to make it work.

Since we are looking for a solution that works only for development mode (non-production) anything that can help us we will be happy to apply.

Here is a video link of the issue that I am talking about, works for SDK v2, but not for SDK v3: https://www.loom.com/share/767b5eb281cc40f7b464cbe9eb087467

To Reproduce
Here is the project sample from the video above:
https://drive.google.com/file/d/1FFtdAojde6JNbf_zHEFJzIBRGRhdNMm5/view

Expected behavior
Azure Cosmos SDK v3, should work like SDK v2. The same goes for new SDKs in the future like v4.

Actual behavior

  • .NET Core 2.x (Working sample)
    We have made it working for CosmosDB SDK 2 via code on the API itself that is ignoring SSL validation. This code is only available for Cosmos SDK 2 and not a case with SDK 3. We want to use the new Cosmos SDK and not be stuck in the past. For this to work we have used /AllowNetworkAccess and /Key flags of the emulator itself.

  • .NET Core 3.x (Not working sample)
    Unfortunately, there is no way you can add code to ignore validation in CosmosDB SDK 3, so we tried other mechanisms like exporting certificates and other stuff without any luck.

Solution
I know what should be changed in your code and if you agree I can make a fix for it from the master branch.

@j82w
Copy link
Contributor

j82w commented May 22, 2020

This looks like a duplicate of #1232

@ealsur
Copy link
Member

ealsur commented May 26, 2020

Did you follow the docs at https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#running-on-mac-or-linux ?

Are you exporting the certificate and importing it as described for Linux? Are you starting the emulator with network requests allowed?

@FVilevski
Copy link
Author

Did you follow the docs at https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#running-on-mac-or-linux ?
The link that you have provided is for Linux or Mac OS that run VM with Windows, but as you can see from the video I am on windows with the emulator that is not on VM. To answer your question, yes we have done and did not solve the problem, having in mind that, that documentation is not for us.

(Are you exporting the certificate and importing it as described for Linux?)
Again... I need it to work on the Linux docker container, not on the Linux machine with VM as described in the docs, but yes as you can see in my description above, we have tried to move the certificate into a container itself and it does not solve our problem.

Are you starting the emulator with network requests allowed?
Yes, as you can see from my video as well.

@ealsur
Copy link
Member

ealsur commented May 26, 2020

So in your case you are running on Windows, and the Emulator is on that Windows machine, but the App is running on a Windows Docker container? Or is it a Linux Docker container?

If it's a Linux Docker container, the docs are valid, I tested the same scenario, Windows machine with Emulator, running Ubuntu docker image with a NET Core app inside. I had to export and import the cert into the docker image. The key there was that each distro might use a different directory for certificates.

Another thing. I see in your video that you are changing the Endpoint and using the Docker URL, the problem is basically that the Certificate that the Emulator uses is only for localhost, not for the Docker URL. That will always fail, because the Urls don't match (a certificate is valid for the Url it was created for). Is there a chance you can actually use localhost or 127.0.0.1 to connect to the Emulator?

@FVilevski
Copy link
Author

App is running on a Windows Docker container? Or is it a Linux Docker container?
We have a core 3.1 app that is running inside a Linux docker container.

If it's a Linux Docker container, the docs are valid, I tested the same scenario, Windows machine with Emulator, running Ubuntu docker image with a NET Core app inside. I had to export and import the cert into the docker image. The key there was that each distro might use a different directory for certificates.
How do you communicate with the emulator then because emulator cert is for localhost as you said in your post?

Is there a chance you can actually use localhost or 127.0.0.1 to connect to the Emulator?
This question is contrary to what you said... Far as I know, there is no way, because Docker URL is a shared network between host itself and containers. Maybe you know some way because you said it is working for you?

Just to note and you can see from the video too, there is no problem whatsoever with SDK v2. Please revert back the functionality as before. We have +30 devs that are waiting on this issue. This post is duplicate as j82w said.

@FVilevski
Copy link
Author

FVilevski commented May 26, 2020

I have provided a small code sample in the first post, please take it, change it, and make it work for Core 3.1. Then upload the working scenario or you can record screen as well. Not just you, but anybody that thinks this is doable.

Update 1: I just saw that you have new version from 6 days ago with #1441 merged. Maybe this can help us somehow, but I have to test it.

@ealsur
Copy link
Member

ealsur commented May 27, 2020

Step 1 - Export the Certificate

The certificate needs to be a PFX, not CRT. It will ask you to set some password.

Step 2 - Place the cert somewhere you can copy or access from docker

I wrote a small Console App with the following code:

private static string EndpointUrl = "https://localhost:8081";
        private static string PrimaryKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";

        public static async Task Main(string[] args)
        {
            CosmosClient client = new CosmosClient(EndpointUrl, PrimaryKey, new CosmosClientOptions(){ ConnectionMode = ConnectionMode.Gateway });
            Container container = client.GetContainer("test", "test");
            ItemResponse<dynamic> response = await container.ReadItemAsync<dynamic>("test", new PartitionKey("test"));
            Console.WriteLine(JsonConvert.SerializeObject(response.Resource));
        }

And I placed the cert in the folder with the source code.

image

Then I went to the Emulator and created a container and an item inside (I did this on Windows, not docker):
image

Step 3 - Get your machine's IP address

As per https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#running-on-mac-or-linux, I used ipconfig and got my IP.

Step 4 - Start a docker image

In my case, I use one with the NET Core 3.1 SDK, the official one from https://docs.microsoft.com/en-us/dotnet/architecture/microservices/net-core-net-framework-containers/official-net-docker-images

I started the container with an interactive shell, and mapping localhost to the IP I got on Step 3.

docker run -v /c/DockerSample:/DockerSample --add-host="localhost:192.168.1.15" -it mcr.microsoft.com/dotnet/core/sdk:3.1 /bin/bash

And I'm also mounting the folder where I saved the project and the certificate I want to import. This is not required, but I'm not fluent on Docker to know if there is a better way to pass the certificate.

After the shell starts, I basically run the commands described in the doc and the certificate gets added.

image

Step 5

Run the app from inside docker, I used dotnet run. Here is the same app code running both in the Docker container and on the Windows prompt:

image

Basically, I followed https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#linux plus the previous part where I had to obtain the IP.

@priyankajayaswal1
Copy link

Instead of 5 steps above, a disableSSLVerification feature might be more convenient from dev perspective as is present in python azure-cosmos sdk and azure-cosmos-js.

@brice-prunier-dev
Copy link

Hi,
I'm facing the same issue.
We currently have an application on .net Core 2.2 working perfectly well on which we can develop locally via the CosmosDb Emulator. We are trying to upgrade this application to .net Core 3.1 but there is no way to validate our migration work by running the app locally (on cosmosdb emulator) to go through none regression tests.

Side by side the app on .net core 2.2 works locally but not the one on .net Core 3.1.

I've tried to run the CosmosDb Emulator on a docker container without any success.

By setting an IHttpClientFactory to bypass SSL certificate validation i got the following error:

Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate success: ServiceUnavailable (503); Substatus: 0; ActivityId: 00000000-0000-0000-0000-000000000000; Reason: (

<TITLE>Network Error</TITLE>
Network Error (tcp_error)

A communication error occurred: ""
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.

For assistance, contact your network support team.

RequestUri: https://127.0.0.1:8081//addresses/?$resolveFor=dbs%2fiJ1ZAA%3d%3d%2fcolls%2fiJ1ZAPfNpqM%3d%2fdocs&$filter=protocol eq rntbd&$partitionKeyRangeIds=0;
RequestMethod: GET;
Header: x-ms-date Length: 29;
Header: Authorization Length: 80;
Header: x-ms-version Length: 10;
Header: User-Agent Length: 100;
Header: Request-Id Length: 29;
, Request URI: //addresses/?$resolveFor=dbs%2fiJ1ZAA%3d%3d%2fcolls%2fiJ1ZAPfNpqM%3d%2fdocs&$filter=protocol%20eq%20rntbd&$partitionKeyRangeIds=0, RequestStats: Please see CosmosDiagnostics, SDK: Windows/10.0.17134 cosmos-netstandard-sdk/3.10.0);

For my migration i 'am moving from Microsoft.Azure.Cosmos 3.6 (.net Core 2.2) to Microsoft.Azure.Cosmos 3.10.1 (.net core 3.1 ) and from what i see on debug the CosmosClient class seem to have change a lot.

This is a "Go To Production" blocking issue. Do we need to stop all our migrations to .net core 3.1 on CosmosDB or is there some work around.

Regards

@brice-prunier-dev
Copy link

I continue my investigation, on CosmosDB on Docket and .net Core 3.1.

-What i don't understand is: Why i can open CosmosDb Emulator in a broswer and then query it but not from my API.
What is that "Creating RNTBD TransportClient with options Rntbd.TransportClient.Options" is messing up the request ?
Is it the "ConnectionMode: Direct, connection Protocol: Tcp" that is wrong ?

Here under what i got from my Visual Studio Ouput console:

'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.5\System.Net.ServicePoint.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
Store.Services.AppSubscriptionRepository: Information: Endpoint=https://localhost:8081; Key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
DocDBTrace Information: 0 : DocumentClient with id 2 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1
DocDBTrace Information: 0 : RntbdConnectionDispenser: requestTimeoutInSeconds: 10, openTimeoutInSeconds: 5, timerValueInSeconds: 1

DocDBTrace Information: 0 : Creating RNTBD TransportClient with options Rntbd.TransportClient.Options
OpenTimeout: 00:00:05
RequestTimeout: 00:00:10
TimerPoolResolution: 00:00:01
MaxChannels: 65535
PartitionCount: 1
MaxRequestsPerChannel: 30
ReceiveHangDetectionTime: 00:01:05
SendHangDetectionTime: 00:00:10
IdleTimeout: -00:00:01
EnableCpuMonitor: True
UserAgent: cosmos-netstandard-sdk/3.10.1|3.10.0|02|X64|Microsoft Windows 10.0.17134|.NET Core 3.1.5|F 00000010| Suffix:
CertificateHostNameOverride:

DocDBTrace Error: 0 : DocumentClientException with status code: NotFound, message: Message: {"Errors":["Resource Not Found"]}
ActivityId: 1df382ed-8c7b-4cd4-a3e5-f2371e05c995, Request URI: /apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, RequestStats:
RequestStartTime: 2020-06-20T09:57:09.4977359Z, RequestEndTime: 2020-06-20T09:57:09.5187131Z, Number of regions attempted:1
ResponseTime: 2020-06-20T09:57:09.5187131Z, StoreResult: StorePhysicalAddress: rntbd://172.18.71.68:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 12, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#12, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Read
ResponseTime: 2020-06-20T09:57:09.5187131Z, StoreResult: StorePhysicalAddress: rntbd://172.18.71.68:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 12, GlobalCommittedLsn: -1, PartitionKeyRangeId: , IsValid: True, StatusCode: 404, SubStatusCode: 0, RequestCharge: 1, ItemLSN: -1, SessionToken: -1#12, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Read
, SDK: Microsoft.Azure.Documents.Common/2.11.0, and response headers: {
"Transfer-Encoding": "chunked",
"Server": "Microsoft-HTTPAPI/2.0",
"Access-Control-Allow-Origin": "",
"Access-Control-Allow-Credentials": "true",
"x-ms-last-state-change-utc": "Sat, 20 Jun 2020 09:51:20.369 GMT",
"lsn": "12",
"x-ms-schemaversion": "1.9",
"x-ms-quorum-acked-lsn": "12",
"x-ms-current-write-quorum": "1",
"x-ms-current-replica-set-size": "1",
"x-ms-xp-role": "0",
"x-ms-global-Committed-lsn": "-1",
"x-ms-number-of-read-regions": "0",
"x-ms-transport-request-id": "45",
"x-ms-cosmos-llsn": "12",
"x-ms-cosmos-quorum-acked-llsn": "12",
"x-ms-session-token": "0:-1#12",
"x-ms-request-charge": "2",
"x-ms-serviceversion": "version=2.11.0.0",
"x-ms-activity-id": "1df382ed-8c7b-4cd4-a3e5-f2371e05c995",
"x-ms-gatewayversion": "version=2.11.0",
"Date": "Sat, 20 Jun 2020 09:57:09 GMT",
}
DocDBTrace Error: 0 : Operation will NOT be retried. Current attempt 0, Status Code: NotFound
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.5\System.Diagnostics.StackTrace.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Regards

@brice-prunier-dev
Copy link

Ok guy, one step further

On my CosmosClientOptions I put ConnectionMode = ConnectionMode.Gateway but guess what CosmosClient try to turn it into a Direct Mode (Tcp) on my container Ip address ???
And it starts looping "Marking endpoint https://172.18.71.68:8081/ unavailable for read"

Just one word: HELP.

DocDBTrace Information: 0 : DocumentClient with id 1 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Gateway, connection Protocol: Https, and consistency level: null
Store.Services.AppSubscriptionRepository: Information: Endpoint=https://localhost:8081; Key: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
DocDBTrace Information: 0 : DocumentClient with id 2 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1
DocDBTrace Information: 0 : RntbdConnectionDispenser: requestTimeoutInSeconds: 10, openTimeoutInSeconds: 5, timerValueInSeconds: 1
DocDBTrace Information: 0 : Creating RNTBD TransportClient with options Rntbd.TransportClient.Options
OpenTimeout: 00:00:05
RequestTimeout: 00:00:10
TimerPoolResolution: 00:00:01
MaxChannels: 65535
PartitionCount: 1
MaxRequestsPerChannel: 30
ReceiveHangDetectionTime: 00:01:05
SendHangDetectionTime: 00:00:10
IdleTimeout: -00:00:01
EnableCpuMonitor: True
UserAgent: cosmos-netstandard-sdk/3.10.1|3.10.0|03|X64|Microsoft Windows 10.0.17134|.NET Core 3.1.5| Suffix:
CertificateHostNameOverride:

DocDBTrace Information: 0 : TimerPool Created with minSupportedTimerDelayInSeconds = 1
DocDBTrace Information: 0 : CpuMonitor started
The thread 0x5394 has exited with code 0 (0x0).
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.5\System.Net.Requests.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DocDBTrace Warning: 0 : Endpoint not reachable. Refresh cache and retry
DocDBTrace Information: 0 : Marking endpoint https://172.18.71.68:8081/ unavailable for read
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : Endpoint https://172.18.71.68:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 06/20/2020 10:23:54
DocDBTrace Warning: 0 : Endpoint not reachable. Refresh cache and retry
DocDBTrace Information: 0 : Marking endpoint https://172.18.71.68:8081/ unavailable for read
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : Endpoint https://172.18.71.68:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 06/20/2020 10:23:55
DocDBTrace Warning: 0 : Endpoint not reachable. Refresh cache and retry
DocDBTrace Information: 0 : Marking endpoint https://172.18.71.68:8081/ unavailable for read
DocDBTrace Information: 0 : Current WriteEndpoints = (https://172.18.71.68:8081/) ReadEndpoints = (https://172.18.71.68:8081/)
DocDBTrace Information: 0 : Endpoint https://172.18.71.68:8081/ unavailable for Read added/updated to unavailableEndpoints with timestamp 06/20/2020 10:23:56
DocDBTrace Warning: 0 : Endpoint not reachable. Refresh cache and retry

@brice-prunier-dev
Copy link

Hello everybody,

End of the weekend and by the way end of this issue :)

As for every thing in IT it is so simple once you identify the root cause...

My problem was the following: I'm on my professional laptop that is secured:

To access internet or my my corporate intranet i have to go through my corporate proxy that is set through a proxy.pac set by a policy at the start up.

In my global settings the NO_PROXY variable includes localhost ... but not 127.0.0.1.

As i showed in the here above threads the CosmosClient once it identifies a localhost call continue with 127.0.0.1 as host.
If if you forget to set it in your NO_PROXY setting it doesn't use the loop back and goes external on your proxy .... and CosmosDb Emulator is not working.

So by just setting "127.0.0.1" and "localhost" at start of yours NO_PROXY global setting you don't need to setup CosmosDB Emulator on Docker, on local it works perfectly well.

So long muchachos...

@FVilevski
Copy link
Author

@ealsur Is there a possible way to have some property for disabling SSL as @priyankajayaswal1 suggested?

@ealsur
Copy link
Member

ealsur commented Jun 26, 2020

@FVilevski the discussion the team had back in the day was around the dangers of such a direct property. If there were such a property and the code was pushed to production (accidentally hopefully), it would mean all data communications would be totally unsecure and your application is now subject to data breach scenarios.

Since this is a dev only scenario (you'd never use the Emulator on production) the steps to setup the required components (while I agree troublesome) make sure that when you push it to production, there is no way you can generate an insecure scenario.

I agree also that in hybrid scenarios, the whole SSL certificate dance represent extra steps and if you use docker, then it also implies powershell scripts. Ideally this would be solved (on the most part) with an Emulator that works on Linux (which is something that the team is still working on).

@D3MaxT
Copy link

D3MaxT commented Jul 29, 2020

No offence, but you are treating developers like children. Let us worry about accidental pushes to production. Especially considering the other SDKs already have this added.

@j82w
Copy link
Contributor

j82w commented Jul 29, 2020

@D3MaxT can you not use the HttpClientFactory to disable the SSL validation and switch the client to gateway mode?

@ealsur
Copy link
Member

ealsur commented Jul 29, 2020

@j82w HttpClientFactory will work but it is not yet included in any release.

After the next release, this should work:

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
    HttpClientFactory = () =>
    {
        HttpMessageHandler httpMessageHandler = new HttpClientHandler()
        {
            ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true
        };
        return new HttpClient(httpMessageHandler);
    },
    ConnectionMode = ConnectionMode.Gateway
};


CosmosClient client = new CosmosClient("https://localhost:8081", 
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", 
    cosmosClientOptions);

Or if you are using a NET Standard 2.1 project:

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


CosmosClient client = new CosmosClient("https://localhost:8081", 
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", 
    cosmosClientOptions);

@D3MaxT
Copy link

D3MaxT commented Jul 29, 2020

@j82w, I will once it works (as @ealsur mentioned).
But my point in general was that developers should be trusted a bit more and this should be made easier, especially considering other Cosmos SDKs have this functionality already. Why is .NET SDK being treated differently?

@j82w
Copy link
Contributor

j82w commented Aug 7, 2020

3.12.0 is released with the necessary changes.

@ealsur example above will now work just like in v2 SDK.

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
    HttpClientFactory = () =>
    {
        HttpMessageHandler httpMessageHandler = new HttpClientHandler()
        {
            ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true
        };
        return new HttpClient(httpMessageHandler);
    },
    ConnectionMode = ConnectionMode.Gateway
};


CosmosClient client = new CosmosClient("https://localhost:8081", 
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", 
    cosmosClientOptions);

Or if you are using a NET Standard 2.1 project:

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


CosmosClient client = new CosmosClient("https://localhost:8081", 
    "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", 
    cosmosClientOptions);

@j82w j82w closed this as completed Aug 7, 2020
@InquisitorJax
Copy link

man - I wish I'd have found this thread sooner :(

@FVilevski
Copy link
Author

@j82w, @ealsur Excellent news, I have tested now and it is working like it supposed to, even better than older SDKs.

Thank you, guys! Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants