AWS S3 Bucket Policy Explicit Deny

gkrizek

I'm trying to restrict my bucket to deny everything, but allow uploads from one specific IAM user and get objects based on referer header. Here is my policy:

{
    "Version": "2012-10-17",
    "Id": "Meteor refer policy",
    "Statement": [
        {
            "Sid": "allow upload",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::556754141176:user/username"
            },
            "Action": "s3:PutObject*",
            "Resource": [
                "arn:aws:s3:::bucketname",
                "arn:aws:s3:::bucketname/*"
            ]
        },
        {
            "Sid": "Allow get",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "bucketname/*",
            "Condition": {
                "StringLike": {
                    "aws:Referer": [
                        "http://myapp.com*",
                        "http://localhost*"
                    ]
                }
            }
        },
        {
            "Sid": "Explicit deny",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": "bucketname/*",
            "Condition": {
                "StringNotLike": {
                    "aws:Referer": [
                        "http://myapp.com*",
                        "http://localhost*"
                    ]
                }
            }
        }
    ]
}

This policy correctly enforces the GetObject directive to only the referer header, but I'm not able to upload anything with that user like I stated. If I take out the explicit deny, I can access the object from anywhere and the referer doesn't matter. What is wrong with my policy? Also, I can't access anything in the bucket from the console. What do I need to do for that?

Thanks,

John Rotenstein

By default, all content in an Amazon S3 bucket is private. So, just add access to users that should be permitted.

Also, merely granting PutObject will only allow that API call and will not permit access via the AWS Management Console, which requires permissions like ListAllMyBuckets. So, make sure the uploading user either has the necessary permissions, or only uses the API calls that it are permitted.

Therefore:

  • Remove the Deny policy -- it is not required
  • In the GetObject policy, you should also remove "Resource": "bucketname/*", because that is explicit in the fact that the Bucket Policy applies to the bucket to which it is attached
  • Have the uploading user use the AWS Command-Line Interface (CLI) or a web page to upload, that only requires PutObject OR grant additional permissions to be able to use the AWS Management Console for Amazon S3 (shown below)

Here is a set of permissions that would grant upload access within the Amazon S3 management console (with thanks to Is there an S3 policy for limiting access to only see/access one bucket?):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1",
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::bucketname"
            ]
        },
        {
            "Effect": "Allow",
            "Action": "s3:ListAllMyBuckets",
            "Resource": "*"
        }
    ]
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

AWS S3 not allowing to rename/move folders after Delete:Deny set as bucket policy

AWS S3 bucket policy should deny actions from ec2

Delete S3 Bucket With Deny All Policy And VPC Condition

AWS S3 bucket policy with condition

AWS S3 Bucket Policy is not valid

AWS S3 Bucket Policy Whitelist

AWS S3 empty bucket policy

Does s3 lifecycle rules overwrite Deny Delete Bucket or DeleteObject policy is s3 bucket?

S3 Bucket Policy - Deny Bucket Delete returning "Invalid policy syntax"

Why is this AWS S3 deny-user policy not working?

AWS S3 Policy, Allow all resources and deny some

I have a Query about AWS S3 bucket policy

AWS S3 Web Console overriding bucket policy

AWS S3 Bucket policy editor access denied

AWS S3 - permission to edit bucket policy

AWS S3: Setting a bucket policy for multiple users in an account

AWS S3: user policy for specifc bucket

AWS s3 bucket multiple StringEquals conditions policy

AWS S3 Bucket Policy not working on mobile browsers

lost accss to AWS S3 bucket via policy

AWS - S3 - Creating a Bucket Policy - Error: Access Denied

How to specify AWS S3 bucket policy

AWS S3 Bucket policy Access Denyed

aws s3 bucket policy - allow range of ip addresses

Elegant way to add exceptions to s3 bucket deny policy using StringNotLike condition for specific actions

S3 Bucket access policy: Deny on IP range and VPC Endpoint not working

AWS S3 bucket encryption - bucket property setting vs. bucket policy setting

Access denied when put bucket policy on aws s3 bucket with root user (= bucket owner)

S3 Bucket Policy to allow S3 Access to Current Authenicated user in AWS Console?

TOP Ranking

HotTag

Archive