我无法使用S3 IAM策略使用Paperclip上传.我甚至遇到直接jQuery上传的问题(没有Paperclip).我的方案如下,我有一个应用程序,将有许多网站.每个站点都有自己的桶,应该只能访问自己的桶,没有其他人可以访问.该IAM示例策略文档解释正是我想在做"范例:允许水桶到一个文件夹的每个IAM用户访问".我为应用程序设置了一个IAM组,并且该组中的每个站点都有一个用户.这些IAM用户属于该组.该小组的政策如下:
{
"Version":"2012-10-17",
"Statement":[{
"Effect":"Allow",
"Action":[
"s3:PutObject",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion"
],
"Resource":"arn:aws:s3:::my-app/${aws:username}/*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是我在存储桶上的CORS配置,当然,dev会在以后被锁定:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
这是我的Paperclip设置:
has_attached_file :background_image,
storage: :s3,
s3_credentials: {
access_key_id: "xxx",
secret_access_key: "xxx"
},
bucket: "my-app",
s3_permissions: "public-read",
path: "/background_images/:id/:filename"
Run Code Online (Sandbox Code Playgroud)
我以前在使用策略时直接使用策略,这确实有效,但是当我进入具有许多"站点"的生产环境时,它不像我需要的那样灵活.据我所知,我已完全遵循文档,但我所做的任何事都会导致"访问被拒绝".此时我甚至不确定我的问题是我的IAM策略还是我的Paperclip配置.
编辑:澄清.
编辑2:最终解决方案
这是我基于这篇文章的最终IAM政策:
{
"Version":"2012-10-17",
"Statement": [
{
"Sid": "AllowUserToSeeBucketListInTheConsole",
"Action": ["s3:ListAllMyBuckets", "s3:GetBucketLocation"],
"Effect": "Allow",
"Resource": ["arn:aws:s3:::*"]
},
{
"Sid": "AllowRootAndHomeListingOfCompanyBucket",
"Action": ["s3:ListBucket"],
"Effect": "Allow", …Run Code Online (Sandbox Code Playgroud) ruby-on-rails amazon-s3 paperclip amazon-web-services amazon-iam