Skip to content

Commit cda7eea

Browse files
committed
Fix pollution of http.Transport TLSConfigs for OCI tests
Natation signing was previously relying on the TLSConfig being added to the http.DefaultTransport as a side-effect Messing with the http.DefaultTransport was causing TLS verification failures for internet requests to the TUF repo. Signed-off-by: leigh capili <leigh@null.net>
1 parent a5f9a84 commit cda7eea

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

internal/controller/ocirepository_controller_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ func TestOCIRepository_CertSecret(t *testing.T) {
861861
clientTLSCert, err := tls.X509KeyPair(clientPublicKey, clientPrivateKey)
862862
g.Expect(err).ToNot(HaveOccurred())
863863

864-
transport := http.DefaultTransport.(*http.Transport)
864+
transport := http.DefaultTransport.(*http.Transport).Clone()
865865
transport.TLSClientConfig = &tls.Config{
866866
RootCAs: pool,
867867
Certificates: []tls.Certificate{clientTLSCert},
@@ -1591,6 +1591,19 @@ func TestOCIRepository_reconcileSource_verifyOCISourceSignatureNotation(t *testi
15911591
remoteRepo.PlainHTTP = true
15921592
}
15931593

1594+
// Configure transport to trust the local registry CA
1595+
transport := http.DefaultTransport.(*http.Transport).Clone()
1596+
if !tt.insecure {
1597+
pool := x509.NewCertPool()
1598+
pool.AppendCertsFromPEM(tlsCA)
1599+
transport.TLSClientConfig = &tls.Config{
1600+
RootCAs: pool,
1601+
}
1602+
}
1603+
remoteRepo.Client = &http.Client{
1604+
Transport: transport,
1605+
}
1606+
15941607
repo := registry.NewRepository(remoteRepo)
15951608

15961609
signatureMediaType := cose.MediaTypeEnvelope
@@ -3550,7 +3563,7 @@ func pushMultiplePodinfoImages(serverURL string, insecure bool, versions ...stri
35503563
if insecure {
35513564
opts = append(opts, crane.Insecure)
35523565
} else {
3553-
transport := http.DefaultTransport.(*http.Transport)
3566+
transport := http.DefaultTransport.(*http.Transport).Clone()
35543567
pool := x509.NewCertPool()
35553568
pool.AppendCertsFromPEM(tlsCA)
35563569
transport.TLSClientConfig = &tls.Config{

0 commit comments

Comments
 (0)