From d576a3fa575c137881afba76fb8fb4bdde8189b3 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 5 Feb 2019 17:50:27 +0100 Subject: [PATCH] FIX: S3 endpoint broke bucket creation in non-default region --- app/models/site_setting.rb | 2 +- config/locales/server.en.yml | 4 ++-- config/site_settings.yml | 2 +- lib/s3_helper.rb | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 0bdf7b3000e..49b9281c3db 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -152,7 +152,7 @@ class SiteSetting < ActiveRecord::Base bucket = SiteSetting.enable_s3_uploads ? Discourse.store.s3_bucket_name : GlobalSetting.s3_bucket_name # cf. http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region - if SiteSetting.s3_endpoint == "https://s3.amazonaws.com" + if SiteSetting.s3_endpoint.blank? || SiteSetting.s3_endpoint.end_with?("amazonaws.com") if SiteSetting.Upload.s3_region.start_with?("cn-") "//#{bucket}.s3.#{SiteSetting.Upload.s3_region}.amazonaws.com.cn" else diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index ddea713c1c6..dba39bc9ded 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1484,7 +1484,7 @@ en: automatic_backups_enabled: "Run automatic backups as defined in backup frequency" backup_frequency: "The number of days between backups." s3_backup_bucket: "The remote bucket to hold backups. WARNING: Make sure it is a private bucket." - s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Use default if using AWS S3" + s3_endpoint: "The endpoint can be modified to backup to an S3 compatible service like DigitalOcean Spaces or Minio. WARNING: Leave blank if using AWS S3." s3_force_path_style: "Enforce path-style addressing for your custom endpoint. IMPORTANT: Required for using Minio uploads and backups." s3_configure_tombstone_policy: "Enable automatic deletion policy for tombstone uploads. IMPORTANT: If disabled, no space will be reclaimed after uploads are deleted." s3_disable_cleanup: "Disable the removal of backups from S3 when removed locally." @@ -1540,7 +1540,7 @@ en: s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase, no periods, no underscores." s3_access_key_id: "The Amazon S3 access key id that will be used to upload images." s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images." - s3_region: "The Amazon S3 region name that will be used to upload images." + s3_region: "The Amazon S3 region name that will be used to upload images and backups." s3_cdn_url: "The CDN URL to use for all s3 assets (for example: https://cdn.somewhere.com). WARNING: after changing this setting you must rebake all old posts." avatar_sizes: "List of automatically generated avatar sizes." diff --git a/config/site_settings.yml b/config/site_settings.yml index a897c968549..6081b718c08 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1038,7 +1038,7 @@ files: default: "" regex: '^[a-z0-9\-\/]+$' # can't use '.' when using HTTPS s3_endpoint: - default: "https://s3.amazonaws.com" + default: "" regex: '^https?:\/\/.+[^\/]$' shadowed_by_global: true s3_cdn_url: diff --git a/lib/s3_helper.rb b/lib/s3_helper.rb index fbdde9674a7..67f6b1069d5 100644 --- a/lib/s3_helper.rb +++ b/lib/s3_helper.rb @@ -193,10 +193,11 @@ class S3Helper def self.s3_options(obj) opts = { region: obj.s3_region, - endpoint: SiteSetting.s3_endpoint, force_path_style: SiteSetting.s3_force_path_style } + opts[:endpoint] = SiteSetting.s3_endpoint if SiteSetting.s3_endpoint.present? + unless obj.s3_use_iam_profile opts[:access_key_id] = obj.s3_access_key_id opts[:secret_access_key] = obj.s3_secret_access_key