microsoft / microsoft/aspire

Support configuring HTTPS endpoint in YARP via extension methods

Open
#11,534 6 comments 0 reactions 0 assignees View on GitHub
area-integrations yarp
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Currently, YARP endpoints can be configured via extension methods, but there is no first-class way to support HTTPS endpoints with certificate configuration (pfx and pem) through these extension methods. This gap makes it challenging to securely expose endpoints in YARP containers and to map HTTPS settings from appsettings.json, as outlined in https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-9.0#configure-https-in-appsettingsjson. Developers need to be able to pass certificate information (path and password) directly to the container in a robust, first-class manner.

### Describe the solution you'd like

Add extension methods to YARP that enable configuring HTTPS endpoints, supporting certificate passing for both pfx and pem formats. The goal is to allow configuring endpoints using appsettings.json style configuration, such as:

```JSON
"Certificates": {
"Default": {
"Path": "",
"Password": "$CREDENTIAL_PLACEHOLDER$"
}
}
```

When HTTPS certificate information is provided, the endpoint should be added to the container as HTTPS, matching the configuration API for Kestrel. This should be a first-class experience for extension method users.

Additionally, set both HTTP_PORTS and HTTPS_PORTS environment variables when configuring endpoints to support both HTTP and HTTPS in containers.

Relevant code locations:
- [`src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs`](https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting.Yarp/YarpResourceExtensions.cs#L59-L82): Extension methods for resource configuration, e.g., `WithConfiguration`, `WithHostPort`.
- [`src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpCluster.cs`](https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting.Yarp/ConfigurationBuilder/YarpCluster.cs): Cluster and endpoint URI logic supporting HTTP/HTTPS endpoints.
- [`src/Aspire.Hosting.Yarp/IYarpJsonConfigGeneratorBuilder.cs`](https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting.Yarp/IYarpJsonConfigGeneratorBuilder.cs): Interface for building configuration files for YARP.
- [`playground/TestShop/TestShop.AppHost/Program.cs`](https://github.com/dotnet/aspire/blob/main/playground/TestShop/TestShop.AppHost/Program.cs#L64-L83): Example usage and configuration patterns.

This will enable secure, flexible endpoint exposure for YARP containers in Aspire applications.

### Additional context

- Support pfx and pem certificate formats for HTTPS endpoints.
- Integrate HTTPS endpoint configuration with extension methods for YARP resources.
- Map appsettings.json HTTPS configuration to YARP endpoints in the container.
- Update docs and samples as needed.
- See related code in `YarpResourceExtensions`, `YarpCluster`, and tests such as `YarpFunctionalTests.cs`.
- Ensure HTTP_PORTS and HTTPS_PORTS environment variables are set appropriately to enable both HTTP and HTTPS endpoints in containers.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.