Skip to content

fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver - #3722

Merged
lyingbug merged 1 commit into
Tencent:mainfrom
ankit373:fix/s3-cos-virtual-hosted
Oct 7, 2026
Merged

lyingbug merged 1 commit into
Tencent:mainfrom
ankit373:fix/s3-cos-virtual-hosted

Conversation

@ankit373

Copy link
Copy Markdown
Contributor

Description

With STORAGE_TYPE=s3 pointed at Tencent COS (S3_ENDPOINT=https://cos.ap-shanghai.myqcloud.com), WeKnora cannot reach a newly created bucket, while the same credentials work through the COS driver.

Root cause: newS3Client forced path-style addressing for every endpoint that is not amazonaws.com, so requests went to cos.<region>.myqcloud.com/<bucket>/<key>. COS does not accept path-style for buckets created on or after 2024-01-01 (announcement), only <bucket>.cos.<region>.myqcloud.com. force_path_style=false could not override this, because the flag can only turn path-style on.

Fix: pull the decision into s3UsePathStyle and treat *.myqcloud.com hosts like AWS, so they use virtual-hosted style. Virtual-hosted style also works for older COS buckets, so existing setups are unaffected. An explicit force_path_style=true still wins, and every other S3-compatible endpoint (MinIO, self-hosted, etc.) keeps path-style. This follows the same approach as the OBS fix in #3273.

Type of Change

  • 🐛 Bug fix
  • 🧪 Test

Related Issue

Fixes #3134

Testing

  • TestS3UsePathStyle now calls the real helper. The old version re-implemented the condition inside the test, so it could never catch a regression. New cases cover COS, COS with force_path_style, and a lookalike host (cos.myqcloud.com.example.org) that must stay path-style.
  • TestNewS3Client_TencentCOSPutObjectUsesVirtualHostedURL builds the client through newS3Client and captures the actual PutObject request without touching the network. Before the fix it fails with host = "cos.ap-shanghai.myqcloud.com", path = "/examplebucket-1250000000/a/b.txt". After the fix it passes with examplebucket-1250000000.cos.ap-shanghai.myqcloud.com and /a/b.txt.

Commands run:

  • go test ./internal/application/service/file/: pass
  • go vet ./internal/application/service/file/: pass
  • golangci-lint run --new-from-merge-base=upstream/main ./internal/application/service/file/... with v2.12.2 (the version pinned in go-lint.yml): 0 issues
  • go build ./cmd/server: pass
  • go test ./internal/application/service/: TestSkillPythonVerifier fails locally both with and without this change (it depends on the local Python environment), so it is unrelated.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (not needed, no config surface changed)
  • Breaking changes are clearly called out in the description above (none)

…he S3 driver

newS3Client forced path-style for every non-AWS endpoint, so a COS
endpoint such as https://cos.ap-shanghai.myqcloud.com sent requests to
cos.<region>.myqcloud.com/<bucket>/<key>. COS rejects path-style for
buckets created from 2024-01-01, so STORAGE_TYPE=s3 could not reach new
COS buckets, and force_path_style=false had no way to turn it off.

Treat *.myqcloud.com like AWS and use virtual-hosted style. An explicit
force_path_style still wins, and other S3-compatible endpoints keep
path-style.

Fixes Tencent#3134

Signed-off-by: Ankit Jha <ankit.jha@tradomate.one>
@ankit373

Copy link
Copy Markdown
Contributor Author

@lyingbug a friendly ping when you have a moment. This makes the S3 driver use virtual-hosted addressing for Tencent COS, because COS no longer accepts path-style for buckets created after 2024-01-01 (#3134). CI is green and it merges cleanly.

@lyingbug
lyingbug merged commit 27b9ee7 into Tencent:main Oct 7, 2026
4 checks passed
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.

[Bug]: 腾讯云cos没有用s3的方式进行连接

2 participants