Skip to content

Instantly share code, notes, and snippets.

@cfbarbero
Created May 14, 2020 03:23
Show Gist options
  • Save cfbarbero/96b8a840ff103967a06313919d2340cf to your computer and use it in GitHub Desktop.
Save cfbarbero/96b8a840ff103967a06313919d2340cf to your computer and use it in GitHub Desktop.

Website bucket policy allowing access from a specific IP address OR from account IAM

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<bucket>/*"
        },
        {
            "Sid": "IPAllow",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<bucket>/*",
            "Condition": {
                "NotIpAddress": {
                    "aws:SourceIp": "<some IP>/32"
                },
                "StringNotEquals": {
                    "aws:PrincipalAccount": "<account>"
                }
            }
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment