繁体   English   中英

如何将我的 S3 web 站点的访问限制为特定域或 IP 地址?

[英]How do I restrict access of my S3 web site to specific domains or IP addresses?

我有一个托管在 S3 存储桶中的 static web 站点。 在 AWS 上使用 SSL 证书,假设该站点是https://myawssite.com/somefolder/ 在其他页面上,比如说http://containerpage.com ,我有一个 iframe 我把

<iframe src="https://myawssite.com/somefolder?url=/content/x83822" frameborder="0" allowfullscreen></iframe>

I want to allow the content to show only when the reference to myawssite.com is on http://containerpage.com , but I don't want to allow the viewing of the content if anyone just puts https://myawssite.com/somefolder?url=/content/x8382 into a browser, or puts the iframe into their own web page (on a web site not at myawssite.com ).

假设containerpage.com位于 IP 地址 5.33.253.12,我想我可以使用这样的 s3 存储桶策略来做到这一点:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject*",
            "Resource": "arn:aws:s3:::mybucketname/*",
            "Condition": {
                "StringEquals": {
                    "aws:SourceIp": "5.33.253.12/32"
                }
            }
        }
    ]
}

这是行不通的。 理想情况下,我想指定允许的域( containerpage.com ),而不是 IP 地址,但我什至无法让 IP 地址工作。

谁能发现我做错了什么,或者整个方法不正确?

在此先感谢您的任何建议!

您正在提供 ip 地址,该地址将引用http://containerpage.com/*

正如@marcin 评论的那样,您应该使用aws:refer

政策应该是这样的:

    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject*",
            "Resource": "arn:aws:s3:::mybucketname/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": "http://containerpage.com"
                }
            }
        }
    ]
}

查看文档

基于Referer限制访问是不安全的。 它很容易被规避。 一个简单的 web 搜索揭示了许多伪造referer字段的方法。

有关更安全的方法,请参阅此 StackOverflow 答案:我的 S3 存储桶策略仅适用于某些对象

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM