Exclude one Amazon S3 object from a Bucket Policy

Brian

I want to cancel the public access permission of a file(images/login_logo.png) inside my S3 bucket my-test-bucket.

Currently, this file's permission setting is as the following:

enter image description here

As you can see in the above picture. It has no public access for everyone.

But I can still access it from the s3 link.

Is this phenomenon caused by my bucket policy?

{
    "Version": "2012-10-17",
    "Id": "Policy1528702071704",
    "Statement": [
        {
            "Sid": "Stmt1528702067249",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-test-bucket/*"
        }
    ]
}

If so, what's the best way to cancel the public access permission of a single file inside a large public bucket which contains about 10,000 files?

I cannot apply make public to a large bucket due to this issue.

John Rotenstein

By default, all objects in Amazon S3 are private.

You can make an object accessible via a Bucket Policy (such as yours above), or by adding permissions on the specific object.

If either of these methods grant access to an object, then the object is accessible. So, the fact that your bucket policy is granting access to the entire bucket means that your object is public.

The only way to make an exception for one file would be to add a Deny policy, such as:

{
    "Version": "2012-10-17",
    "Id": "Policy1528702071704",
    "Statement": [
        {
            "Sid": "AllowALl",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-test-bucket/*"
        },
        {
            "Sid": "DenyOneObject",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::my-test-bucket/images/login_logo.png"
        }
    ]
}

A Deny always overrides an Allow, so that object will remain private.

However, be careful: This policy is denying read access to everybody (including you!). You will probably need to tweak it so that you can still get access (probably by using NotPrincipal).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Amazon S3 Bucket Policy Public

Amazon S3 Bucket Policy to prevent download?

Cannot set bucket policy of amazon s3

Amazon S3 Bucket Policy - Filter by User Agent

Amazon S3 bucket policy for referer condition on specific folder

Amazon S3 Bucket Policy & Google Docs View

Amazon S3 Bucket Policy Block User Agent

Amazon S3 Bucket policy to allow user to write to the bucket but that bucket only

s3 bucket policy to access object url

Amazon S3 bucket policy to set "Content Type" to "application/pdf" for a specific folder in a bucket

When creating an amazon s3 bucket, is it possible to set a policy to be automatically written into the bucket?

S3 bucket policy for the access from inside of ECS container

Cannot 'getObject' from S3 bucket - policy not working

Accessing S3 bucket from a dedicated user ( policy failure ? )

how to copy s3 object from one bucket to another using python boto3

Store Java object to Amazon S3 bucket

Revoking Amazon S3 Bucket or Object Permissions

Shell script - How to copy the last modified AWS S3 Object from one bucket to another?

copy object from minio bucket to S3 bucket

How to revoke public permissions from a Amazon S3 Bucket

Javascript to download a file from amazon s3 bucket?

Error in opening file from amazon s3 bucket

Images are not loading from an Amazon S3 bucket

Prevent from listing Amazon s3 bucket content

AWS S3 bucket policy for Get object, error in the policy generator Json code

IAM user policy returning 403 Forbidden on Amazon S3 bucket

Amazon s3 bucket policy access denied when hosting static webpage

Amazon S3 bucket policy, what am I doing wrong?

Amazon S3 bucket policy allow access to ONLY specific http