Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
s3: Support non-AWS S3 providers which do not support request checksums.
Alex Vandiveraeed907c50be
diff --git a/docs/production/upload-backends.md b/docs/production/upload-backends.mdindex 831faf141b7..00c1409600b 100644--- a/docs/production/upload-backends.md+++ b/docs/production/upload-backends.md@@ -52,6 +52,10 @@ backend. To enable this backend, you need to do the following:For certain AWS regions, you may need to set the `S3_REGION`setting to your default AWS region's code (e.g., `"eu-central-1"`).+1. Non-AWS block storage providers may need `S3_SKIP_CHECKSUM = True`; you+ should try without this at first, but enable it if you see exceptions+ involving `XAmzContentSHA256Mismatch`.+1. Finally, restart the Zulip server so that your settings changestake effect(`/home/zulip/deployments/current/scripts/restart-server`).diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.pyindex e97f5151321..d1e49af7e9d 100644--- a/zerver/lib/upload/s3.py+++ b/zerver/lib/upload/s3.py@@ -56,6 +56,9 @@ if settings.S3_SKIP_PROXY is True: # nocoveragedef get_bucket(bucket_name: str, authed: bool = True) -> "Bucket":import boto3+ checksum: Literal["when_required", "when_supported"] = (+ "when_required" if settings.S3_SKIP_CHECKSUM else "when_supported"+ )return boto3.resource("s3",aws_access_key_id=settings.S3_KEY if authed else None,@@ -65,6 +68,7 @@ def get_bucket(bucket_name: str, authed: bool = True) -> "Bucket":config=Config(signature_version=None if authed else botocore.UNSIGNED,s3={"addressing_style": settings.S3_ADDRESSING_STYLE},+ request_checksum_calculation=checksum,),).Bucket(bucket_name)diff --git a/zerver/management/commands/runtusd.py b/zerver/management/commands/runtusd.pyindex ce030c66cc4..47671df8e20 100644--- a/zerver/management/commands/runtusd.py+++ b/zerver/management/commands/runtusd.py@@ -73,4 +73,6 @@ class Command(BaseCommand):env_vars["AWS_SECRET_ACCESS_KEY"] = settings.S3_SECRET_KEYif settings.S3_REGION is not None:env_vars["AWS_REGION"] = settings.S3_REGION+ if settings.S3_SKIP_CHECKSUM:+ env_vars["AWS_REQUEST_CHECKSUM_CALCULATION"] = "when_required"os.execvpe("tusd", tusd_args, env_vars)diff --git a/zproject/default_settings.py b/zproject/default_settings.pyindex 1bdeccc4eac..e488a9d4c76 100644--- a/zproject/default_settings.py+++ b/zproject/default_settings.py@@ -166,6 +166,7 @@ S3_UPLOADS_STORAGE_CLASS: Literal["STANDARD_IA",] = "STANDARD"S3_AVATAR_PUBLIC_URL_PREFIX: str | None = None+S3_SKIP_CHECKSUM: bool = FalseLOCAL_UPLOADS_DIR: str | None = NoneLOCAL_AVATARS_DIR: str | None = NoneLOCAL_FILES_DIR: str | None = Nonediff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.pyindex dc811a1f4dc..15016a304c1 100644--- a/zproject/prod_settings_template.py+++ b/zproject/prod_settings_template.py@@ -818,6 +818,7 @@ LOCAL_UPLOADS_DIR = "/home/zulip/uploads"# S3_ADDRESSING_STYLE = "auto"# S3_SKIP_PROXY = True# S3_UPLOADS_STORAGE_CLASS = "STANDARD"+# S3_SKIP_CHECKSUM = False## Maximum allowed size of uploaded files, in megabytes. Set## MAX_FILE_UPLOAD_SIZE to 0 to disable file uploads completely