s3: fix presigned URLs for GCS, Linode and Ceph
Presigning failed with "not found: FixupRequest" for providers with use_x_id or sign_accept_encoding set to false, breaking rclone link, the link backend command and use_presigned_request uploads. Presigning replaces the Signing middleware with PresignHTTPRequest before APIOptions run, so anchor the request fixups on whichever is present.
This commit is contained in:
1 parent
2fb0f2c58c
commit
2ff2bfee8f
2 files changed
+35
-2
No files matched your search
+7
-2
@@ -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
|
||||
|
||||
@@ -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))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user