FEATURE: Make S3 presigned GET URL expiry configurable (#16912)

Previously we hardcoded the DOWNLOAD_URL_EXPIRES_AFTER_SECONDS const
inside S3Helper to be 5 minutes (300 seconds). For various reasons,
some hosted sites may need this to be longer for other integrations.

The maximum expiry time for presigned URLs is 1 week (which is
604800 seconds), so that has been added as a validation on the
setting as well. The setting is hidden because 99% of the time
it should not be changed.
This commit is contained in:
Martin Brennan
2022-05-26 09:53:01 +10:00
committed by GitHub
parent 08cd7a3849
commit 641c4e0b7a
9 changed files with 17 additions and 11 deletions

View File

@@ -132,7 +132,7 @@ module BackupRestore
end
def create_file_from_object(obj, include_download_source = false)
expires = S3Helper::DOWNLOAD_URL_EXPIRES_AFTER_SECONDS
expires = SiteSetting.s3_presigned_get_url_expires_after_seconds
BackupFile.new(
filename: File.basename(obj.key),
size: obj.size,

View File

@@ -224,7 +224,7 @@ module FileStore
url.sub(File.join("#{schema}#{absolute_base_url}", folder), File.join(SiteSetting.Upload.s3_cdn_url, "/"))
end
def signed_url_for_path(path, expires_in: S3Helper::DOWNLOAD_URL_EXPIRES_AFTER_SECONDS, force_download: false)
def signed_url_for_path(path, expires_in: SiteSetting.s3_presigned_get_url_expires_after_seconds, force_download: false)
key = path.sub(absolute_base_url + "/", "")
presigned_get_url(key, expires_in: expires_in, force_download: force_download)
end
@@ -343,7 +343,7 @@ module FileStore
url,
force_download: false,
filename: false,
expires_in: S3Helper::DOWNLOAD_URL_EXPIRES_AFTER_SECONDS
expires_in: SiteSetting.s3_presigned_get_url_expires_after_seconds
)
opts = { expires_in: expires_in }

View File

@@ -15,7 +15,8 @@ class S3Helper
# * cache time for secure-media URLs
# * expiry time for S3 presigned URLs, which include backup downloads and
# any upload that has a private ACL (e.g. secure uploads)
DOWNLOAD_URL_EXPIRES_AFTER_SECONDS ||= 5.minutes.to_i
#
# SiteSetting.s3_presigned_get_url_expires_after_seconds
##
# Controls the following: