From 79a091b12aab9c41085840eb7db28d9787dd2573 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 16 Dec 2018 16:24:17 -0800 Subject: [PATCH] Fix object storage not working properly with Google S3 compatibility Even in AWS S3 compatibility mode, Google now appears to reject requests that includes this header with this error: ``` Requests cannot specify both x-amz and x-goog headers ``` This has been submitted upstream via https://github.com/carrierwaveuploader/carrierwave/pull/2356. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/53846. --- Gemfile | 5 +++-- .../unreleased/sh-carrierwave-patch-google-acl.yml | 5 +++++ config/initializers/carrierwave_patch.rb | 13 +++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/sh-carrierwave-patch-google-acl.yml diff --git a/Gemfile b/Gemfile index 9ce23e693d3..61a9848a522 100644 --- a/Gemfile +++ b/Gemfile @@ -89,8 +89,9 @@ gem 'kaminari', '~> 1.0' gem 'hamlit', '~> 2.8.8' # Files attachments -# Locked until https://github.com/carrierwaveuploader/carrierwave/pull/2332/files is merged. -# config/initializers/carrierwave_patch.rb can be removed once that change is released. +# Locked until https://github.com/carrierwaveuploader/carrierwave/pull/2332 and +# https://github.com/carrierwaveuploader/carrierwave/pull/2356 are merged. +# config/initializers/carrierwave_patch.rb can be removed once both changes are released. gem 'carrierwave', '= 1.2.3' gem 'mini_magick' diff --git a/changelogs/unreleased/sh-carrierwave-patch-google-acl.yml b/changelogs/unreleased/sh-carrierwave-patch-google-acl.yml new file mode 100644 index 00000000000..206253a100c --- /dev/null +++ b/changelogs/unreleased/sh-carrierwave-patch-google-acl.yml @@ -0,0 +1,5 @@ +--- +title: Fix object storage not working properly with Google S3 compatibility +merge_request: 23858 +author: +type: fixed diff --git a/config/initializers/carrierwave_patch.rb b/config/initializers/carrierwave_patch.rb index 35ffff03abe..c361784491d 100644 --- a/config/initializers/carrierwave_patch.rb +++ b/config/initializers/carrierwave_patch.rb @@ -23,6 +23,19 @@ module CarrierWave end end end + + # Fix for https://github.com/carrierwaveuploader/carrierwave/pull/2356 + def acl_header + if fog_provider == 'AWS' + { 'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private' } + else + {} + end + end + + def fog_provider + @uploader.fog_credentials[:provider].to_s + end end end end