Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

s3: fix presigned URLs for GCS, Linode and Ceph

Leon Brocard2ff2bfee8f2d
diff --git a/backend/s3/s3.go b/backend/s3/s3.go
index 26b7bf963..5e12ba6d2 100644
--- a/backend/s3/s3.go
+++ b/backend/s3/s3.go
@@ -1446,10 +1446,15 @@ func fixupRequest(o *s3.Options, opt *Options) {
)
o.APIOptions = append(o.APIOptions, func(stack *middleware.Stack) error {
- if err := stack.Finalize.Insert(fixup, "Signing", middleware.Before); err != nil {
+ // Presigning replaces the "Signing" middleware before APIOptions run
+ signing := "Signing"
+ if _, ok := stack.Finalize.Get(signing); !ok {
+ signing = "PresignHTTPRequest"
+ }
+ if err := stack.Finalize.Insert(fixup, signing, middleware.Before); err != nil {
return err
}
- if err := stack.Finalize.Insert(restore, "Signing", middleware.After); err != nil {
+ if err := stack.Finalize.Insert(restore, signing, middleware.After); err != nil {
return err
}
return nil
diff --git a/backend/s3/s3_link_test.go b/backend/s3/s3_link_test.go
index 7a8b01708..f7d5d420c 100644
--- a/backend/s3/s3_link_test.go
+++ b/backend/s3/s3_link_test.go
@@ -225,3 +225,31 @@ func TestPublicLink(t *testing.T) {
_, err = f.PublicLink(context.Background(), "missing", fs.DurationOff, false)
assert.ErrorIs(t, err, fs.ErrorObjectNotFound)
}
+
+func TestPublicLinkRequestFixups(t *testing.T) {
+ for _, tt := range []struct {
+ name string
+ useXID bool
+ signAcceptEncoding bool
+ }{
+ {"no x-id", false, true},
+ {"unsigned Accept-Encoding", true, false},
+ {"no x-id and unsigned Accept-Encoding", false, false},
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ f := newLinkTestFs(t)
+ f.opt.UseXID = fs.Tristate{Value: tt.useXID, Valid: true}
+ f.opt.SignAcceptEncoding = fs.Tristate{Value: tt.signAcceptEncoding, Valid: true}
+ c, _, err := s3Connection(f.ctx, &f.opt, getClient(f.ctx, &f.opt))
+ require.NoError(t, err)
+ f.c = c
+ link, err := f.PublicLink(context.Background(), "file", fs.Duration(time.Hour), false)
+ require.NoError(t, err)
+ u, err := url.Parse(link)
+ require.NoError(t, err)
+ assert.Equal(t, tt.useXID, u.Query().Has("x-id"))
+ assert.Equal(t, "host", u.Query().Get("X-Amz-SignedHeaders"))
+ assert.Equal(t, u.Query().Get("X-Amz-Signature"), linkSignature(t, u))
+ })
+ }
+}