我正在尝试限制我的存储桶拒绝所有内容,但允许从一个特定的IAM用户上传并根据referer
标头获取对象。这是我的政策:
{
"Version": "2012-10-17",
"Id": "Meteor refer policy",
"Statement": [
{
"Sid": "allow upload",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::556754141176:user/username"
},
"Action": "s3:PutObject*",
"Resource": [
"arn:aws:s3:::bucketname",
"arn:aws:s3:::bucketname/*"
]
},
{
"Sid": "Allow get",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "bucketname/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://myapp.com*",
"http://localhost*"
]
}
}
},
{
"Sid": "Explicit deny",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "bucketname/*",
"Condition": {
"StringNotLike": {
"aws:Referer": [
"http://myapp.com*",
"http://localhost*"
]
}
}
}
]
}
此策略正确地将GetObject指令强制执行到referer标头,但是我无法像我所说的那样使用该用户上传任何内容。如果我取出明确拒绝,我可以从任何地方访问该对象,并且引用无关紧要。我的保单有什么问题?此外,我无法从控制台访问存储桶中的任何内容。我需要做些什么呢?
谢谢,
答案 0 :(得分:2)
默认情况下,Amazon S3存储桶中的所有内容都是私有的。因此,只需添加对应该被允许的用户的访问权限。
此外,仅授予PutObject
仅允许该API调用且不允许通过AWS管理控制台进行访问,这需要ListAllMyBuckets
等权限。因此,请确保上传用户具有必要的权限,或仅使用允许的API调用。
因此:
GetObject
政策中,您还应删除"Resource": "bucketname/*",
,因为广告素材政策适用于与其相关联的存储桶这是明确的。PutObject
或授予其他权限,以便能够使用AWS管理控制台亚马逊S3(如下所示)以下是一组权限,可以在Amazon S3管理控制台中授予上传访问权限(感谢Is there an S3 policy for limiting access to only see/access one bucket?):
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1",
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::bucketname"
]
},
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "*"
}
]
}