Raanan Ikar
Raanan Ikar

Reputation: 57

S3 Object Creation with meta-data using CURL is failing

I am trying to perform a HTTP PUT to create and update objects while specifying a custom meta-data header. I am having difficulty generating the correct signature while I have no issue generating signatures for other requested operations. Here is my basic bash / CURL example. Let me emphasize, I must see and use Bash and Curl, not leverage s3curl, or other libraries or CLIs in my specific situation:

#!/bin/bash

file="$1"

key_id="raanan"
key_secret="my-secret"
url="my-s3-endpoint"
bucket="testbucket"
path="$file"
content_type="application/octet-stream"
date="$(LC_ALL=C date -u +"%a, %d %b %Y %X %z")"
md5="$(openssl md5 -binary < "$file" | base64)"
daheader="x-amz-meta-user:qatester\n"
sig="$(printf "PUT\n$md5\n$content_type\n$date\n$daheader$bucket/$path" |    
openssl sha1 -binary -hmac "$key_secret" | base64)"
curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket$path -vv \
-H "Date: $date" \
-H "Authorization: AWS $key_id:$sig" \
-H "Content-Type: $content_type" \
-H "Content-MD5: $md5" \
-H "x-amz-meta-user: qatester"

>>>>HTTP/1.1 403 Forbidden
>>>>?xml version="1.0" encoding="UTF-8" standalone="yes"?><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><Resource></Resource><RequestId></RequestId>    </Error>

Am I missing something here?

Thanks

Upvotes: 0

Views: 1892

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179084

You appear to be missing the / before the bucket name.

date\n$daheader$bucket/$path  # incorrect
date\n$daheader/$bucket/$path # correct

You are also missing a / after the bucket name in the actual URL you're handing to curl.

curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket$path -vv \  # incorrect
curl -k -w "@curl-format.txt" -T $file http://my-s3-endpoint/$bucket/$path -vv \ # correct

With these two changes, the script works for me.

Note, also, this is not Signature V4. This is Signature V2.

Upvotes: 1

Related Questions