From 2ff2bfee8f2d20de856bfb0a78ada335000fa0e0 Mon Sep 17 00:00:00 2001 From: Leon Brocard Date: Mon, 5 Oct 2026 10:25:55 +0100 Subject: [PATCH] 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. --- backend/s3/s3.go | 9 +++++++-- backend/s3/s3_link_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) 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)) + }) + } +}