2017-03-06 170 views
0

我正在尝试向我的存储区发布帖子,而且我对于formdata的政策应该如何与我的存储区政策相匹配有点困惑。s3存储桶政策发布

@time = Time.now.utc 
@time_policy = @time.strftime('%Y%m%dT000000Z') 
@date_stamp = @time.strftime('%Y%m%d') 

ret = {"expiration" => 1.day.from_now.utc.xmlschema, 
     "conditions" => [ 
      {"bucket" => Rails.application.secrets.aws_bucket}, 
      {"x-amz-credential": "#{Rails.application.secrets.aws_access_key_id}/#{@date_stamp}/us-west-2/s3/aws4_request"}, 
      {"x-amz-algorithm": "AWS4-HMAC-SHA256"}, 
      {"x-amz-date": @time_policy }, 
     ] 
     } 

    @policy = Base64.encode64(ret.to_json).gsub(/\n|\r/, '') 

桶政策:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Sid": "Allow Get", 
      "Effect": "Allow", 
      "Principal": "*", 
      "Action": "s3:GetObject", 
      "Resource": "arn:aws:s3:::example-development/*" 
     }, 
     { 
      "Sid": "AddPerm", 
      "Effect": "Allow", 
      "Principal": { 
       "AWS": "arn:aws:iam::123456789:user/example" 
      }, 
      "Action": "s3:*", 
      "Resource": ["arn:aws:s3:::example-development/*","arn:aws:s3:::example-development"] 
     } 
    ] 
} 

做这些比赛?我没有偶然发现任何显示两者并行比较的文档。

回答

1

条件独立于政策。

条件强制执行上载的特定属性。例如,{ "{acl": "public-read" }强制执行上载必须将ACL设置为public-read的规则。如果上传未设置该值,则上传将被拒绝。

存储桶策略在有人试图访问Amazon S3时执行。因此,"s3:x-amz-acl": "public-read"表示只要该值为真,人们就可以访问存储桶。这是一个非常奇怪的事情放在存储桶策略中,因为该属性只与PutObject操作有关。从S3读取对象时,它不适用。

有关使用PutObject的示例,请参阅Specifying Conditions in a Policy

+0

我同意,我真的只是想让上传工作。当时,我不确定一个非特定的桶是否有问题。 –