Create Public Buckets on R2
Overview
Public Bucket is a feature that allows users to expose the contents of their R2 buckets directly to the internet. By default, buckets are never publicly accessible and will always require explicit user permission to enable.
Public buckets can be set up in two ways:
- The first exposes your bucket as a custom domain.
- The second exposes your bucket as an
*.r2.dev
Cloudflare subdomain that is generated after you set up your bucket.
To configure firewall rules, caching, access controls, or bot management for your bucket, you must set up a custom domain.
Enable public access for your bucket
Enabling public access for your bucket will make the content of your bucket available to the Internet. To enable public access for your buckets:
- Log in to the Cloudflare dashboard > select your account > R2.
- In. R2, select the bucket you want to enable public access for.
- Go to Settings.
- In Settings, go to Bucket Access.
- Under Bucket Access, select Allow Access.
- You will be prompted to confirm your choice. In the confirmation dialog, type ‘allow’ to confirm and select Allow.
- You can now access the bucket and its objects using the Public Bucket URL.
You can review if your bucket is publicly accessible by going to your bucket and checking that Public URL Access states Allowed.
Connect your bucket to a custom domain
Domain access through a custom domain allows you to use features such as access management, Cache and bot management.
To connect a custom domain to your bucket:
- Go to R2 and select your bucket.
- Go to Settings.
- Go to Domain Access.
- Select Connect Domain.
- Enter the domain name you want to connect to and select Continue.
- Review the new record that will be added to the DNS table and select Connect Domain.
Your domain is now connected. It takes a few minutes for the status to change from Initializing to Active. Refresh to review the status update. If the status has not changed, select the … next to your bucket and select Retry connection.
To view the added DNS record, select … next to the connected domain and select Manage DNS.
Disable domain access
Disabling a domain will turn off public access to your bucket through that domain. Your bucket will still be publicly accessible.
To disable a domain:
- In R2, select the bucket for which you want to disable custom domain access.
- Go to Settings.
- Scroll down to Domain Access.
- Next to the domain you want to disable, select … and select Disable domain.
- The badge under Access to Bucket will update to Not allowed.
Remove domain
Removing a domain will remove custom domain configuration that you have set up on the dashboard. Your bucket will still be publicly accessible.
To remove a domain:
- In R2, select the bucket for which you want to remove domain access.
- Go to Settings.
- Scroll down to Domain Access.
- Select … next to the domain to disable and select Remove domain.
- Select ‘Remove domain’ in the confirmation window. The CNAME record pointing to the domain will also be removed as part of this step. You can always add the domain again.
The domain is no longer connected to your bucket and will no longer appear in the connected domains list.
Disable public access for your bucket
Your bucket will not be exposed to the Internet after you disable public access.
To disable public access for your bucket:
- In R2, select the bucket for which you want to turn off public access.
- Go to Settings.
- Scroll down to Public Access.
- Select Disallow Access.
- In the confirmation dialog, type ‘disallow’ to confirm and select Disallow.
Your bucket and its objects can no longer be accessed using the Public Bucket URL.