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.

How to use V3 CosmosClient with Emulator while ignoring SSL errors?

See original GitHub issue

Describe the bug Impossible to connect CosmosClient to Emulator while trying to ignore SSL certificates.

I already searched this repo and the web to find some information about how to ignore the SSL error if we try to connect to the emulator. All I could find was some hints on how to solve these problems on V2 DocumentClient (like #42), but nothing for V3 CosmosClient.

I dig through the public interface of the class, their options, etc. and the only maybe promising I could find was the Collection<RequestHandler> CustomHandlers. So I wrote my own handler (see below), added it to the options new CosmosClient(EndPoint, Key, new CosmosClientOptions { CustomHandlers = { new IgnoringSSLErrorsRequestHandler() } }); and guess what, it won’t be called (so I also don’t know if the implementation is correct or does really work).

Expected behavior Some code example on how it is possible to instantiate an CosmosClient that will ignore SSL errors.

Actual behavior Nothing is available to work around this problem, except importing the certificate to the windows certificate store, but we need some solution in pure code.

Environment summary SDK Version: 3.6.0 OS Version: Windows

Additional context

internal class IgnoringSSLErrorsRequestHandler : RequestHandler
{
    private readonly HttpClient _httpClient;

    public IgnoringSSLErrorsRequestHandler()
    {
        var messageHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = (req, cert, chain, errors) => true };
        _httpClient = new HttpClient(messageHandler);
    }

    public override async Task<ResponseMessage> SendAsync(RequestMessage request, CancellationToken cancellationToken)
    {
        var httpRequest = new HttpRequestMessage
        {
            Method = request.Method,
            RequestUri = request.RequestUri,
        };

        foreach (var headerKey in request.Headers.AllKeys())
        {
            httpRequest.Headers.Add(headerKey, request.Headers[headerKey]);
        }

        foreach (var kvp in request.Properties)
        {
            httpRequest.Properties.Add(kvp);
        }

        var response = await _httpClient.SendAsync(httpRequest, cancellationToken);

        return new ResponseMessage(response.StatusCode, request)
        {
            Content = await response.Content.ReadAsStreamAsync()
        };
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:28 (9 by maintainers)

github_iconTop GitHub Comments

19reactions
joshystuartcommented, Jun 16, 2020

When thinking about how to allow us to get past this SSL issue (without the huge ‘create a special cert for Docker, blah blah’)

I gave up trying to work around the ssl issue, and I am currently trying to get a custom cosmos docker image to work.

Honestly, this has been the biggest waste of dev time in my entire life. The MS Cosmos team should add a no SSL config option; just like the rest of the tools we use! You dont have to run mongo, mysql, etc etc locally with a cert… you can if you want to, but it isn’t mandatory. That’s the part that annoys me most; treating developers with kid gloves!

14reactions
olivermuecommented, Feb 27, 2020

I’d really like to NOT import a certificate somewhere. I’d like to use the emulator locally without validating the certificate in my test code. That should really be possible, especially for testing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Allow invalid CosmosDB Emulator certificate with ...
Getting around SSL issues when using CosmosDB's Docker-based emulator and ... the following functionality for ignoring certificate issues:.
Read more >
Export the Azure Cosmos DB Emulator certificates
Learn how to export the Azure Cosmos DB Emulator certificate for use with languages and environments that don't integrate with the Windows ...
Read more >
Azure Cosmos DB SQL API client library for Python
Use the Azure Cosmos DB SQL API SDK for Python to manage databases and the JSON documents they contain in this NoSQL database...
Read more >
Btc Directory Azure Websites Net Warning Understand Works
How to use V3 CosmosClient with Emulator while ignoring. Url unblocker v2. However, your history and identity is still fragmented across the ...
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