Repository: sa7mon/S3Scanner (language: python)

Issue:
use HTTP_PROXY if set
Will be useful for debugging purposes and probably helpful for networks that don't allow direct connections out


Discussion / hints:

Fix patch:
diff --git a/provider/aws.go b/provider/aws.go
index dcd153f..ed65c72 100644
--- a/provider/aws.go
+++ b/provider/aws.go
@@ -10,6 +10,7 @@ import (
 	"github.com/aws/aws-sdk-go-v2/service/s3"
 	"github.com/sa7mon/s3scanner/bucket"
 	log "github.com/sirupsen/logrus"
+	"net/http"
 )
 
 type providerAWS struct {
@@ -106,6 +107,9 @@ func (*providerAWS) newAnonClientNoRegion() (*s3.Client, error) {
 		context.TODO(),
 		config.WithDefaultRegion("us-west-2"),
 		config.WithCredentialsProvider(aws.AnonymousCredentials{}),
+		config.WithHTTPClient(&http.Client{Transport: &http.Transport{
+			Proxy: http.ProxyFromEnvironment,
+		}}),
 	)
 	if err != nil {
 		return nil, err
@@ -123,7 +127,10 @@ func (a *providerAWS) newClient(region string) (*s3.Client, error) {
 	cfg, err := config.LoadDefaultConfig(
 		context.TODO(),
 		config.WithRegion(region),
-		config.WithCredentialsProvider(aws.AnonymousCredentials{}))
+		config.WithCredentialsProvider(aws.AnonymousCredentials{}),
+		config.WithHTTPClient(&http.Client{Transport: &http.Transport{
+			Proxy: http.ProxyFromEnvironment,
+		}}))
 
 	if err != nil {
 		return nil, err
diff --git a/provider/providers.go b/provider/providers.go
index 01f385d..2ed976e 100644
--- a/provider/providers.go
+++ b/provider/providers.go
@@ -64,6 +64,19 @@ func NewProvider(name string) (StorageProvider, error) {
 }
 
 func newNonAWSClient(sp StorageProvider, regionURL string) (*s3.Client, error) {
+	var httpClient s3.HTTPClient
+
+	if sp.Insecure() {
+		httpClient = &http.Client{Transport: &http.Transport{
+			Proxy:           http.ProxyFromEnvironment,
+			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+		}}
+	} else {
+		httpClient = &http.Client{Transport: &http.Transport{
+			Proxy: http.ProxyFromEnvironment,
+		}}
+	}
+
 	cfg, err := config.LoadDefaultConfig(
 		context.TODO(),
 		config.WithEndpointResolverWithOptions(
@@ -73,17 +86,12 @@ func newNonAWSClient(sp StorageProvider, regionURL string) (*s3.Client, error) {
 				}, nil
 			})),
 		config.WithCredentialsProvider(aws.AnonymousCredentials{}),
+		config.WithHTTPClient(httpClient),
 	)
 	if err != nil {
 		return nil, err
 	}
 
-	if sp.Insecure() {
-		cfg.HTTPClient = &http.Client{Transport: &http.Transport{
-			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
-		}}
-	}
-
 	addrStyleOption := func(o *s3.Options) { o.UsePathStyle = false }
 	if sp.AddressStyle() == PathStyle {
 		addrStyleOption = func(o *s3.Options) { o.UsePathStyle = true }


Test patch:
diff --git a/.github/workflows/pr_test-coverage.yml b/.github/workflows/pr_test-coverage.yml
index af5d444..8ee7e60 100644
--- a/.github/workflows/pr_test-coverage.yml
+++ b/.github/workflows/pr_test-coverage.yml
@@ -36,6 +36,7 @@ jobs:
           go-version: '1.19'
       - name: Test
         run: TEST_DB=1 TEST_MQ=1 go test ./... -coverprofile=cover.out
+        timeout-minutes: 5
       - name: Install dependencies
         run: go install github.com/axw/gocov/gocov@v1.1.0 && go install github.com/AlekSi/gocov-xml@v1.1.0
       - run: gocov convert cover.out | gocov-xml > coverage.xml
diff --git a/.github/workflows/pr_test-matrix.yml b/.github/workflows/pr_test-matrix.yml
index d549def..3196161 100644
--- a/.github/workflows/pr_test-matrix.yml
+++ b/.github/workflows/pr_test-matrix.yml
@@ -36,6 +36,7 @@ jobs:
           go-version: ${{ matrix.go }}
       - name: Test
         run: TEST_DB=1 TEST_MQ=1 go test ./...
+        timeout-minutes: 5
       - name: Build
         run: go build -v ./...
   windows-matrix: