Skip to content

fix: auto-detect GCS endpoint for correct V4 signature config#635

Merged
yaojin3616 merged 3 commits into
mainfrom
fix/gcs-virtual-hosted-style
May 29, 2026
Merged

fix: auto-detect GCS endpoint for correct V4 signature config#635
yaojin3616 merged 3 commits into
mainfrom
fix/gcs-virtual-hosted-style

Conversation

@yaojin3616
Copy link
Copy Markdown
Collaborator

Problem

GCS S3-compatible API continues to reject put_object with SignatureDoesNotMatch even after setting ContentType explicitly.

Root Cause

The boto3/aiobotocore clients were hardcoded to:

  • addressing_style: "path" — GCS S3 API requires virtual-hosted-style
  • region_name: used raw S3_REGION env var (often empty) — GCS requires "auto" for V4 signatures

With path-style addressing, GCS computes the signature over a different canonical request than what boto3 signs, causing an unrecoverable mismatch.

Fix

  • Extract shared _boto_config() method used by both sync and async clients
  • Auto-detect storage.googleapis.com in endpoint URL via _is_gcs()
  • When GCS is detected: set addressing_style=virtual, region_name=auto
  • MinIO and other S3 backends remain unchanged (path style, user-specified region)

Verification

Existing test test_s3_backend_passes_max_pool_connections passes. The test creates a mock S3Backend — GCS detection is endpoint-based and only activates when storage.googleapis.com appears in the URL.

yaojin added 3 commits May 30, 2026 03:26
GCS S3-compatible API requires:
- virtual-hosted-style addressing (not path-style)
- region_name='auto' for V4 signatures

Previously both clients were hardcoded to path-style addressing
and used the raw S3_REGION value (often empty), causing
SignatureDoesNotMatch on every put_object.

Now _boto_config() auto-detects storage.googleapis.com and applies
the correct settings, while MinIO and other S3 backends keep
path-style addressing unchanged.
@yaojin3616 yaojin3616 merged commit 2e26c6e into main May 29, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant