FIX: S3 custom endpoint incompatible with dualstack (#29654)

Followup 0568d36133

S3 itself and other S3-compatible providers do not
allow using an S3 custom endpoint and dualstack at
the same time, so this commit fixes that by not using
dualstack when the endpoint is present.
This commit is contained in:
Martin Brennan 2024-11-08 11:12:49 +10:00 committed by GitHub
parent 64291fedf8
commit 97cf069a06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View File

@ -169,7 +169,7 @@ class SiteSetting < ActiveRecord::Base
end
def self.use_dualstack_endpoint
!SiteSetting.Upload.s3_region.start_with?("cn-")
SiteSetting.Upload.s3_endpoint.blank? && !SiteSetting.Upload.s3_region.start_with?("cn-")
end
def self.enable_s3_uploads

View File

@ -196,4 +196,25 @@ RSpec.describe SiteSetting do
expect(SiteSetting.all_settings(filter_categories: ["required"]).count).to eq(12)
end
end
describe "Upload" do
before { setup_s3 }
describe "#use_dualstack_endpoint" do
it "returns false if s3_endpoint has been set" do
SiteSetting.s3_endpoint = "https://s3clone.test.com"
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(false)
end
it "returns false if the s3_region is in China" do
SiteSetting.s3_region = "cn-north-1"
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(false)
end
it "returns true if the s3_region is not in China" do
SiteSetting.s3_region = "us-west-1"
expect(SiteSetting.Upload.use_dualstack_endpoint).to eq(true)
end
end
end
end

View File

@ -139,10 +139,6 @@ module SystemHelpers
SiteSetting.s3_secret_access_key = MinioRunner.config.minio_root_password
SiteSetting.s3_endpoint = MinioRunner.config.minio_server_url
# This is necessary for Minio because you cannot use dualstack
# at the same time as using a custom S3 endpoint.
SiteSetting.Upload.stubs(:use_dualstack_endpoint).returns(false)
SiteSetting.enable_direct_s3_uploads = enable_direct_s3_uploads
SiteSetting.secure_uploads = enable_secure_uploads