Tools

Bucket policy generator

Choose what you want to allow or block and copy the policy in JSON with the steps to apply it. Free, no sign-up.

What you want to do
Provider

One per line, IP or CIDR range.

Policy for AWS S3

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyOutsideAllowedIPs",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::example-photos",
        "arn:aws:s3:::example-photos/*"
      ],
      "Condition": {
        "NotIpAddress": {
          "aws:SourceIp": ["203.0.113.0/24", "198.51.100.7/32"]
        }
      }
    }
  ]
}

This policy also blocks the console and any service that uses the bucket from another address, Nubbo included.

How to apply it

  1. In the S3 console, open the bucket and go to the Permissions tab.
  2. Under Bucket policy, press Edit.
  3. Paste the policy and press Save changes.

Which providers accept bucket policies

  • AWS S3Yes.
  • WasabiYes, from the bucket settings (Permissions) or the API.
  • DigitalOcean SpacesYes, only through the API and with a full-access key.
  • Backblaze B2No. Its S3 API has no bucket policy calls: buckets are only private or public.
  • Cloudflare R2No. Public access is turned on in the bucket settings or with a custom domain.

Generated in your browser. Nothing is sent.

What a bucket policy is

It is a JSON document stored on the bucket that says who can do what with it and under which conditions. It applies to every request, whichever key it comes from.

A Deny rule always wins over an Allow. So before you save a policy that blocks, check that it does not lock you out or lock out the tools that use the bucket.

Frequently asked questions

Can I use a bucket policy on Cloudflare R2?

No. R2 does not implement PutBucketPolicy. Buckets are private by default and you make them public in the bucket settings, with an r2.dev subdomain for testing or with a custom domain. To limit what a key can do, use R2 API tokens.

What do I do if I lock myself out?

On AWS, sign in with the account root user and delete the policy: AWS says that is how you get access back. With an IP limit, you can also edit it from an allowed address. On Wasabi and Spaces, delete it with a key and an address the policy does not block.

How is it different from an IAM policy?

An IAM policy is attached to a user or role and says what that identity can do on any bucket. A bucket policy is attached to the bucket and applies to whoever accesses it, even from other accounts or anonymously. When both apply, an explicit Deny in either one wins.

Does Nubbo need a bucket policy?

No. Nubbo connects with an access key and shares files with links signed for a short time, so the bucket can stay private. Just make sure a policy you add does not block Nubbo, such as an IP limit.

Sources

Policies and support checked against these pages.