AWS Cloudfront - 具有 CloudFront 源访问和 Referer 存储桶策略的 S3

AWS Cloudfront - S3 with CloudFront Origin Access and Referer bucket policy

我在我的 s3 存储桶策略上有这个设置,我只允许我的云端和引用访问存储桶上的文件。我还使用了 Signed URL.

{
    "Version": "2008-10-17",
    "Id": "PolicyForCloudFrontContent",
    "Statement": [
        {
            "Sid": "1",
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ABCD1234"
                ]
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::my-files/*",
            "Condition":{
                "StringLike":{"aws:Referer":[
                    "https://example.com/*"
                ]}
            }
        }
    ]
}

并且在云端行为上,我在此处添加了 Referer

然后,使缓存失效。

在 s3 存储桶策略上设置 referer 之前,我仍然可以使用签名 url 访问我的文件。但是在设置 aws:Referer 条件并使缓存无效后,我无法访问我的文件。它显示 403 禁止状态。

我错过了什么设置?或者是否可以将 Cloudfront OAI 与 Referer 一起使用?

What settings did I missed? Or is it possible to use Cloudfront OAI with Referer?

不应该像使用 OAI 一样使用推荐人。这意味着 CF 将使用 AWS API 来获取您的对象,而不是常规的 HTTP(s) 请求。在那种情况下 aws:Referernot used:

This key is included in the request context only if the request to the AWS resource was invoked by linking from a web page URL in the browser. This key is not included for programmatic requests because it doesn't use a browser link to access the AWS resource.