Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ea81fe

Browse files
milosgajdosopenshift-cherrypick-robot
authored and
openshift-cherrypick-robot
committedJan 15, 2025·
UPSTREAM distribution/distribution: 4190 fix: use http.DefaultTransport in S3 client
Signed-off-by: Michal Pryc <[email protected]>
1 parent 9b9c54d commit 9ea81fe

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed
 

‎registry/storage/driver/s3-aws/s3.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ func New(params DriverParameters) (*Driver, error) {
557557
awsConfig.WithUseDualStack(params.UseDualStack)
558558

559559
if params.SkipVerify {
560-
httpTransport := &http.Transport{
561-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
562-
}
560+
httpTransport := http.DefaultTransport.(*http.Transport).Clone()
561+
httpTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
563562
awsConfig.WithHTTPClient(&http.Client{
564563
Transport: httpTransport,
565564
})

‎registry/storage/driver/s3-aws/s3_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"math/rand"
8+
"net/http"
89
"os"
910
"path"
1011
"reflect"
@@ -254,6 +255,59 @@ func TestWalkEmptySubDirectory(t *testing.T) {
254255
}
255256
}
256257

258+
func TestClientTransport(t *testing.T) {
259+
if skipS3() != "" {
260+
t.Skip(skipS3())
261+
}
262+
263+
testCases := []struct {
264+
skipverify bool
265+
}{
266+
{true},
267+
{false},
268+
}
269+
270+
for _, tc := range testCases {
271+
// NOTE(milosgajdos): we cannot simply reuse s3DriverConstructor
272+
// because s3DriverConstructor is initialized in init() using the process
273+
// env vars: we can not override S3_SKIP_VERIFY env var with t.Setenv
274+
params := map[string]interface{}{
275+
"region": os.Getenv("AWS_REGION"),
276+
"bucket": os.Getenv("S3_BUCKET"),
277+
"skipverify": tc.skipverify,
278+
}
279+
t.Run(fmt.Sprintf("SkipVerify %v", tc.skipverify), func(t *testing.T) {
280+
drv, err := FromParameters(context.TODO(), params)
281+
if err != nil {
282+
t.Fatalf("failed to create driver: %v", err)
283+
}
284+
285+
s3drv := drv.baseEmbed.Base.StorageDriver.(*driver)
286+
if tc.skipverify {
287+
tr, ok := s3drv.S3.Client.Config.HTTPClient.Transport.(*http.Transport)
288+
if !ok {
289+
t.Fatal("unexpected driver transport")
290+
}
291+
if !tr.TLSClientConfig.InsecureSkipVerify {
292+
t.Errorf("unexpected TLS Config. Expected InsecureSkipVerify: %v, got %v",
293+
tc.skipverify,
294+
tr.TLSClientConfig.InsecureSkipVerify)
295+
}
296+
// make sure the proxy is always set
297+
if tr.Proxy == nil {
298+
t.Fatal("missing HTTP transport proxy config")
299+
}
300+
return
301+
}
302+
// if tc.skipverify is false we do not override the driver
303+
// HTTP clien transport and leave it to the AWS SDK.
304+
if s3drv.S3.Client.Config.HTTPClient.Transport != nil {
305+
t.Errorf("unexpected S3 driver client transport")
306+
}
307+
})
308+
}
309+
}
310+
257311
func TestStorageClass(t *testing.T) {
258312
if skipS3() != "" {
259313
t.Skip(skipS3())

0 commit comments

Comments
 (0)
Please sign in to comment.