durch/rust-s3

Cloudflare R2 put_object_stream fails every time with SignatureDoesNotMatch error

Closed this issue · 1 comments

Describe the bug
When using the library with Cloudflare R2, the put_object_stream function fails every time with an 8MB file of all 0s (and any other large file I tired). It gives the following error:

Error: Got HTTP 403 with content '<?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>'

To Reproduce

use s3::{creds::Credentials, Bucket, Region};
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let account_id = std::env::var("S3_ID")?;
    let access_key_id = std::env::var("S3_ACCESS_KEY_ID")?;
    let secret_access_key = std::env::var("S3_SECRET_ACCESS_KEY")?;
    let credentials = Credentials::new(
        Some(&access_key_id),
        Some(&secret_access_key),
        None,
        None,
        None,
    )?;
    let bucket =
        Bucket::new("multipart-testing", Region::R2 { account_id }, credentials)?.with_path_style();

    // empty_file_8_mb = `dd if=/dev/zero of=empty_file_8_mb bs=1 count=8388608`
    let mut file = tokio::fs::File::open("empty_file_8_mb").await?;
    let result = bucket
        .put_object_stream(&mut file, "empty_file_8_mb")
        .await?;

    dbg!(&result);

    Ok(())
}

Expected behavior
I expect it to upload the file with no errors.

Environment

  • cargo 1.70.0 (ec8a8a0ca 2023-04-25)
  • rust-s3 = "0.33.0"

Additional Context

I tried various combinations of nightly, the 0.34.0-beta3 beta, using slashes, not using slashes, always the same result.

I also tried using put_multipart_chunk manually from an existing multipart upload to ensure it was not a concurrency issue and I still get the same error.

Uploading the entire object from memory with put_object works fine.

Test file created with dd if=/dev/zero of=empty_file_8_mb bs=1 count=8388608

Added a test for streaming big objects into R2 which is currently passing