Skip to content

download 403 when dfget get object from s3 and range header is empty #4436

@pirDOL

Description

@pirDOL

Bug report:

download success: false, cost: 41 ms error: SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your Secret Access Key and signing method. Consult the service documentation for details.

Expected behavior:

Set range header when it is not empty. I have fixed the problem as follows:

diff --git a/pkg/source/clients/s3protocol/s3_source_client.go b/pkg/source/clients/s3protocol/s3_source_client.go
index 5dea03ed..acb2e1e7 100644
--- a/pkg/source/clients/s3protocol/s3_source_client.go
+++ b/pkg/source/clients/s3protocol/s3_source_client.go
@@ -132,14 +132,15 @@ func (s *s3SourceClient) Download(request *source.Request) (*source.Response, er
                return nil, err
        }
 
-       resp, err := client.GetObjectWithContext(request.Context(),
-               &s3.GetObjectInput{
-                       Bucket: aws.String(request.URL.Host),
-                       Key:    aws.String(request.URL.Path),
-                       // TODO more header pass to GetObjectInput
-                       Range: aws.String(request.Header.Get(headers.Range)),
-               })
-
+       req := &s3.GetObjectInput{
+               Bucket: aws.String(request.URL.Host),
+               Key:    aws.String(request.URL.Path),
+       }
+       if rangeHeader := request.Header.Get(headers.Range); rangeHeader != "" {
+               req.Range = aws.String(rangeHeader)
+       }
+       // TODO more header pass to GetObjectInput
+       resp, err := client.GetObjectWithContext(request.Context(), req)

How to reproduce it:

Environment:

  • Dragonfly version: main
  • OS: centos4u3
  • Kernel (e.g. uname -a): 4.14
  • Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions