haiwen / seafile

High performance file syncing and sharing, with also Markdown WYSIWYG editing, Wiki, file label and other knowledge management features.
http://seafile.com/
Other
12.14k stars 1.54k forks source link

Cannot connect to Cloudflare R2, which is an S3 compatible storage #2790

Open akang943578 opened 2 months ago

akang943578 commented 2 months ago

I'm trying to setup storage to use new Cloudflare R2's S3 compatible API but it is not working:

Here is my seafile.conf:

[commit_object_backend]
name = s3
bucket = seafile-commit-objects
key_id = KEY_ID
key = SECRET_KEY
host = a98785e068722eb3f6d8d56deb7143f2.r2.cloudflarestorage.com
path_style_request = true
use_v4_signature = true
aws_region = auto
use_https = true

[fs_object_backend]
name = s3
bucket = seafile-fs-objects
key_id = KEY_ID
key = SECRET_KEY
host = a98785e068722eb3f6d8d56deb7143f2.r2.cloudflarestorage.com
path_style_request = true
use_v4_signature = true
aws_region = auto
use_https = true

[block_backend]
name = s3
bucket = seafile-block-objects
key_id = KEY_ID
key = SECRET_KEY
host = a98785e068722eb3f6d8d56deb7143f2.r2.cloudflarestorage.com
path_style_request = true
use_v4_signature = true
aws_region = auto
use_https = true

It fails when create Library:

2024-06-28 10:05:43 start to serve on pipe client
2024-06-28 10:05:43 ../common/s3-client.c(1085): S3 error status for HEAD: 403.
2024-06-28 10:05:43 ../common/s3-client.c(841): S3 error status for PUT: 403.
2024-06-28 10:05:43 ../common/s3-client.c(842): Request URL: https://a98785e068722eb3f6d8d56deb7143f2.r2.cloudflarestorage.com/seafile-commit-objects/46fd1c91-5585-43f3-b809-183fca1676db/8dbf00cbb241bb30b99bb751ce1b0e156ace7988
2024-06-28 10:05:43 ../common/s3-client.c(843): Request headers:
2024-06-28 10:05:43 ../common/s3-client.c(731): Date: Fri, 28 Jun 2024 02:05:43 GMT
2024-06-28 10:05:43 ../common/s3-client.c(731): Authorization: AWS4-HMAC-SHA256 Credential=433f47c9c573a866daf1318f278d5a41/20240628/auto/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=9d10c24330d6a560d7ac3640701ec7edf655b44c35a48382e4ff0e7c7308626d
2024-06-28 10:05:43 ../common/s3-client.c(731): x-amz-content-sha256: 01e4227637330059ae1fae5cf7166b4a29e6cd2899249c858310b572da84f064
2024-06-28 10:05:43 ../common/s3-client.c(731): x-amz-date: 20240628T020543Z
2024-06-28 10:05:43 ../common/obj-backend-s3.c(354): Put object 8dbf00cbb241bb30b99bb751ce1b0e156ace7988 error 403. Response:
<?xml version="1.0" encoding="UTF-8"?><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your secret access key and signing method. </Message></Error>horization: AWS4-HMAC
2024-06-28 10:05:43 repo-mgr.c(7638): Failed to add commit.

My credentials are ok, as tested with another tools.

I found another Issue about the S3 compatible issue: https://github.com/haiwen/seafile/issues/2356, but it still not resolved after 4 years passed.

Can you resolve it as high priority, or can you point out where is the s3-client.c located? I searched all the files in the repositories but could not found s3-client.c. If you can point out the file location, maybe I can check it and give an fix on it.

killing commented 1 month ago

You should follow the instructions in this manual: https://manual.seafile.com/deploy_pro/setup_with_amazon_s3/#other-public-hosted-s3-storage (notice for the "other public hosted s3 storage" part).

Specifically for your case, you can try to remove the "path_style_request". The "auto" region also looks strange. It should be set to the region where you allocate your buckets.