簡體   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