Skip to content

Commit d92e24d

Browse files
authored
Merge pull request #5 from PowerDNS/use-tlsconfig-for-s3
s3: add TLS configuration options
2 parents 774ca99 + 4d8a573 commit d92e24d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

backends/s3/s3.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212
"time"
1313

14+
"github.com/PowerDNS/go-tlsconfig"
1415
"github.com/aws/aws-sdk-go-v2/aws"
1516
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
1617
s3config "github.com/aws/aws-sdk-go-v2/config"
@@ -51,6 +52,10 @@ type Options struct {
5152
// instead of AWS S3.
5253
EndpointURL string `yaml:"endpoint_url"`
5354

55+
// TLS allows customising the TLS configuration
56+
// See https://github.com/PowerDNS/go-tlsconfig for the available options
57+
TLS tlsconfig.Config `yaml:"tls"`
58+
5459
// InitTimeout is the time we allow for initialisation, like credential
5560
// checking and bucket creation. It defaults to DefaultInitTimeout, which
5661
// is currently 20s.
@@ -241,15 +246,39 @@ func New(ctx context.Context, opt Options) (*Backend, error) {
241246
return nil, err
242247
}
243248

244-
// Some of the following calls require a context
249+
// Automatic TLS handling
250+
// This MUST receive a longer running context to be able to automatically
251+
// reload certificates, so we use the original ctx, not one with added
252+
// InitTimeout.
253+
tlsmgr, err := tlsconfig.NewManager(ctx, opt.TLS, tlsconfig.Options{
254+
IsClient: true,
255+
// TODO: logging might be useful here, but we need to figure this
256+
// out for other parts of simpleblob first.
257+
Logr: nil,
258+
})
259+
if err != nil {
260+
return nil, err
261+
}
262+
// Get an opinionated HTTP client that:
263+
// - Uses a custom tls.Config
264+
// - Sets proxies from the environment
265+
// - Sets reasonable timeouts on various operations
266+
// Check the implementation for details.
267+
hc, err := tlsmgr.HTTPClient()
268+
if err != nil {
269+
return nil, err
270+
}
271+
272+
// Some of the following calls require a short running context
245273
ctx, cancel := context.WithTimeout(ctx, opt.InitTimeout)
246274
defer cancel()
247275

248276
creds := credentials.NewStaticCredentialsProvider(opt.AccessKey, opt.SecretKey, "")
249277
cfg, err := s3config.LoadDefaultConfig(
250278
ctx,
251279
s3config.WithCredentialsProvider(creds),
252-
s3config.WithRegion(opt.Region))
280+
s3config.WithRegion(opt.Region),
281+
s3config.WithHTTPClient(hc))
253282
if err != nil {
254283
return nil, err
255284
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
)
1515

1616
require (
17+
github.com/PowerDNS/go-tlsconfig v0.0.0-20201014142732-fe6ff56e2a95 // indirect
1718
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.2.0 // indirect
1819
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.10.0 // indirect
1920
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.4 // indirect
@@ -28,6 +29,7 @@ require (
2829
github.com/beorn7/perks v1.0.1 // indirect
2930
github.com/cespare/xxhash/v2 v2.1.2 // indirect
3031
github.com/davecgh/go-spew v1.1.1 // indirect
32+
github.com/go-logr/logr v0.2.1 // indirect
3133
github.com/golang/protobuf v1.5.2 // indirect
3234
github.com/jmespath/go-jmespath v0.4.0 // indirect
3335
github.com/kr/text v0.2.0 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3333
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3434
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3535
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
36+
github.com/PowerDNS/go-tlsconfig v0.0.0-20201014142732-fe6ff56e2a95 h1:jWxEVXkF1InUh1o5aCq4cc+ZjKKSwYsGV3yNK5Rpp6A=
37+
github.com/PowerDNS/go-tlsconfig v0.0.0-20201014142732-fe6ff56e2a95/go.mod h1:Q+i/He4WS46khYyqBUWBASsayUrenws7sOh964AK7TY=
3638
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3739
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3840
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -100,6 +102,8 @@ github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vb
100102
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
101103
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
102104
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
105+
github.com/go-logr/logr v0.2.1 h1:fV3MLmabKIZ383XifUjFSwcoGee0v9qgPp8wy5svibE=
106+
github.com/go-logr/logr v0.2.1/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
103107
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
104108
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
105109
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=

0 commit comments

Comments
 (0)