@@ -3,6 +3,8 @@ package s3
3
3
import (
4
4
"bytes"
5
5
"context"
6
+ "crypto/tls"
7
+ "crypto/x509"
6
8
"fmt"
7
9
"io/ioutil"
8
10
"net"
@@ -11,7 +13,6 @@ import (
11
13
"os"
12
14
"path/filepath"
13
15
"reflect"
14
- "strings"
15
16
"time"
16
17
17
18
"github.com/aws/aws-sdk-go/aws"
@@ -22,6 +23,7 @@ import (
22
23
"github.com/aws/aws-sdk-go/service/s3"
23
24
"github.com/aws/aws-sdk-go/service/s3/s3manager"
24
25
"golang.org/x/net/http/httpproxy"
26
+ "golang.org/x/net/http2"
25
27
26
28
corev1 "k8s.io/api/core/v1"
27
29
"k8s.io/apimachinery/pkg/api/errors"
@@ -236,27 +238,48 @@ func (d *driver) getS3Service() (*s3.S3, error) {
236
238
return nil , err
237
239
}
238
240
241
+ rootCAs , err := x509 .SystemCertPool ()
242
+ if err != nil {
243
+ return nil , fmt .Errorf ("unable to load system root CA bundle: %w" , err )
244
+ }
245
+
246
+ userCABundle , err := d .getCABundle ()
247
+ if err != nil {
248
+ return nil , err
249
+ }
250
+ rootCAs .AppendCertsFromPEM ([]byte (userCABundle ))
251
+
252
+ tr := & http.Transport {
253
+ Proxy : func (req * http.Request ) (* url.URL , error ) {
254
+ return httpproxy .FromEnvironment ().ProxyFunc ()(req .URL )
255
+ },
256
+ DialContext : (& net.Dialer {
257
+ Timeout : 30 * time .Second ,
258
+ KeepAlive : 30 * time .Second ,
259
+ DualStack : true ,
260
+ }).DialContext ,
261
+ TLSClientConfig : & tls.Config {
262
+ RootCAs : rootCAs ,
263
+ },
264
+ MaxIdleConns : 100 ,
265
+ IdleConnTimeout : 90 * time .Second ,
266
+ TLSHandshakeTimeout : 10 * time .Second ,
267
+ ExpectContinueTimeout : 1 * time .Second ,
268
+ ForceAttemptHTTP2 : true ,
269
+ }
270
+
271
+ err = http2 .ConfigureTransport (tr )
272
+ if err != nil {
273
+ return nil , fmt .Errorf ("unable to configure http2 transport: %w" , err )
274
+ }
275
+
239
276
// A custom HTTPClient is used here since the default HTTPClients ProxyFromEnvironment
240
277
// uses a cache which won't let us update the proxy env vars
241
278
awsOptions := session.Options {
242
279
Config : aws.Config {
243
280
Region : & d .Config .Region ,
244
281
HTTPClient : & http.Client {
245
- Transport : & http.Transport {
246
- Proxy : func (req * http.Request ) (* url.URL , error ) {
247
- return httpproxy .FromEnvironment ().ProxyFunc ()(req .URL )
248
- },
249
- DialContext : (& net.Dialer {
250
- Timeout : 30 * time .Second ,
251
- KeepAlive : 30 * time .Second ,
252
- DualStack : true ,
253
- }).DialContext ,
254
- ForceAttemptHTTP2 : true ,
255
- MaxIdleConns : 100 ,
256
- IdleConnTimeout : 90 * time .Second ,
257
- TLSHandshakeTimeout : 10 * time .Second ,
258
- ExpectContinueTimeout : 1 * time .Second ,
259
- },
282
+ Transport : tr ,
260
283
},
261
284
},
262
285
SharedConfigState : session .SharedConfigEnable ,
@@ -276,13 +299,6 @@ func (d *driver) getS3Service() (*s3.S3, error) {
276
299
277
300
awsOptions .Config .WithEndpointResolver (d .endpointsResolver )
278
301
279
- switch caBundle , err := d .getCABundle (); {
280
- case err != nil :
281
- return nil , err
282
- case caBundle != "" :
283
- awsOptions .CustomCABundle = strings .NewReader (caBundle )
284
- }
285
-
286
302
sess , err := session .NewSessionWithOptions (awsOptions )
287
303
if err != nil {
288
304
return nil , err
0 commit comments