cd686ffdf3
This change updates the TLS config used by all pinniped components. There are no configuration knobs associated with this change. Thus this change tightens our static defaults. There are four TLS config levels: 1. Secure (TLS 1.3 only) 2. Default (TLS 1.2+ best ciphers that are well supported) 3. Default LDAP (TLS 1.2+ with less good ciphers) 4. Legacy (currently unused, TLS 1.2+ with all non-broken ciphers) Highlights per component: 1. pinniped CLI - uses "secure" config against KAS - uses "default" for all other connections 2. concierge - uses "secure" config as an aggregated API server - uses "default" config as a impersonation proxy API server - uses "secure" config against KAS - uses "default" config for JWT authenticater (mostly, see code) - no changes to webhook authenticater (see code) 3. supervisor - uses "default" config as a server - uses "secure" config against KAS - uses "default" config against OIDC IDPs - uses "default LDAP" config against LDAP IDPs Signed-off-by: Monis Khan <mok@vmware.com>
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Copyright 2021 the Pinniped contributors. All Rights Reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package phttp
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"net/http"
|
|
"time"
|
|
|
|
"k8s.io/apimachinery/pkg/util/net"
|
|
"k8s.io/client-go/rest"
|
|
"k8s.io/client-go/transport"
|
|
|
|
"go.pinniped.dev/internal/crypto/ptls"
|
|
"go.pinniped.dev/internal/plog"
|
|
)
|
|
|
|
func Default(rootCAs *x509.CertPool) *http.Client {
|
|
return buildClient(ptls.Default, rootCAs)
|
|
}
|
|
|
|
func Secure(rootCAs *x509.CertPool) *http.Client {
|
|
return buildClient(ptls.Secure, rootCAs)
|
|
}
|
|
|
|
func buildClient(tlsConfigFunc ptls.ConfigFunc, rootCAs *x509.CertPool) *http.Client {
|
|
baseRT := defaultTransport()
|
|
baseRT.TLSClientConfig = tlsConfigFunc(rootCAs)
|
|
|
|
return &http.Client{
|
|
Transport: defaultWrap(baseRT),
|
|
Timeout: 3 * time.Hour, // make it impossible for requests to hang indefinitely
|
|
}
|
|
}
|
|
|
|
func defaultTransport() *http.Transport {
|
|
baseRT := http.DefaultTransport.(*http.Transport).Clone()
|
|
net.SetTransportDefaults(baseRT)
|
|
baseRT.MaxIdleConnsPerHost = 25 // copied from client-go
|
|
return baseRT
|
|
}
|
|
|
|
func defaultWrap(rt http.RoundTripper) http.RoundTripper {
|
|
rt = safeDebugWrappers(rt, transport.DebugWrappers, func() bool { return plog.Enabled(plog.LevelTrace) })
|
|
rt = transport.NewUserAgentRoundTripper(rest.DefaultKubernetesUserAgent(), rt)
|
|
return rt
|
|
}
|