Repository navigation
fix(storage): use virtual-hosted addressing for Tencent COS through the S3 driver - #3722
Merged
Merged
Conversation
…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>
1 task done
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
With
STORAGE_TYPE=s3pointed 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:
newS3Clientforced path-style addressing for every endpoint that is notamazonaws.com, so requests went tocos.<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=falsecould not override this, because the flag can only turn path-style on.Fix: pull the decision into
s3UsePathStyleand treat*.myqcloud.comhosts like AWS, so they use virtual-hosted style. Virtual-hosted style also works for older COS buckets, so existing setups are unaffected. An explicitforce_path_style=truestill 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
Related Issue
Fixes #3134
Testing
TestS3UsePathStylenow 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 withforce_path_style, and a lookalike host (cos.myqcloud.com.example.org) that must stay path-style.TestNewS3Client_TencentCOSPutObjectUsesVirtualHostedURLbuilds the client throughnewS3Clientand captures the actual PutObject request without touching the network. Before the fix it fails withhost = "cos.ap-shanghai.myqcloud.com",path = "/examplebucket-1250000000/a/b.txt". After the fix it passes withexamplebucket-1250000000.cos.ap-shanghai.myqcloud.comand/a/b.txt.Commands run:
go test ./internal/application/service/file/: passgo vet ./internal/application/service/file/: passgolangci-lint run --new-from-merge-base=upstream/main ./internal/application/service/file/...with v2.12.2 (the version pinned in go-lint.yml): 0 issuesgo build ./cmd/server: passgo test ./internal/application/service/:TestSkillPythonVerifierfails locally both with and without this change (it depends on the local Python environment), so it is unrelated.Checklist
git diff --check origin/main...HEADpasses