whitebear
whitebear

Reputation: 12433

Make s3 file in bucket public as default

My s3 bucket sertting Access is public and block public aceess is off

Now I uploaded the file by aws-web console.

The file is blocked from public.

I check the page here and set

Bucketpolicy is like this below.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": [
                "s3:GetBucket*",
            ],
            "Resource": [
                "arn:aws:s3:::si12-s3-resource-up",
                "arn:aws:s3:::si12-s3-resource-up/*"
            ]
        }
    ]
}

However ,still the same.

Where the point should I check more?


After uploading the file manually.

comes to each object page and set ACL as public to everyone.

The file can be seen.

SO,,,,in my opinion.

Bucket policy is set but somehow ACL is prioritized or bucket policy is ignored???


Solution

I off the ACL and set

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-bucket--name/*"
        }
    ]
}

It works, I am not sure why former bucket policy doesn't work

But thank you very much for comment.

Upvotes: 0

Views: 824

Answers (1)

Jijo Alexander
Jijo Alexander

Reputation: 1290

Use this policy in Bucket to make the object public, please don't allow DELETE operations with public access, If your application wants programmatically delete then better create ROLE for that and assign to your machine that application is running.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action":["s3:GetObject"],
            "Resource":[ 
                "arn:aws:s3:::si12-s3-resource-up",
                "arn:aws:s3:::si12-s3-resource-up/*"
            ]
        }
    ]
}

Also, Use the add the ACL in the destination object in django-s3direct

S3DIRECT_DESTINATIONS = {
    'example_destination': {
        'key': 'uploads/images',
        'acl': 'public-read', # [optional] Custom ACL for object is 'private'
        'server_side_encryption': 'AES256',
    }
} 

Upvotes: 2

Related Questions