AWS S3 bucket policy that allows GetObject only from an IP or with Presigned URL

25 Views Asked by At

I am trying to create a bucket policy that only allows me to get the objects of a bucket but only if I have a specific IP OR if I have the URL with the presigned parameters.

So far I have been trying this with no success (this means I am still unable to access it with the resigned URL if I am not in that SourceIp):

{
  "Version": "2012-10-17",
  "Id": "MyPolicy",
  "Statement": [
    {
      "Sid": "MyRestriction",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:GetObject",
      "Resource": [
        "arn:aws:s3:::mybucket",
        "arn:aws:s3:::mybucket/*"
      ],
      "Condition": {
        "NotIpAddress": {
          "aws:SourceIp": "74.X.X.X/32"
        },
        "Bool": {
          "aws:ViaAWSService": "false"
        }
      }
    }
  ]
}

I have also tried with 2 statements for the 2 conditions separated with no success too.

The policy should meet the following conditions:

Thanks in advance.

0

There are 0 best solutions below