Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revoke public permissions from a Amazon S3 Bucket

I created a Amazon S3 Bucket to store only images from my website. I have more than 1 million images all with public read access. Everytime I make a login, Amazon gives me this warning:

"This bucket has public access You have provided public access to this bucket. We highly recommend that you never grant any kind of public access to your S3 bucket. "

I'm using the following Bucket Policy to only allow images to be shown just in my site:

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

How can I revoke the public access to the bucket and to my files and grant it only to my sites?

Thank you!

like image 979
Andre Avatar asked Nov 10 '17 22:11

Andre


People also ask

How do you make a public S3 bucket private?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Bucket name list, choose the name of the bucket that you want. Choose Permissions. Choose Edit to change the public access settings for the bucket.

Can anyone access a public S3 bucket?

By default, new buckets, access points, and objects don't allow public access. However, users can modify bucket policies, access point policies, or object permissions to allow public access. S3 Block Public Access settings override these policies and permissions so that you can limit public access to these resources.

How do I access S3 bucket without public access?

A user who does not have AWS credentials or permission to access an S3 object can be granted temporary access by using a presigned url. A presigned url is generated by an AWS user who has access to the object. The generated url is then given to the user without making our bucket private.

How do you check S3 bucket is public or private?

http://[bucket_name].s3.amazonaws.com/ So, if someone wants to test the openness of a bucket, all they have to do is hit the bucket's URL from a web browser. A private bucket will return a message of “Access Denied,” and no bucket contents will be shown.


2 Answers

It's a scary warning meant to prevent people from leaking data unintentionally. There have been lots of cases in the news lately about companies accidentally setting permissions to allow public reads.

In your case you really do want these to be publicly readable so you can just ignore the warning. Your security policy looks fine and still matches the documentation for public hosting.

You could theoretically put these images behind another server that streams them to the user if you really don't want someone to be able to download them directly. That's not really any more secure though.

If you do not want to have these publicly available at all just delete this policy from your bucket. In that case your website will not be able to serve the images.

like image 66
user210309 Avatar answered Sep 20 '22 12:09

user210309


Your policy looks good. You are providing a higher level of security then just public thru the referer header and not allowing the listing of objects.

Using S3 to provide common files such as CSS, JS and Images is just so easy. However, with all of the accidental security problems I usually recommend one of these approaches:

  1. Turn on static web site hosting for the bucket. This makes it very clear to future admins that this bucket is intended for public files. Also I do not see big warning messages for these buckets. Enable redirect requests.
  2. Better, turn off all public access and use CloudFront. Enable Origin Access Identity. You receive all the benefits of CloudFront, tighter security, etc.

Using an Origin Access Identity to Restrict Access to Your Amazon S3 Content

like image 28
John Hanley Avatar answered Sep 22 '22 12:09

John Hanley