S3Mock icon indicating copy to clipboard operation
S3Mock copied to clipboard

Cannot get generate_presigned_post to work

Open chaen opened this issue 5 years ago • 7 comments

Hi,

I am running S3Mock in a container. I try uploading a file there using pre-signed URL with boto3. In order to do so, I literally copy paste from the official tutorial: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-presigned-urls.html#generating-a-presigned-url-to-upload-a-file

However, this ends up in a http return code 400 The server does not spit any error nor any message at all. This is the presigned output I get, which seems quite legit:

{'url': u'http://s3-direct:9090/myFirstBucket', 'fields': {'policy': u'eyJjb25kaXRpb25zIjogW3siYnVja2V0IjogIm15Rmlyc3RCdWNrZXQifSwgeyJrZXkiOiAidGVzdFByZXNpZ25lZC5weSJ9XSwgImV4cGlyYXRpb24iOiAiMjAyMC0wMy0yOFQwMDozOTozN1oifQ==', 'AWSAccessKeyId': u'aws_access_key_id', 'key': 'testPresigned.py', 'signature': u'Hnb1No6c8bU0Mat62jApXL3IY/Q='}}

Any hint on how I could tackle that ? Thanks for your help, and thanks for this super useful product !! :-)

chaen avatar Mar 27 '20 23:03 chaen

I am running into a similar issue, and the presigned urls works for me when actually using s3

jfarshankar avatar May 01 '22 04:05 jfarshankar

2022-05-01 17:15:27.948 DEBUG 1 --- [tp1003693033-21] o.s.web.servlet.DispatcherServlet        : POST "/bucket", parameters={multipart}
2022-05-01 17:15:27.990 DEBUG 1 --- [tp1003693033-21] o.s.w.s.m.m.a.HttpEntityMethodProcessor  : Using 'application/x-www-form-urlencoded', given [application/x-www-form-urlencoded, application/xml] and supported [*/*]
2022-05-01 17:15:27.992 DEBUG 1 --- [tp1003693033-21] o.s.web.servlet.DispatcherServlet        : Completed 400 BAD_REQUEST

I don't know the first thing about spring, but based on the debug logs and FileStoreController, this request isn't getting mapped to any handler. I tried to use a presigned put, but I can't get that to work with user-defined metadata either with S3Mock or S3.

jfarshankar avatar May 01 '22 17:05 jfarshankar

Sorry, but S3Mock currently does not implement the generation of presigned URLs.

afranken avatar May 02 '22 10:05 afranken

Darn, thanks for the information.

jfarshankar avatar May 02 '22 15:05 jfarshankar

Well, I can do basic presigned put/get requests with S3Mock, should that not be possible?

jfarshankar avatar May 02 '22 15:05 jfarshankar

You mean, if you add presigned parameters to a URL, you can request that against S3Mock? That is expected - those parameters are currently completely ignored.

#125 lists a bug where a HEAD is possible with presigned parameters allowing only a GET request.

afranken avatar May 03 '22 07:05 afranken

ah, thanks for the clarification.

jfarshankar avatar May 03 '22 16:05 jfarshankar

I wrote tests for all presigned requests, everything works as expected. Parameters are completely ignored, however. This is good enough to test happy cases in your integration. See readme for a full description.

afranken avatar Aug 15 '23 14:08 afranken

@chaen what I did not realize is that the SDK you're using is generating the presigned URLs. You need to configure the SDK for path-style access, then the presigned URLs will work too. In the Java SDK, presigner and S3Client use different configurations.

afranken avatar Aug 15 '23 14:08 afranken