json - Amazon S3 存储桶策略只允许访问特定的 http

标签 json amazon-web-services amazon-s3

我正在尝试将对 Amazon S3 存储桶中的对象(媒体文件)的访问限制为特定的推荐域,privatewebsite.com ,使用存储桶策略,但无论引用的域如何,都会拒绝访问。
我对阻止公共(public)访问有以下设置

Block public access to buckets and objects granted through new access control lists (ACLs) - On

Block public access to buckets and objects granted through any access control lists (ACLs) - On

Block public access to buckets and objects granted through new public bucket policies - Off

Block public and cross-account access to buckets and objects through any public bucket policies - Off


我添加了以下代码、带有和不带有 http://和 https://的 URL,但仍然被拒绝访问。 (privatewebsite.com, https://privatewebsite.com, http://privatewebsite.com)
{
    "Version": "2012-10-17",
    "Id": "Policy8675309",
    "Statement": [
        {
            "Sid": "Stmt8675309",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-media-bucket/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": "https://privatewebsite.com"
                }
            }
        },
        {
            "Sid": "Explicit deny to ensure requests are allowed only from specific referer.",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::my-media-bucket/*",
            "Condition": {
                "StringNotLike": {
                    "aws:Referer": [
                        "https://privatewebsite.com/*",
                        "http://privatewebsite.com/*"
                    ]
                }
            }
        }
    ]
}
任何人都可以在我的存储桶策略中看到任何明显的错误吗?
我希望此政策允许来自 privatewebsite.com 上的页面的任何请求,同时拒绝所有其他请求,但目前所有请求都被拒绝。

最佳答案

来自 Bucket Policy Examples - Restricting Access to a Specific HTTP Referrer :

{
    "Version": "2012-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originating from www.example.com and example.com.",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::examplebucket/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "http://www.example.com/*",
                        "http://example.com/*"
                    ]
                }
            }
        }
    ]
}

此方法仅授予 Allow访问给定的Referer。无需使用 Deny使用它的策略,因为默认情况下拒绝访问。因此,只有 Allow授予权限。

关于json - Amazon S3 存储桶策略只允许访问特定的 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56227723/

相关文章:

javascript - 更新 html 标签中的动态 api 值的最佳实践

json - 使用 'as JSON'呈现响应时更改JSON响应的Content-Type

python - 需要框架来处理 Redshift 和 python 之间的交互

amazon-web-services - AWS Elastic Beanstalk 应用程序和静态 Assets 部署隔离

javascript - 将查询结果从 MySQL 发送到 .ejs

ajax - 如何在警报中显示 AJAX 响应消息?

amazon-web-services - 尝试通过 AWS : ssh 实例时出现问题

node.js - 如何使用 Node.js 和 Axios 将文件上传到 AWS 中的预签名 URL?

amazon-web-services - 我可以在 aws 安全组中添加 dns 名称吗

amazon-web-services - S3 中的 AWS lambda 部署包