Azure / Azure/azure-functions-dotnet-worker

Cosmos DB Extension HttpClientFactory Setting Not Applied in Function App Behind Corporate Proxy

Open
#3,018 0 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions) potential-bug
Dominant language
C#
Stars
466
Forks
215
Avg merge
3d 10h
Merged PRs (30d)
7

Description

### Description

When running an Azure Function App behind a corporate proxy with a Cosmos DB account configured to use a private endpoint, the custom configuration to disable the proxy (i.e., setting UseProxy = false via the HttpClientFactory) does not take effect. In a Console App, the following configuration works as expected:

```csharp
CosmosClientOptions options = new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway,
HttpClientFactory = () =>
{
var handler = new HttpClientHandler
{
UseProxy = false
};
return new HttpClient(handler);
}
};
```

However, when applying a similar configuration within a Function App:

```csharp
FunctionsApplicationBuilder builder = FunctionsApplication.CreateBuilder(args);

builder.ConfigureFunctionsWebApplication();

builder.ConfigureCosmosDBExtensionOptions(options =>
{
options.ClientOptions.ConnectionMode = ConnectionMode.Gateway;
options.ClientOptions.HttpClientFactory = () =>
{
var handler = new HttpClientHandler
{
UseProxy = false,
};
return new HttpClient(handler);
};
});

IHost host = builder.Build();
host.Run();
```
**Environment Details:**

**Project Configuration:**

Target Framework: net9.0

Azure Functions Version: v4

Output Type: Exe

Implicit Usings: Enabled

Nullable: Enabled

**Package References:**

Microsoft.Azure.Functions.Worker: 2.0.0

Microsoft.Azure.Functions.Worker.Extensions.CosmosDB: 4.12.0

Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore: 2.0.1

Microsoft.Azure.Functions.Worker.Sdk: 2.0.2

Framework Reference: Microsoft.AspNetCore.App

### Steps to reproduce

1. Create an Azure Function App that uses the Cosmos DB extension.
2. Configure the Cosmos client in the Function App using ConfigureCosmosDBExtensionOptions to override the default HttpClient with one that sets UseProxy = false.
3. Run the Function App behind a corporate proxy where a private endpoint is required.
4. Observe that the Cosmos client still connects via the public IP instead of the private endpoint.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at the ConfigureCosmosDBExtensionOptions entry point and inspect how the Microsoft.Azure.Functions.Worker.Extensions.CosmosDB package constructs its client options. Reproduce the Function App configuration behind the proxy, then verify that the supplied HttpClientFactory and UseProxy = false setting are actually used and that the client reaches the private endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.