minio / minio-cpp

MinIO C++ Client SDK for Amazon S3 Compatible Cloud Storage
https://minio-cpp.min.io/
Apache License 2.0
136 stars 56 forks source link

Signature Mismatch Issue with GetPresignedObjectUrl() in MinIO C++ SDK #110

Closed bboy-hui closed 8 months ago

bboy-hui commented 8 months ago

I encountered an issue when generating a presigned URL using the GetPresignedObjectUrl() method from the MinIO C++ SDK. Upon attempting to access this URL, I received an error indicating that "The request signature we calculated does not match the signature you provided. Check your key and signing method (SignatureDoesNotMatch)." I have verified that both my accesskey and secretkey are correct.

My MinIO server is deployed using Docker. The SDK version was the latest, compiled from the official GitHub repository. Notably, when I obtain a presigned URL using the mc client, the generated URL works fine. Moreover, if I use the same SDK to access the official MinIO demo server at play.min.io, the URL returned by the same code also works properly. I have also checked the system time synchronization to ensure that the time on my client and server is in sync.

Could you please help me identify the possible cause of this issue?

code:

include "client.h"

int main(int argc, char* argv[]) { // Create S3 base URL. minio::s3::BaseUrl base_url("192.168.15.17:9000",false);

// Create credential provider. minio::creds::StaticProvider provider( "Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG");

// Create S3 client."youraccesskey", "yoursecretkey" minio::s3::Client client(base_url, &provider); // Create bucket exists arguments. minio::s3::BucketExistsArgs args; args.bucket = "whotest";

// Call bucket exists. minio::s3::BucketExistsResponse resp = client.BucketExists(args);

// Handle response. if (resp) { if (resp.exist) { std::cout << "my-bucket exists" << std::endl; } else { std::cout << "my-bucket does not exist" << std::endl; } } else { std::cout << "unable to do bucket existence check; " << resp.Error().String() << std::endl; }

// Create get presigned object url arguments. minio::s3::GetPresignedObjectUrlArgs args1;

args1.bucket = "whotest"; args1.object = "photo.png"; args1.method = minio::http::Method::kGet; args1.expiry_seconds = 60 60 24 * 7; // 7 day.

// Call get presigned object url. minio::s3::GetPresignedObjectUrlResponse resp1 = client.GetPresignedObjectUrl(args1);

// Handle response. if (resp1) { std::cout << "presigned URL to get object: " << resp1.url << std::endl; } else { std::cout << "unable to get presigned object url; " << resp1.Error().String() << std::endl; }

return 0; }

balamurugana commented 8 months ago

As you are able to generate presigned URL for play.min.io and the generated URL works fine, the issue should be outside of minio-cpp i.e. you might have passed wrong values to execute the generated URL.

Please share URLs you generated using mc and minio-cpp.

bboy-hui commented 8 months ago

minio-cpp: http://192.168.15.17:9000/whotest/photo.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20240305%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240305T092833Z&X-Amz-Expires=604800&X-Amz-Signature=82b0e4372f2b4763270a5be87ae64ea80bbf7c733ec8a98404eef0b8686bf194&X-Amz-SignedHeaders=host mc: http://192.168.15.17:9000/whotest/photo.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20240305%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240305T093356Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=5303583c97dd5057dad7c3281d87667383f5fcf838d0e425a38971e47636b757

thank you

balamurugana commented 8 months ago

I do not see any difference. How did you execute these URLs?

bboy-hui commented 8 months ago

thank you ,I used the wrong execution tool.

bboy-hui commented 8 months ago

Hello, I mistakenly thought that I was using the wrong tool.The URLs I used are as follows: 1709696631726 17096965778675 When I use the PUT method to obtain a presigned URL for uploading files, the generated URL is also unusable, but it works when I use the minio-python SDK.

minio-cpp url:http://192.168.15.17:9000/whotest/photo.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20240306%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240306T031643Z&X-Amz-Expires=604800&X-Amz-Signature=dcebadab495c9f5c40917633eabdda0b0ffd1f54502243dc35862b99f22c487a&X-Amz-SignedHeaders=host

minio-py url:http://192.168.15.17:9000/whotest/photo.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=Q3AM3UQ867SPQQA43P2F%2F20240306%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240306T031844Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=9fecc32e9a9f188f3537ae18e2c8e3af3ae1e17300033763d7403a74acbfe74d

up_17096950603837 up17096952127852

balamurugana commented 8 months ago

I am able to reproduce this issue locally.