Skip to content

Commit 3d11288

Browse files
jonesphillipelithrarOxyjun
authored
Add R2 bucket lock changelog entry + update bucket lock docs (#20566)
* Add R2 bucket lock changelog entry + update bucket lock docs * Apply suggestions from code review Co-authored-by: Matt Silverlock <[email protected]> * pr suggestion: Added example lock rules per * Change id parameter to name for both bucket lifecycle and r2 bucket lock commands * Apply suggestions from code review * clearer language on what bucket locks allow you to do --------- Co-authored-by: Matt Silverlock <[email protected]> Co-authored-by: Jun Lee <[email protected]>
1 parent f997220 commit 3d11288

File tree

3 files changed

+62
-8
lines changed

3 files changed

+62
-8
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Set retention polices for your R2 bucket with bucket locks
3+
description: Set retention polices for your R2 bucket with bucket locks
4+
products:
5+
- r2
6+
date: 2025-03-06T10:00:00Z
7+
---
8+
9+
You can now use [bucket locks](/r2/buckets/bucket-locks/) to set retention policies on your [R2 buckets](/r2/buckets/) (or specific prefixes within your buckets) for a specified period — or indefinitely. This can help ensure compliance by protecting important data from accidental or malicious deletion.
10+
11+
Locks give you a few ways to ensure your objects are retained (not deleted or overwritten). You can:
12+
13+
- Lock objects for a specific duration, for example 90 days.
14+
- Lock objects until a certain date, for example January 1, 2030.
15+
- Lock objects indefinitely, until the lock is explicitly removed.
16+
17+
Buckets can have up to 1,000 [bucket lock rules](/r2/buckets/). Each rule specifies which objects it covers (via prefix) and how long those objects must remain retained.
18+
19+
Here are a couple of examples showing how you can configure bucket lock rules using [Wrangler](/workers/wrangler/):
20+
21+
#### Ensure all objects in a bucket are retained for at least 180 days
22+
23+
```sh
24+
npx wrangler r2 bucket lock add <bucket> --name 180-days-all --retention-days 180
25+
```
26+
27+
#### Prevent deletion or overwriting of all logs indefinitely (via prefix)
28+
29+
```sh
30+
npx wrangler r2 bucket lock add <bucket> --name indefinite-logs --prefix logs/ --retention-indefinite
31+
```
32+
33+
For more information on bucket locks and how to set retention policies for objects in your R2 buckets, refer to our [documentation](/r2/buckets/bucket-locks/).

src/content/docs/r2/buckets/bucket-locks.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Before getting started, you will need:
1212
- An existing R2 bucket. If you do not already have an existing R2 bucket, refer to [Create buckets](/r2/buckets/create-buckets/).
1313
- (API only) An API token with [permissions](/r2/api/s3/tokens/#permissions) to edit R2 bucket configuration.
1414

15+
### Enable bucket lock via dashboard
16+
17+
1. From the Cloudflare dashboard, select **R2** from the sidebar.
18+
2. Select the bucket you would like to add bucket lock rule to.
19+
3. Switch to the **Settings** tab, then scroll down to the **Bucket lock rules** card.
20+
4. Select **Add rule** and enter the rule name, prefix, and retention period.
21+
5. Select **Save changes**.
22+
1523
### Enable bucket lock via Wrangler
1624

1725
1. Install [`npm`](https://docs.npmjs.com/getting-started).
@@ -77,6 +85,12 @@ If your bucket is setup with [jurisdictional restrictions](/r2/reference/data-lo
7785

7886
## Get bucket lock rules for your R2 bucket
7987

88+
### Dashboard
89+
90+
1. From the Cloudflare dashboard, select **R2** from the sidebar.
91+
2. Select the bucket you would like to add bucket lock rule to.
92+
3. Switch to the **Settings** tab, then scroll down to the **Bucket lock rules** card.
93+
8094
### Wrangler
8195

8296
To list bucket lock rules, run the [`r2 bucket lock list` command](/workers/wrangler/commands/#r2-bucket-lock-list):
@@ -91,6 +105,13 @@ For more information on required parameters and examples of how to get bucket lo
91105

92106
## Remove bucket lock rules from your R2 bucket
93107

108+
### Dashboard
109+
110+
1. From the Cloudflare dashboard, select **R2** from the sidebar.
111+
2. Select the bucket you would like to add bucket lock rule to.
112+
3. Switch to the **Settings** tab, then scroll down to the **Bucket lock rules** card.
113+
4. Locate the rule you want to remove, select the `...` icon next to it, and then select **Delete**.
114+
94115
### Wrangler
95116

96117
To remove a bucket lock rule, run the [`r2 bucket lock remove` command](/workers/wrangler/commands/#r2-bucket-lock-remove):

src/content/partials/workers/wrangler-commands/r2.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ wrangler r2 bucket lifecycle add <NAME> [OPTIONS]
263263

264264
- `NAME` <Type text="string" /> <MetaInfo text="required" />
265265
- The name of the R2 bucket to add a lifecycle rule to.
266-
- `--id` <Type text="string" /> <MetaInfo text="optional" />
267-
- A unique identifier for the lifecycle rule.
266+
- `--name` <Type text="string" /> <MetaInfo text="optional" />
267+
- A unique name for the lifecycle rule, used to identify and manage it. For example: `delete-logs-180-days`.
268268
- `--prefix` <Type text="string" /> <MetaInfo text="optional" />
269269
- Prefix condition for the lifecycle rule (leave empty for all prefixes).
270270
- `--expire-days` <Type text="number" /> <MetaInfo text="optional" />
@@ -296,8 +296,8 @@ wrangler r2 bucket lifecycle remove <NAME> [OPTIONS]
296296

297297
- `NAME` <Type text="string" /> <MetaInfo text="required" />
298298
- The name of the R2 bucket to remove a lifecycle rule from.
299-
- `--id` <Type text="string" /> <MetaInfo text="required" />
300-
- The unique identifier of the lifecycle rule to remove.
299+
- `--name` <Type text="string" /> <MetaInfo text="required" />
300+
- The unique name of the lifecycle rule to remove.
301301
- `--jurisdiction` <Type text="string" /> <MetaInfo text="optional" />
302302
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
303303

@@ -349,8 +349,8 @@ wrangler r2 bucket lock add <NAME> [OPTIONS]
349349

350350
- `NAME` <Type text="string" /> <MetaInfo text="required" />
351351
- The name of the R2 bucket to add a bucket lock rule to.
352-
- `--id` <Type text="string" /> <MetaInfo text="optional" />
353-
- A unique identifier for the bucket lock rule.
352+
- `--name` <Type text="string" /> <MetaInfo text="optional" />
353+
- A unique name for the bucket lock rule, used to identify and manage it. For example: `retain-logs-180-days`.
354354
- `--prefix` <Type text="string" /> <MetaInfo text="optional" />
355355
- Prefix condition for the bucket lock rule (leave empty for all prefixes).
356356
- `--retention-days` <Type text="number" /> <MetaInfo text="optional" />
@@ -374,8 +374,8 @@ wrangler r2 bucket lock remove <NAME> [OPTIONS]
374374

375375
- `NAME` <Type text="string" /> <MetaInfo text="required" />
376376
- The name of the R2 bucket to remove a bucket lock rule from.
377-
- `--id` <Type text="string" /> <MetaInfo text="required" />
378-
- The unique identifier of the bucket lock rule to remove.
377+
- `--name` <Type text="string" /> <MetaInfo text="required" />
378+
- The unique name of the bucket lock rule to remove.
379379
- `--jurisdiction` <Type text="string" /> <MetaInfo text="optional" />
380380
- The jurisdiction where the bucket exists, if a jurisdiction has been specified. Refer to [jurisdictional restrictions](/r2/reference/data-location/#jurisdictional-restrictions).
381381

0 commit comments

Comments
 (0)