FIX: Use dualstack S3 endpoint for direct uploads (#29611)

When we added direct S3 uploads to Discourse, which use
presigned URLs, we never took into account the dualstack
endpoints for IPv6 on S3.

This commit fixes the issue by using the dualstack endpoints
for presigned URLs and requests, which are used in the
get-presigned-put and batch-presign-urls endpoints used when
directly uploading to S3.

It also makes regular S3 requests for `put` and so on use
dualstack URLs. It doesn't seem like there is a downside to
doing this, but a bunch of specs needed to be updated to reflect this.
This commit is contained in:
Martin Brennan
2024-11-07 11:06:39 +10:00
committed by GitHub
parent cc01555fce
commit 0568d36133
10 changed files with 90 additions and 27 deletions

View File

@ -82,9 +82,8 @@ RSpec.describe BackupRestore::S3BackupStore do
end,
)
setup_s3
SiteSetting.s3_backup_bucket = "s3-backup-bucket"
SiteSetting.s3_access_key_id = "s3-access-key-id"
SiteSetting.s3_secret_access_key = "s3-secret-access-key"
SiteSetting.backup_location = BackupLocationSiteSetting::S3
end

View File

@ -171,16 +171,14 @@ RSpec.shared_examples "backup store" do
end
it "runs if SiteSetting.automatic_backups_enabled? is true" do
stub_request(
:get,
"https://s3-backup-bucket.s3.amazonaws.com/?list-type=2&prefix=default/",
).to_return(status: 200, body: "", headers: {})
stub_request(:head, "https://s3-backup-bucket.s3.amazonaws.com/").to_return(
base_backup_s3_url = "https://s3-backup-bucket.s3.dualstack.us-west-1.amazonaws.com"
stub_request(:get, "#{base_backup_s3_url}/?list-type=2&prefix=default/").to_return(
status: 200,
body: "",
headers: {
},
)
stub_request(:head, "#{base_backup_s3_url}/").to_return(status: 200, body: "", headers: {})
SiteSetting.automatic_backups_enabled = true
scheduleBackup = Jobs::ScheduleBackup.new