简体   繁体   English

Amazon S3权限

[英]Amazon S3 Permissions

I'm using temporary sessions in Amazon S3 with GetSessionToken/GetFederationToken, I am planing on having more than 10K users each one can upload to S3 so initialy I thought of use a bucket for each user and set write (upload) permissions per bucket for each user, but since there is a limitation on the number of buckets per Amazon account I have forsaken that idea. 我正在使用GetSessionToken / GetFederationToken在Amazon S3中使用临时会话,我计划每个人都可以上传到S3超过10K用户,因此我最初想到为每个用户使用一个存储桶并为每个存储桶设置写入(上载)权限每个用户,但由于每个亚马逊帐户的存储桶数量有限制,我已经抛弃了这个想法。

How can I set a permission like allow public read, and upload only if the prefix on the key of the object that the user wants to upload ? 如何设置允许公共读取的权限,并仅在用户想要上载的对象的键的前缀上传?

For example if username X uploads a file the key must be like X_filename. 例如,如果用户名X上传文件,则密钥必须类似于X_filename。

Or any other way which allows me to have security, this is for a mobile app and I would not like to go through our own servers when uploading a file. 或者任何其他允许我拥有安全性的方式,这适用于移动应用程序,我不希望在上传文件时通过我们自己的服务器。

Edit: 编辑:

I've tried the operation GetFederationToken with the following policy 我已经使用以下策略尝试了GetFederationToken操作

"{
   "Statement":[{
      "Effect":"Allow",
      "Action":["s3:PutObject","s3:GetObject","s3:GetObjectVersion",
      "s3:DeleteObject",\"s3:DeleteObjectVersion"],
      "Resource":"arn:aws:s3:::user.uploads/john/*"
   }
   ]
}"

I have the bucket user.uploads on S3 and folder john 我在S3和文件夹john上有bucket user.uploads

however any upload with the session credentials to bucket user.uploads with key john/filename fails with access denied" 但是任何使用会话凭据上传到具有密钥john / filename的bucket user.uploads都会因访问被拒绝而失败“

Amazon's Identity and Access Management (IAM) service is what you need. 亚马逊的身份和访问管理(IAM)服务是您所需要的。 The documentation has numerous examples, some of which match your scenario. 文档有许多示例,其中一些与您的场景相匹配。

From the docs: 来自文档:

Example 5 : Allow a partner to drop files into a specific portion of the corporate bucket 示例5 :允许合作伙伴将文件放入公司存储桶的特定部分

In this example, we create a group called WidgetCo that represents the partner company, then create a user for the specific person (or application) at the partner company who needs access, and then put the user in the group. 在此示例中,我们创建一个名为WidgetCo的组,代表合作伙伴公司,然后为需要访问的合作伙伴公司的特定人员(或应用程序)创建用户,然后将用户放入组中。

We then attach a policy that gives the group PutObject access to the following directory in the corporate bucket: my_corporate_bucket/uploads/widgetco. 然后,我们附加一个策略,使组PutObject访问公司存储桶中的以下目录:my_corporate_bucket / uploads / widgetco。

We also want to prevent the WidgetCo group from doing anything else with the bucket, so we add a statement that denies permission to any Amazon S3 actions except PutObject on any Amazon S3 resource in the AWS account. 我们还希望阻止WidgetCo组对存储桶执行任何其他操作,因此我们添加一个语句,拒绝对AWS账户中任何Amazon S3资源上除PutObject之外的任何Amazon S3操作的权限。 This is only necessary if there's a broad policy in use elsewhere in your AWS account that gives users wide access to Amazon S3. 只有在您的AWS账户中的其他地方使用广泛的政策,才能为用户提供对Amazon S3的广泛访问权限时,才需要这样做。

 { "Statement":[{ "Effect":"Allow", "Action":"s3:PutObject", "Resource":"arn:aws:s3:::my_corporate_bucket/uploads/widgetco/*" }, { "Effect":"Deny", "NotAction":"s3:PutObject", "Resource":["arn:aws:s3:::my_corporate_bucket/uploads/widgetco/*"] }, { "Effect":"Deny", "Action":"s3:*", "NotResource": ”arn:aws:s3:::my_corporate_bucket/uploads/widgetco/*" }] } 

You would create a new identity for each user and use that to control access to the subfolders (prefixes) as needed. 您将为每个用户创建一个新标识,并根据需要使用该标识来控制对子文件夹(前缀)的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM