Skip to content

Commit fa6f1bf

Browse files
authored
fix(aws): use BuildableClient insead of xhttp.Client (aquasecurity#9436)
1 parent e7c16a7 commit fa6f1bf

File tree

1 file changed

+11
-3
lines changed
  • pkg/fanal/image/registry/ecr

1 file changed

+11
-3
lines changed

pkg/fanal/image/registry/ecr/ecr.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package ecr
33
import (
44
"context"
55
"encoding/base64"
6+
"net/http"
67
"regexp"
78
"strings"
89

910
"github.com/aws/aws-sdk-go-v2/aws"
11+
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
1012
"github.com/aws/aws-sdk-go-v2/config"
1113
"github.com/aws/aws-sdk-go-v2/credentials"
1214
"github.com/aws/aws-sdk-go-v2/service/ecr"
@@ -15,7 +17,6 @@ import (
1517
"github.com/aquasecurity/trivy/pkg/fanal/image/registry/intf"
1618
"github.com/aquasecurity/trivy/pkg/fanal/types"
1719
"github.com/aquasecurity/trivy/pkg/log"
18-
xhttp "github.com/aquasecurity/trivy/pkg/x/http"
1920
)
2021

2122
type ecrAPI interface {
@@ -30,6 +31,13 @@ type ECRClient struct {
3031
}
3132

3233
func getSession(domain, region string, option types.RegistryOptions) (aws.Config, error) {
34+
// Use BuildableClient to configure a custom Transport.
35+
// See: https://docs.aws.amazon.com/sdk-for-go/v2/developer-guide/configure-http.html
36+
// This is required because the xhttp.Client can cause issues when accessing IMDS.
37+
// cf. https://github.com/aquasecurity/trivy/discussions/9429
38+
client := awshttp.NewBuildableClient().WithTransportOptions(func(transport *http.Transport) {
39+
transport.TLSClientConfig.InsecureSkipVerify = option.Insecure
40+
})
3341
// create custom credential information if option is valid
3442
if option.AWSSecretKey != "" && option.AWSAccessKey != "" && option.AWSRegion != "" {
3543
if region != option.AWSRegion {
@@ -38,14 +46,14 @@ func getSession(domain, region string, option types.RegistryOptions) (aws.Config
3846
return config.LoadDefaultConfig(
3947
context.TODO(),
4048
config.WithRegion(region),
41-
config.WithHTTPClient(xhttp.Client()),
49+
config.WithHTTPClient(client),
4250
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(option.AWSAccessKey, option.AWSSecretKey, option.AWSSessionToken)),
4351
)
4452
}
4553
return config.LoadDefaultConfig(
4654
context.TODO(),
4755
config.WithRegion(region),
48-
config.WithHTTPClient(xhttp.Client()),
56+
config.WithHTTPClient(client),
4957
)
5058
}
5159

0 commit comments

Comments
 (0)