mardi 28 juillet 2015

Amazon S3 Bucket policy, allow only one domain to access files

I have a S3 bucket with a file in it. I only want a certain domain to be able to access the file. I have tried a few policies on the bucket but all are not working, this one is from the AWS documentation.

{
    "Version": "2012-10-17",
    "Id": "http referer policy example",
    "Statement": [
        {
            "Sid": "Allow get requests originated from www.example.com and example.com",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket-name/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "http://ift.tt/1OyVm3u",
                        "http://phpfiddle.org/*"
                    ]
                }
            }
        }
    ]
}

To test the file, i have hosted a code on phpfiddle.org and have this code. But i am not able to access this file neither by directly accessing from the browser nor by the phpfiddle code.

<?php 
    $myfile = file_get_contents("http://ift.tt/1LTAMNu");
    echo $myfile;
    ?>

Here are the permissions for the file, the bucket itself also has the same permissions + the above policy.

enter image description here

This is just an example link and not an actually working link.




Aucun commentaire:

Enregistrer un commentaire