quarfie / s3presignedUrl_FMFunction

FileMaker custom function to generate a presigned URL to upload/download/delete an object in S3
MIT License
20 stars 4 forks source link

Doesn't work with Garage (locally hosted) #6

Open gompper opened 2 months ago

gompper commented 2 months ago

I'm trying to generate a presigned URL for a locally hosted instance of Garage, but the URL I'm getting results in:

` AccessDenied

Forbidden: Invalid signature /test/test.txt garage

`

I'm using the function as follows:

`s3presignURL ( "GET"; "test"; "garage"; "test.txt"; 1000;

; ; JSONSetElement ( "{}" ; "host" ; "localhost:3900/test" ; JSONString ) )` Note: I had to change (delete the 's' in 'https') [`"https://" & ~host & ~file & "?" & ~query & "&X-Amz-Signature=" & ~signature`](https://github.com/quarfie/s3presignedUrl_FMFunction/blob/14ed0bdc43d7d4c1df777bb8333285a354b7ebbb/s3presignedUrl.fmfunction#L102) to `"http://" & ~host & ~file & "?" & ~query & "&X-Amz-Signature=" & ~signature` in order to make the URL reach the storage. Same values used with the [demo](https://docs.aws.amazon.com/de_de/AmazonS3/latest/userguide/S3OutpostsPresignedUrlUploadObject.html#s3-outposts-presigned-urls-upload-examples) of the AWS-SDK resulted in a working URL. The URL generated by the SDK is identical to the one generated with the FM function, except for the value of *X-Amz-Date* and the value of *X-Amz-Signature*, so my assumption is: If the host address doesnt follow \.s3.\.\ as in [ ~host = If ( IsEmpty ( ~optionsHost ) ; ~bucket & ".s3." & ~region & ".amazonaws.com" ; ~optionsHost ) ;](https://github.com/quarfie/s3presignedUrl_FMFunction/blob/14ed0bdc43d7d4c1df777bb8333285a354b7ebbb/s3presignedUrl.fmfunction#L56) the signature should be calculated differently.
gompper commented 2 months ago

I think I solved my problem.

In the code I only had to, as mentioned above, change from https to http. For the arguments I got a valid presigned URL with:

region: garage theFilePath: /<bucketname>/<file> optionsObj:{ "host" : "localhost:3900" }

The other arguments were as described in the Readme