我正在尝试执行HTTP PUT来创建和更新对象,同时指定自定义元数据头。我无法生成正确的签名,而我没有问题为其他请求的操作生成签名。这是我的基本bash / CURL示例。让我强调一下,我必须看到并使用Bash和Curl,而不是在我的特定情况下利用s3curl或其他库或CLI:
#!/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>
我在这里错过了什么吗?
由于
答案 0 :(得分:1)
您似乎错过了存储区名称前的/
。
date\n$daheader$bucket/$path # incorrect
date\n$daheader/$bucket/$path # correct
在您递归卷曲的实际网址中之后,您还错过了/
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
通过这两项更改,该脚本适合我。
另请注意,这是不是签名V4。这是Signature V2。