Merge branch v2.6 into v2.7
This commit is contained in:
commit
05f3e60366
20 changed files with 398 additions and 79 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync/atomic"
|
||||
|
@ -101,7 +102,7 @@ func (h *handler) handleDiscoverIP(rw http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
func (h *handler) doDiscoveryReq(ctx context.Context, ip, port, nonce string) error {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://%s:%s", ip, port), http.NoBody)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://%s", net.JoinHostPort(ip, port)), http.NoBody)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating request: %w", err)
|
||||
}
|
||||
|
|
|
@ -400,7 +400,7 @@ func getServicePort(svc *corev1.Service, port intstr.IntOrString) (*corev1.Servi
|
|||
|
||||
if hasValidPort {
|
||||
log.WithoutContext().
|
||||
Warning("The port %d from IngressRoute doesn't match with ports defined in the ExternalName service %s/%s.", port, svc.Namespace, svc.Name)
|
||||
Warnf("The port %s from IngressRoute doesn't match with ports defined in the ExternalName service %s/%s.", port, svc.Namespace, svc.Name)
|
||||
}
|
||||
|
||||
return &corev1.ServicePort{Port: port.IntVal}, nil
|
||||
|
|
|
@ -14,33 +14,31 @@ import (
|
|||
// Proxy forwards a TCP request to a TCP service.
|
||||
type Proxy struct {
|
||||
address string
|
||||
target *net.TCPAddr
|
||||
tcpAddr *net.TCPAddr
|
||||
terminationDelay time.Duration
|
||||
proxyProtocol *dynamic.ProxyProtocol
|
||||
refreshTarget bool
|
||||
}
|
||||
|
||||
// NewProxy creates a new Proxy.
|
||||
func NewProxy(address string, terminationDelay time.Duration, proxyProtocol *dynamic.ProxyProtocol) (*Proxy, error) {
|
||||
tcpAddr, err := net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if proxyProtocol != nil && (proxyProtocol.Version < 1 || proxyProtocol.Version > 2) {
|
||||
return nil, fmt.Errorf("unknown proxyProtocol version: %d", proxyProtocol.Version)
|
||||
}
|
||||
|
||||
// enable the refresh of the target only if the address in not an IP
|
||||
refreshTarget := false
|
||||
if host, _, err := net.SplitHostPort(address); err == nil && net.ParseIP(host) == nil {
|
||||
refreshTarget = true
|
||||
// Creates the tcpAddr only for IP based addresses,
|
||||
// because there is no need to resolve the name on every new connection,
|
||||
// and building it should happen once.
|
||||
var tcpAddr *net.TCPAddr
|
||||
if host, _, err := net.SplitHostPort(address); err == nil && net.ParseIP(host) != nil {
|
||||
tcpAddr, err = net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &Proxy{
|
||||
address: address,
|
||||
target: tcpAddr,
|
||||
refreshTarget: refreshTarget,
|
||||
tcpAddr: tcpAddr,
|
||||
terminationDelay: terminationDelay,
|
||||
proxyProtocol: proxyProtocol,
|
||||
}, nil
|
||||
|
@ -83,10 +81,14 @@ func (p *Proxy) ServeTCP(conn WriteCloser) {
|
|||
}
|
||||
|
||||
func (p Proxy) dialBackend() (*net.TCPConn, error) {
|
||||
if !p.refreshTarget {
|
||||
return net.DialTCP("tcp", nil, p.target)
|
||||
// Dial using directly the TCPAddr for IP based addresses.
|
||||
if p.tcpAddr != nil {
|
||||
return net.DialTCP("tcp", nil, p.tcpAddr)
|
||||
}
|
||||
|
||||
log.WithoutContext().Debugf("Dial with lookup to address %s", p.address)
|
||||
|
||||
// Dial with DNS lookup for host based addresses.
|
||||
conn, err := net.Dial("tcp", p.address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -176,16 +176,20 @@ func TestLookupAddress(t *testing.T) {
|
|||
testCases := []struct {
|
||||
desc string
|
||||
address string
|
||||
expectRefresh bool
|
||||
expectAddr assert.ComparisonAssertionFunc
|
||||
expectRefresh assert.ValueAssertionFunc
|
||||
}{
|
||||
{
|
||||
desc: "IP doesn't need refresh",
|
||||
address: "8.8.4.4:53",
|
||||
desc: "IP doesn't need refresh",
|
||||
address: "8.8.4.4:53",
|
||||
expectAddr: assert.Equal,
|
||||
expectRefresh: assert.NotNil,
|
||||
},
|
||||
{
|
||||
desc: "Hostname needs refresh",
|
||||
address: "dns.google:53",
|
||||
expectRefresh: true,
|
||||
expectAddr: assert.NotEqual,
|
||||
expectRefresh: assert.Nil,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -197,16 +201,12 @@ func TestLookupAddress(t *testing.T) {
|
|||
proxy, err := NewProxy(test.address, 10*time.Millisecond, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotNil(t, proxy.target)
|
||||
test.expectRefresh(t, proxy.tcpAddr)
|
||||
|
||||
conn, err := proxy.dialBackend()
|
||||
require.NoError(t, err)
|
||||
|
||||
if test.expectRefresh {
|
||||
assert.NotEqual(t, test.address, conn.RemoteAddr().String())
|
||||
} else {
|
||||
assert.Equal(t, test.address, conn.RemoteAddr().String())
|
||||
}
|
||||
test.expectAddr(t, test.address, conn.RemoteAddr().String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,6 +171,13 @@ func (m *Manager) Get(storeName, configName string) (*tls.Config, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
if store == nil {
|
||||
log.WithoutContext().Errorf("TLS: No certificate store found with this name: %q, closing connection", storeName)
|
||||
|
||||
// Same comment as above, as in the isACMETLS case.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
log.WithoutContext().Debugf("Serving default certificate for request: %q", domainToCheck)
|
||||
return store.DefaultCertificate, nil
|
||||
}
|
||||
|
|
|
@ -171,6 +171,36 @@ func TestManager_Get(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestManager_Get_GetCertificate(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
expectedGetConfigErr require.ErrorAssertionFunc
|
||||
expectedCertificate assert.ValueAssertionFunc
|
||||
}{
|
||||
{
|
||||
desc: "Get a default certificate from non-existing store",
|
||||
expectedGetConfigErr: require.Error,
|
||||
expectedCertificate: assert.Nil,
|
||||
},
|
||||
}
|
||||
|
||||
tlsManager := NewManager()
|
||||
|
||||
for _, test := range testCases {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
config, err := tlsManager.Get("default", "foo")
|
||||
test.expectedGetConfigErr(t, err)
|
||||
|
||||
certificate, err := config.GetCertificate(&tls.ClientHelloInfo{})
|
||||
require.NoError(t, err)
|
||||
test.expectedCertificate(t, certificate)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientAuth(t *testing.T) {
|
||||
tlsConfigs := map[string]Options{
|
||||
"eca": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue