From 75d6f35069a47c0e93f9b539b494cc2c07b01a41 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Wed, 3 Jan 2024 20:27:53 +0000 Subject: [PATCH] s3: Add a setting for S3 addressing style. This controls if boto3 attempts to use `https://bucketname.endpointname/` or `https://endpointname/bucket/` as its prefix. See https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html Fixes: #28424. --- zerver/lib/upload/s3.py | 1 + zproject/default_settings.py | 1 + zproject/prod_settings_template.py | 1 + 3 files changed, 3 insertions(+) diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py index 7b4099057f..d22c85099d 100644 --- a/zerver/lib/upload/s3.py +++ b/zerver/lib/upload/s3.py @@ -65,6 +65,7 @@ def get_bucket(bucket_name: str, authed: bool = True) -> Bucket: endpoint_url=settings.S3_ENDPOINT_URL, config=Config( signature_version=None if authed else botocore.UNSIGNED, + s3={"addressing_style": settings.S3_ADDRESSING_STYLE}, ), ).Bucket(bucket_name) diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 0f6e3a22ba..91d0ef9c59 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -148,6 +148,7 @@ S3_AVATAR_BUCKET = "" S3_AUTH_UPLOADS_BUCKET = "" S3_REGION: Optional[str] = None S3_ENDPOINT_URL: Optional[str] = None +S3_ADDRESSING_STYLE: Literal["auto", "virtual", "path"] = "auto" S3_SKIP_PROXY = True S3_UPLOADS_STORAGE_CLASS: Literal[ "GLACIER_IR", diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py index 63969f5efc..adc18a92cd 100644 --- a/zproject/prod_settings_template.py +++ b/zproject/prod_settings_template.py @@ -788,6 +788,7 @@ LOCAL_UPLOADS_DIR = "/home/zulip/uploads" # S3_AVATAR_BUCKET = "" # S3_REGION = None # S3_ENDPOINT_URL = None +# S3_ADDRESSING_STYLE = "auto" # S3_SKIP_PROXY = True # S3_UPLOADS_STORAGE_CLASS = "STANDARD"