我看到aws s3 ls和aws s3api list-buckets 的不同行为
这是第一个:
$ aws s3 ls s3://demo.for.customers
Bucket: demo.for.customers
Prefix:
LastWriteTime Length Name
------------- ------ ----
PRE 5CE4D191-FD14-4C85-8146-9FB8C29B7A7B/
PRE FFBC4675-F864-40E9-8AB8-BDF7A0437010/
因此,我可以列出存储桶demo.for.customers中的对象
现在,当我使用s3api运行相同的东西时,我被拒绝访问:
$ aws s3api list-objects --bucket demo.for.customers
A client error (AccessDenied) occurred: Access Denied
问题:为什么我会因为通过 s3api 列出对象而被拒绝访问。
我提出这个问题的原因是如果我使用AWS S3 Ruby SDK也会遇到同样的问题。
但是,当我使用aws s3 ls时,一切都很好。
因此,AWS S3 Ruby SDK和aws s3api表现出相同的行为。所以,我在这里只粘贴aws s3api CLI问题。
顺便说一句,这是已应用于运行上述所有命令的用户的 IAM 策略:
{
"Statement": [
{
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::"
]
},
{
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::demo.for.customers"
],
"Condition": {
"StringEquals": {
"s3:prefix": [
"",
"FFBC4675-F864-40E9-8AB8-BDF7A0437010/"
],
"s3:delimiter": [
"/"
]
}
}
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": [
"arn:aws:s3:::demo.for.customers/FFBC4675-F864-40E9-8AB8-BDF7A0437010/"
]
}
]
}
这是产生完全相同错误的ruby代码;
#!/usr/bin/ruby
require 'aws-sdk'
require 'awesome_print'
AWS.config( :access_key_id => 'whatever',
:secret_access_key => 'again whatever',
:region => 'us-west-2')
s3 = AWS.s3
buckets = s3.client.list_objects(:bucket_name => "demo.for.customers")
ap buckets
输出是:
# ruby s3policies.rb
/var/lib/gems/1.9.1/gems/aws-sdk-1.14.1/lib/aws/core/client.rb:366:in `return_or_raise': Access Denied (AWS::S3::Errors::AccessDenied)