S3存储桶策略-限制对对象的访问

时间:2018-10-20 03:37:13

标签: amazon-s3 policy bucket

我的设置:

  • 存储在S3存储桶中的图像
  • 使用自定义CNAME(即/home/%u)链接到CloudFront CDN的存储桶

我的意图是:考虑一个对象,其原始位置为cdn.mydomain.com,而CDN位置为mybucket.s3.amazonaws.com/object.jpg

仅在以下时间允许

    使用原始URL或CDN URL从我的域(cdn.mydomain.com/object.jpg)访问的
  • 对象

  • 仅使用CDN URL访问而没有标题(即粘贴到浏览器中的链接)的对象

为此,我正在使用以下政策:

mydomain.com

我面临两个问题:

  • 无论何时应用此政策,即使嵌入到我自己的网站中,许多图像也会返回“访问被拒绝”
  • 当未指定引荐来源时,原始S3 URL(即{ "Version": "2008-10-17", "Id": "PolicyForCloudFrontPrivateContent", "Statement": [ { "Sid": "Allow access to objects when requested by CloudFront Distribution", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity <my ID>" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<my bucket>/*" }, { "Sid": "Give access if referer is not set", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<my bucket>/*", "Condition": { "StringNotLike": { "aws:Referer": "*" } } }, { "Sid": "Give access if referer is my site", "Effect": "Allow", "Principal": { "AWS": "*" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::<my bucket>/*", "Condition": { "StringLike": { "aws:Referer": ["https://www.example.com/*","https://example.com/*"] } } } ] } )仍然可以访问。

任何帮助将不胜感激。

0 个答案:

没有答案