Skip to content

Configuring the HttpClientHandler (& Client Certs) #137

Closed

Description

@Tratcher

What should we add or change to make your life better?

The application needs to be able to configure attributes on the outbound HttpClient / SocketHttpHandler / HttpClientHandler per backend and/or backend endpoint, especially client certificates.

Client certificates for backend endpoints should be configurable in the config file as well as in code.

Why is this important to you?

Service-to-service mutual authentication.

Activity

  1. added
    Type: Idea
    on May 4, 2020
  2. Tratcher commented on May 5, 2020

    @Tratcher
    MemberAuthor
  3. added this to the 1.0.0 milestone on May 12, 2020
  4. Tratcher commented on May 26, 2020

    @Tratcher
    MemberAuthor

    Note we've now had two partners need to customize server cert validation because of self-signed certs. The workaround at the moment is to replace the entire ProxyHttpClientFactory in DI.

  5. Tratcher commented on Jun 18, 2020

    @Tratcher
    MemberAuthor

    Consolidated from #253

    Requirements:

    • Ability to specify SocketsHttpHandler.SslClientAuthenticationOptions.RemoteCertificateValidationCallback per backend
    • Ability for that to be set up to depend on Backend config. Internally, we have an implementation that works efficiently using Signals
      • When a backend's config changes, a derived signal produces a new cert validation callback lambda
      • In the hot-path, cert validation just calls the latest validation lambda produced by the signal, which always tracks the backend config

    Why is this important to you?

    Compliance requirement. YARP isn't an option for us without this.

  6. Tratcher commented on Jul 2, 2020

    @Tratcher
    MemberAuthor

    Also: The ability to add a DelegatingHandler for advanced customization. #283

  7. samsp-msft commented on Jul 9, 2020

    @samsp-msft
    Contributor

    Need to be able to tweak the handler on a per cluster basis.

    Need to consider the association between httpClient and clusters/destinations. Are httpclient instances created on a per cluster basis. What happens if destinations are used in multiple clusters.

  8. Tratcher commented on Jul 10, 2020

    @Tratcher
    MemberAuthor

    Island gateway explicitly does not want a destination in multiple clusters to share connections or HttpClient instances. They want to limit the impact different clients/routes can have on each other.

    This is the current behavior.

  9. Tratcher commented on Jul 14, 2020

    @Tratcher
    MemberAuthor

    Implementation notes:
    IProxyHttpClientFactory is split into two APIs, CreateNormalClient() and CreateUpgradableClient(). The only difference is this additional line in the upgrade client:
    https://github.com/microsoft/reverse-proxy/blob/24c0c5a969bb025dd7a355f0b62ee4cbac96c99f/src/ReverseProxy/Service/Proxy/Infrastructure/ProxyHttpClientFactory.cs#L63
    @stephentoub confirmed that this is only an optimization used by the ClientWebSocket implementation because it knows none of its connections will ever be pooled. We don't need it in YARP.

    Proposal: Consolidate to a single CreateClient() API.

    Also, we should make these IProxyHttpClientFactory APIs public soon to unblock people, even if they're not the final APIs we want.

  10. Tratcher commented on Jul 21, 2020

    @Tratcher
    MemberAuthor

    Design proposals:

    • Remove IProxyHttpClientFactoryFactory
    • Make IProxyHttpClientFactory public
    • Change from calling CreateClient per request to only calling it when cluster config changes. Snapshot the client instance on the the ClusterConfig. Capture it at the start of the request pipeline with the rest of the snapshots.
    • ClusterConfig gets new proxy client options ProxyHttpClientOptions:
      • SSL validation options
      • Client certificates
      • Extensible config / metadata
    • CreateClient takes the new ProxyHttpClientOptions.
    • IProxyHttpClientFactory probably moves from ClusterInfo to ReverseProxyConfigManager where ClusterConfigs are created.

    Unresolved:

    What sugar should we have in Startup to help define these?

    • AddProxyClient(clusterDetails => new SocketsHttpHandler() => { })?
    • AddProxyClient((cluserDetails, socketHttpHandler) => {}) with pre-configured defaults?

    What guidance should we give people writing factories?

    • Don't use HttpClient, use HttpMessageInvoker, less overhead.
    • You could adapt in IHttpClientFactory here, but it would always return you an HttpClient.
    • Disable things we do in the default factory unless you really need them
      • Auto-redirects
      • Decompression
      • Cookies
      • UseProxy
  11. self-assigned this
    on Jul 23, 2020
  12. modified the milestones: 1.0.0, 1.0.0-preview4 on Jul 23, 2020
  13. removed their assignment
    on Aug 18, 2020
  14. amweiss commented on Aug 19, 2020

    @amweiss
    Contributor

    Hit an issue today where the underlying service returned a 301 with a relative URL and it attempted to find it on the YARP host instead of the route cluster. Presumably if we could set AllowAutoRedirect to true this would have worked.

  15. Tratcher commented on Aug 19, 2020

    @Tratcher
    MemberAuthor

    Hit an issue today where the underlying service returned a 301 with a relative URL and it attempted to find it on the YARP host instead of the route cluster. Presumably if we could set AllowAutoRedirect to true this would have worked.

    Proxies should not follow redirects, the client needs to see those. The redirect should be generated or rewritten using publicly accessible urls, relative or absolute. Please open a separate issue if you want to discuss rewriting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Partner Blocking: Island GatewayType: Idea

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions