FIXED: App Service unable to connect to Cosmos database with private endpoints - RemoteCertificateNameMismatch

TH-4622 20 Reputation points
2025-02-13T07:59:14.24+00:00

Hi, I have a problem with a new Cosmos account service. I have never deployed one before.

Both the App Service and the Cosmos database account have private endpoints. Both private endpoints are in the same vnet and subnet. It seems the App Service cannot connect to the Cosmos database due to RemoteCertificateNameMismatch.

All references to resources use standard Microsoft FQDNs as this is in Dev, so no custom certificates are used. As all certificates are therefore MS controlled I wouldn't have expected a RemoteCertificateNameMismatch to happen?

These are the steps that the application goes through…

  1. Uploads doc to blob storage
  2. Writes to SQL DB (not Cosmos) of the link to the file in blob storage
  3. Writes to SQL DB (not Cosmos) to create a conversation entry
  4. External library reads doc as filestream and converts/reads tokens
  5. Checks if doc is of certain size (txt size exceeds token limit set)
  6. Breaks down to chunks – the Log Stream on the backend App Service shows the following so confirms the process gets this far: Processed document alices-adventures-in-wonderland 1.pdf with content type application/pdf into 38 chunks
  7. Connect to the Cosmos database to upload the chunks to the database… this is the part that appears to be related to the failure.
  8. … app should then continue on to further steps

_
App Service backend application Log Stream:

2025-02-12T08:51:29.8020806Z       System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception._

2025-02-12T08:51:29.8020837Z        ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

2025-02-12T08:51:29.8020861Z          at System.Net.Security.SslStream.CompleteHandshake(SslAuthenticationOptions sslAuthenticationOptions)

2025-02-12T08:51:29.8020893Z          at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter]

_2025-02-12T08:51:29.8020924Z          at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
_
Any assistance/guidance would be very much appreciated.

Thanks,

Tim.

Azure Private Link
Azure Private Link
An Azure service that provides private connectivity from a virtual network to Azure platform as a service, customer-owned, or Microsoft partner services.
536 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,765 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,318 questions
{count} votes

Accepted answer
  1. Oury Ba-MSFT 20,341 Reputation points Microsoft Employee
    2025-02-14T21:12:16.0666667+00:00

    @TH

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer. Accepted answers show up at the top, resulting in improved discoverability for others.

    Issue:

    App Service unable to connect to Cosmos database with private endpoints - RemoteCertificateNameMismatch

    Solution:

    by removing.privatelink. and it works!If the resource is enabled with a private endpoint, you do not need to add the FQDN like privatelink.documents.azure.com instead, it should be CosmosDBAccountName.documents.azure.com

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. TH-4622 20 Reputation points
    2025-02-14T12:48:24.1666667+00:00

    FIXED!

    I went back over some settings with one of our developers and he noticed he had the connection string in an environment variable on the App Service with the .privatelink. section added which we know shouldn't have been there. This I guess caused the certificate mismatch. After removing .privatelink. it works!

    What we don't understand is how this got there as the dev would have copied this from the Keys section of the Cosmos Account which clearly doesn't list it with .privatelink in the name. That part is a bit of a mystery.

    Thanks for your assistance!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.