【问题标题】:S3 Object Creation with meta-data using CURL is failing使用 CURL 使用元数据创建 S3 对象失败
【发布时间】:2015-10-30 00:55:07
【问题描述】:

我正在尝试执行 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>

我错过了什么吗?

谢谢

【问题讨论】:

  • 你在这里使用什么版本的签名?这个方法的文档在哪里?
  • 您好,v4 签名,相关文档位于 docs.aws.amazon.com/AmazonS3/latest/API/…
  • 我没有在任何地方看到该文档中引用的 md5。你确定你在你的代码中遵循这些指示而不是旧版本吗?
  • 是的,我在 PUT、GET 和 HEAD 请求中成功使用了它,但是当我包含元数据标头时只有 auth sig 失败消息。
  • @EtanReisner 您的观察是准确的,这不是 V4。是V2。 md5 不是实际 hmac 签名算法的一部分本身,而是用于Content-MD5 标头,它是要签名的字符串中的一个组件。

标签: bash http amazon-web-services curl amazon-s3


【解决方案1】:

您似乎缺少存储桶名称前的/

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

您还缺少/ 您传递给 curl 的实际 URL 中的存储桶名称。

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

通过这两项更改,该脚本适用于我。

另外请注意,这是不是 Signature V4。这是Signature V2

【讨论】:

  • $date\n$daheader/$bucket/$path" 也不起作用。我最初尝试过这种方式,但它也失败了。
  • 谢谢先生们!做到了! ----> 我们已经完全上传好了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-19
  • 1970-01-01
  • 2016-08-23
  • 1970-01-01
相关资源
最近更新 更多