Skip to content

Commit f600212

Browse files
authored
Apply cluster TLS profile to outgoing HTTP client (#2767)
Use the configured TLS profile (set via --tls-profile flags) for the catalogd HTTP client, consistent with how the metrics server TLS is configured. Falls back to TLS 1.2 minimum when no profile is set. Signed-off-by: Todd Short <tshort@redhat.com>
1 parent af1dffb commit f600212

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

internal/shared/util/http/httputil.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package http
22

33
import (
44
"crypto/tls"
5+
"fmt"
56
"net/http"
67
"time"
8+
9+
"github.com/operator-framework/operator-controller/internal/shared/util/tlsprofiles"
710
)
811

912
func BuildHTTPClient(cpw *CertPoolWatcher) (*http.Client, error) {
@@ -18,6 +21,11 @@ func BuildHTTPClient(cpw *CertPoolWatcher) (*http.Client, error) {
1821
RootCAs: pool,
1922
MinVersion: tls.VersionTLS12,
2023
}
24+
tlsProfile, err := tlsprofiles.GetTLSConfigFunc()
25+
if err != nil {
26+
return nil, fmt.Errorf("getting TLS config func: %w", err)
27+
}
28+
tlsProfile(tlsConfig)
2129
httpClient.Transport = &http.Transport{
2230
TLSClientConfig: tlsConfig,
2331
// Proxy must be set explicitly; a nil Proxy field means "no proxy" and

internal/shared/util/http/httputil_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package http_test
22

33
import (
44
"context"
5+
"crypto/tls"
56
"encoding/pem"
67
"io"
78
"net"
@@ -14,10 +15,12 @@ import (
1415
"testing"
1516
"time"
1617

18+
"github.com/spf13/pflag"
1719
"github.com/stretchr/testify/require"
1820
"sigs.k8s.io/controller-runtime/pkg/log"
1921

2022
httputil "github.com/operator-framework/operator-controller/internal/shared/util/http"
23+
"github.com/operator-framework/operator-controller/internal/shared/util/tlsprofiles"
2124
)
2225

2326
// startRecordingProxy starts a plain-HTTP CONNECT proxy that tunnels HTTPS
@@ -169,6 +172,34 @@ func TestBuildHTTPClientProxyTunnelsConnections(t *testing.T) {
169172
}
170173
}
171174

175+
// TestBuildHTTPClientAppliesTLSProfile verifies that BuildHTTPClient applies
176+
// the configured TLS profile to the transport's TLSClientConfig. When the
177+
// "modern" profile is active the minimum TLS version must be 1.3.
178+
func TestBuildHTTPClientAppliesTLSProfile(t *testing.T) {
179+
// Switch to the "modern" profile for this test and restore afterward.
180+
fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
181+
tlsprofiles.AddFlags(fs)
182+
require.NoError(t, fs.Parse([]string{"--tls-profile=modern"}))
183+
t.Cleanup(func() {
184+
resetFS := pflag.NewFlagSet("reset", pflag.ContinueOnError)
185+
tlsprofiles.AddFlags(resetFS)
186+
require.NoError(t, resetFS.Parse([]string{"--tls-profile=intermediate"}))
187+
})
188+
189+
cpw, err := httputil.NewCertPoolWatcher("", log.FromContext(context.Background()))
190+
require.NoError(t, err)
191+
t.Cleanup(cpw.Done)
192+
require.NoError(t, cpw.Start(context.Background()))
193+
194+
client, err := httputil.BuildHTTPClient(cpw)
195+
require.NoError(t, err)
196+
197+
transport, ok := client.Transport.(*http.Transport)
198+
require.True(t, ok)
199+
require.Equal(t, uint16(tls.VersionTLS13), transport.TLSClientConfig.MinVersion,
200+
"modern TLS profile must set MinVersion to TLS 1.3")
201+
}
202+
172203
// TestBuildHTTPClientProxyBlocksWhenRejected verifies that when the proxy
173204
// rejects the CONNECT tunnel, the client request fails rather than silently
174205
// falling back to a direct connection.

0 commit comments

Comments
 (0)