Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws/session: Use HTTP_PROXY environment variable when AWS_CA_BUNDLE is specified #2343

Merged
merged 3 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions aws/session/cabundle_transport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// +build go1.7

package session

import (
"net"
"net/http"
"time"
)

// Transport that should be used when a custom CA bundle is specified with the
// SDK.
func getCABundleTransport() *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}
22 changes: 22 additions & 0 deletions aws/session/cabundle_transport_1_5.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// +build !go1.6,go1.5

package session

import (
"net"
"net/http"
"time"
)

// Transport that should be used when a custom CA bundle is specified with the
// SDK.
func getCABundleTransport() *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
}
}
23 changes: 23 additions & 0 deletions aws/session/cabundle_transport_1_6.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build !go1.7,go1.6

package session

import (
"net"
"net/http"
"time"
)

// Transport that should be used when a custom CA bundle is specified with the
// SDK.
func getCABundleTransport() *http.Transport {
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
}
30 changes: 30 additions & 0 deletions aws/session/custom_ca_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,36 @@ func TestNewSession_WithCustomCABundle_Option(t *testing.T) {
}
}

func TestNewSession_WithCustomCABundle_HTTPProxyAvailable(t *testing.T) {
skipTravisTest(t)

oldEnv := initSessionTestEnv()
defer awstesting.PopEnv(oldEnv)

s, err := NewSessionWithOptions(Options{
Config: aws.Config{
HTTPClient: &http.Client{},
Region: aws.String("mock-region"),
Credentials: credentials.AnonymousCredentials,
},
CustomCABundle: bytes.NewReader(awstesting.TLSBundleCA),
})
if err != nil {
t.Fatalf("expect no error, got %v", err)
}
if s == nil {
t.Fatalf("expect session to be created, got none")
}

tr := s.Config.HTTPClient.Transport.(*http.Transport)
if tr.Proxy == nil {
t.Fatalf("expect transport proxy, was nil")
}
if tr.TLSClientConfig.RootCAs == nil {
t.Fatalf("expect TLS config to have root CAs")
}
}

func TestNewSession_WithCustomCABundle_OptionPriority(t *testing.T) {
skipTravisTest(t)

Expand Down
5 changes: 4 additions & 1 deletion aws/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ func loadCustomCABundle(s *Session, bundle io.Reader) error {
}
}
if t == nil {
t = &http.Transport{}
// Nil transport implies `http.DefaultTransport` should be used. Since
// the SDK cannot modify, nor copy the `DefaultTransport` specifying
// the values the next closest behavior.
t = getCABundleTransport()
}

p, err := loadCertPool(bundle)
Expand Down