aws/aws-sdk-cpp

S3-CRT Client signature error on s3 object keys with special characters

epasveer opened this issue · 5 comments

Describe the bug

When using the S3-CRT PUT command, this error is encountered if the object key contains a special character. In our case, the '@' character.

The regular S3 PUT command works as intended.

Expected Behavior

s3-crt client would work seamlessly against the same object keys that the regular s3 client supports.

Current Behavior

S3-crt client fails on object keys with special characters with the following message:

The request signature we calculated does not match the signature you provided. Check your key and signing method.

Reproduction Steps

Example code.

Change the bucket name. Make sure the object name has a '@' in the name.

#include <aws/core/Aws.h>
#include <aws/core/client/ClientConfiguration.h>

#include <aws/s3-crt/model/PutObjectRequest.h>
#include <aws/s3-crt/S3CrtClient.h>

#include <aws/s3/S3Client.h>
#include <aws/s3/model/PutObjectRequest.h>

int main(int argc, char ** argv) {

    // Init AWS API
    Aws::SDKOptions awsSdkOptions;
    awsSdkOptions.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Trace;
    awsSdkOptions.httpOptions.installSigPipeHandler = true;
    Aws::InitAPI(awsSdkOptions);

    std::string bucket("your-bucket");
    std::string objectKey("scratch/objectwithspecialchar@");
    std::string region("us-east-1");
    std::string message("Hello, World!");

    // s3 client code: --> works
    {
        Aws::Client::ClientConfiguration config;
        config.region = region;

        Aws::S3::S3Client s3Client(config);

        Aws::S3::Model::PutObjectRequest objectRequest;
        objectRequest.WithBucket(bucket).WithKey(objectKey);

        const std::shared_ptr<Aws::IOStream> inputData = Aws::MakeShared<Aws::StringStream>("");
        *inputData << message.c_str();

        objectRequest.SetBody(inputData);

        auto putObjectOutcome = s3Client.PutObject(objectRequest);

        if (!putObjectOutcome.IsSuccess()) {
            std::cerr << "failed s3 client put: " << putObjectOutcome.GetError().GetMessage() << std::endl;
        } else {
            std::cerr << "s3 client success!" << std::endl;
        }
    }

    // s3-crt client code --> fails on signature verification
    {
        Aws::S3Crt::ClientConfiguration config;
        config.region = region;

        Aws::S3Crt::S3CrtClient s3Client(config);

        Aws::S3Crt::Model::PutObjectRequest objectRequest;
        objectRequest.WithBucket(bucket).WithKey(objectKey);

        const std::shared_ptr<Aws::IOStream> inputData = Aws::MakeShared<Aws::StringStream>("");
        *inputData << message.c_str();

        objectRequest.SetBody(inputData);

        auto putObjectOutcome = s3Client.PutObject(objectRequest);

        if (!putObjectOutcome.IsSuccess()) {
            std::cerr << "failed s3 CRT client put: " << putObjectOutcome.GetError().GetMessage() << std::endl;
        } else {
            std::cerr << "s3 CRT client success!" << std::endl;
        }
    }

    Aws::ShutdownAPI(awsSdkOptions);
}

Possible Solution

Possible resolution from #2898 ??

Additional Information/Context

No response

AWS CPP SDK version used

1.11.258

Compiler and Version used

gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-15)

Operating System and version

Rocky Linux 8.7 (Green Obsidian) x86_64

should have been fixed with #2898. can you try a more recent version?

Sure. I'll try a newer release. I will update this task with the findings.

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

The latest "main" works fine. Thanks for the fix. This task can be closed.

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.