s3cmd
是通过运行epel-testing
repo安装的:
yum --enablerepo epel-testing install s3cmd
然后我用s3cmd --configure
调用了配置工具,但是我收到了这个错误:
Test access with supplied credentials? [Y/n]
Please wait, attempting to list all buckets...
ERROR: Test failed: 400 (InvalidToken): The provided token is malformed or otherwise invalid.
Invoked as: /usr/bin/s3cmd --configureProblem: AttributeError: 'S3Error' object has no attribute 'find'
S3cmd: 1.5.0-beta1
python: 2.6.8 (unknown, Mar 14 2013, 09:31:22)
[GCC 4.6.2 20111027 (Red Hat 4.6.2-2)]
Traceback (most recent call last):
File "/usr/bin/s3cmd", line 2323, in <module>
main()
File "/usr/bin/s3cmd", line 2221, in main
run_configure(options.config, args)
File "/usr/bin/s3cmd", line 1704, in run_configure
if e.find('403') != -1:
AttributeError: 'S3Error' object has no attribute 'find'
我确定钥匙是正确的。
你对此有什么想法吗?
更新时间3月21日星期五22:44:42 ICT 2014
在调试模式下运行时找到一些线索。
使用相同的凭据,在工作系统上:
DEBUG: SignHeaders: 'GET\n\n\n\nx-amz-date:Fri, 21 Mar 2014 07:07:18 +0000\n/'
在失败的系统上:
DEBUG: SignHeaders: 'GET\n\n\n\nx-amz-date:Fri, 21 Mar 2014 07:40:56 +0000\nx-amz-security-token:AQoDYXdzENb...\n/'
此安全令牌取自元数据:
# wget -O - -q 'http://169.254.169.254/latest/meta-data/iam/security-credentials/myrole'
{
"Code" : "Success",
"LastUpdated" : "2014-03-21T12:45:27Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "foo",
"SecretAccessKey" : "bar",
"Token" : "AQoDYXdzENb....",
"Expiration" : "2014-03-21T19:18:02Z"
}
所以我的问题应该改为:为什么有时s3cmd
在运行x-amz-security-token
时添加--configure
到头部(我不使用--add-header
)?
安装s3cmd,设置IAM并附加“Amazon S3 Full Access”角色后,我也遇到了“提供的令牌格式错误或无效”错误。接下来,我创建了一个IAM并附加了一个带有管理员凭据(一切)的策略。
使用这个新的IAM再次出现错误。
在github.com线程中,@ mdomsch提到了使用EC2和嵌入式IAM角色的一些可能问题 - 这就是我使用s3cmd的EC2所具有的。
接下来,我试着跑步。
s3cmd --access_key=xxxx --secret_key=xxxxxxxxxxxxx ls
使用带有S3策略的IAM密钥并且它有效。
因此,s3cmd默认使用EC2中嵌入角色的凭据。我确信,如果您使用可以访问S3的角色启动另一个EC2 - 您将无法获得“提供的令牌格式错误或无效”错误。
但是 - 请不要使用s3cmd将-access_key=xxxx --secret_key=xxxxxxxxxxxxx
参数粘贴到任何脚本中。尽可能 - 尝试在启动时将角色嵌入到EC2中(良好的安全实践)
无论如何 - 测试 - 我启动了另一个EC2 w / out任何嵌入式IAM角色,已安装s3cmd,已配置 - 并且所有内容都按照预期使用具有S3策略的IAM用户工作。
这让我筋疲力尽了一两个小时。我在EC2实例上修复此问题的方法是在配置s3cmd之前在环境中设置我的安全凭据。
最简单的方法是将AWS Key和Secret添加为环境变量:
export AWS_ACCESS_KEY_ID=EXAMPLE_KEY
export AWS_SECRET_ACCESS_KEY=EXAMPLE_SECRET
您还可以在〜/ .aws中设置aws_config_file。
设置好环境后,运行s3cmd --configure,然后设置为go。
对于那些有同样问题的人来说这是我的解决方案:创建/编辑文件/home/vagrant/.s3cfg并在引号之间添加你的秘密和密钥,例如:
access_key="BLAHBBLAHBBLAHBBLAHB"
secret_key="2T0wyvmhfGw42T0wyvmhfGw4+-"
请注意,Windows 10上也会出现此问题:
aws s3 ls s3://mybucketname/
我也为EC2实例分配了具有完全管理员访问权限的IAM角色。在创建具有完全管理员权限的用户后,我所做的全部是.aws / config和.aws / credentials文件:
aws configure
好老的移除和替换得到了我的支持。