我创建了一个带有cloudformation的存储桶:
<ul>
<li>
<p>ddd<br>ddd</p>
</li>
<li>
<p>ddd</p>
</li>
<li>
<p>ddd<br>ddd<br>ddd</p>
</li>
<li>
<p>ddd</p>
</li>
<li>
<p>ddd<br>ddd</p>
</li>
<li>
<p>ddd<br>ddd<br>ddd</p>
</li>
<li>
<p>ddd<br>ddd<br>ddd</p>
</li>
<li>
<p>ddd</p>
</li>
<li>
<p>ddd<br>ddd</p>
</li>
</ul>
现在我正在写一个bucketPolicy,但我面临一些问题。我想要实现的目标:
我怎样才能做到这一点? 目前,我拒绝从userA删除并允许从userA上传。
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
BucketName:
Type: String
Description: "Choose a name for the S3 Bucket"
Default: "myrandomnameforbucket"
S3Bucket:
Type: "AWS::S3::Bucket"
Properties:
AccessControl: "Private"
BucketName: !Ref BucketName
答案 0 :(得分:1)
我知道有两个问题:
第一个问题起初很容易,the documentation states:
在基于资源的策略中,使用Principal元素指定允许访问资源的帐户或用户
所以这意味着你可以做类似的事情:
Principal:
AWS: !Ref "AWS::AccountId"
但是当我尝试它时却没有工作。设置特定用户的arn时,它对我有用。这对我来说似乎是个错误。或者文档中的不明确。有this other report I found。
无论如何,您可以使用Principal: AWS: "*"
,然后使用Condition
到restrict to IAM users only。
第二个问题要容易得多:评估政策时明确的deny
优先于一般allow
,see documentation。
由此产生的政策可以是例如写得像这样:
S3Policy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref S3Bucket
PolicyDocument:
Statement:
- Effect: Deny
Action: "s3:DeleteObject"
Resource: !Join ["", ["arn:aws:s3:::", Ref: "S3Bucket", "/*"]]
Principal:
AWS: !GetAtt UserA.Arn
- Effect: Allow
Action: "s3:PutObject"
Resource: !Join ["", ["arn:aws:s3:::", Ref: "S3Bucket", "/*"]]
Principal:
AWS: !GetAtt UserA.Arn
- Effect: Allow
Action: ["s3:GetObject", "s3:DeleteObject"]
Resource: !Join ["", ["arn:aws:s3:::", Ref: "S3Bucket", "/*"]]
Principal:
AWS: "*"
Condition:
StringEquals:
"aws:PrincipalType": ["User"]
答案 1 :(得分:0)
{
"Version": "2012-10-17",
"Id": "S3PolicyId1",
"Statement": [
{
"Sid": "AllowGet",
"Effect": "Allow",
"Principal":{"AWS":"arn:aws:iam::account-number-without-hyphens:user/user1"},
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": [
"arn:aws:s3:::s3_bucket_name",
"arn:aws:s3:::s3_bucket_name/*"
]
},
{
"Sid": "DenyDeleteObject",
"Effect": "Deny",
"Principal": {"AWS":"arn:aws:iam::account-number-without-hyphens:user/user1"},
"Action": "s3:Delete*",
"Resource": [
"arn:aws:s3:::s3_bucket_name",
"arn:aws:s3:::s3_bucket_name/*"
]
},
{
"Sid": "Allow anyone in your account to access bucket",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::account-number-without-hyphens:root"
},
"Action": [
"s3:Get*",
"s3:List*",
"s3:Put*",
"s3:Delete*"
],
"Resource": [
"arn:aws:s3:::s3_bucket_name",
"arn:aws:s3:::s3_bucket_name/*"
]
}
]
}
这是我快速整理的JSON格式的模板。我的假设是你的小组“所有用户(在我的环境中,nob public)”是帐户中的每个人。因此,我们在第三个块中定义它。你总是可以随心所欲地操纵委托人。
如果您有任何疑问请咨询,我很乐意提供帮助。