---
title: "Object Lock"
sidebarTitle: "Object Lock"
description: "Use Object Lock to prevent file versions from being permanently deleted during a retention period, for tamper-proof backups and compliance retention: governance mode, compliance mode, default retention, and legal hold."
layout: overview
tags: Preview
tags-style: border
---

Object Lock prevents a version of a file from being permanently deleted during its retention period, for tamper-proof backups and compliance retention. It builds on [versioning](/bitiful-s4/handbook/versioning): what's protected is a version, not a file name.

<Note>
  Object Lock is in preview. It is live on the storage side, and the console entry is rolling out account by account: accounts that don't have it yet won't see the **Versions & protection** tab on the bucket page. To use it early, please [contact support](/contact).
</Note>

## Enable Object Lock

Go to **Object storage › [Buckets](https://console.bitiful.com/buckets)** › click the bucket name › **Versions & protection**, and click **Enable Object Lock** on the **Object Lock** card.

<Frame>
  ![The Versions & protection page: the Object Lock card explains governance mode, compliance mode, and legal hold, and shows the default retention](/assets/console/bucket-protection-en.webp)
</Frame>

<Warning>
  Object Lock **can't be turned off** once enabled. Enabling it also enables versioning, which then can't be suspended.
</Warning>

- Enabling it doesn't lock any file by itself. Only versions with a retention period or a legal hold are protected.
- It can't be enabled if the bucket's path has automatic expiration configured.

## Two kinds of protection

| Protection | Description |
| --- | --- |
| Retention period | The version can't be permanently deleted before its expiration time. There are two modes: governance and compliance |
| Legal hold | An on/off switch independent of the retention period. While on, the version can't be deleted until you turn it off |

Both can apply at the same time. While either is in effect, the version can't be deleted.

### Retention modes

| Mode | During the retention period |
| --- | --- |
| Governance mode | Can't be deleted. The bucket owner can shorten or remove the retention, or bypass it to delete. These actions are logged |
| Compliance mode | Nobody can delete it, shorten the retention period, or switch it back to governance mode. It can only be extended |

Governance mode can be upgraded to compliance mode, but compliance mode can't go back to governance mode.

<Warning>
  Compliance mode can't be undone: versions within the retention period can't be deleted by anyone, and the storage they use is billed until the retention period ends. Double-check the retention length before you set it.
</Warning>

## Default retention

On the **Object Lock** card, click **Set default retention** and choose the mode and length (in days or years, up to 100 years). Every version written afterward is automatically retained for that long from the moment it's written.

- It only affects versions written afterward; existing versions don't change.
- Without it, new versions aren't protected automatically, and you can set protection version by version.

## Protect individual versions

From a file's details on the **Files** page, or from **Retention & legal hold** on a version in the **Versions** view, you can view and change a version's protection:

| Action | Description |
| --- | --- |
| Set retention | Choose a mode and an expiration time, which must be in the future |
| Extend retention | Works in both modes |
| Shorten or remove retention | Governance mode only, done by the bucket owner bypassing the retention |
| Turn legal hold on or off | Can be switched at any time |
| Bypass retention and delete | Only for versions in governance mode, one file at a time. Compliance mode and legal hold can't be bypassed |

## What gets rejected

| Operation | Result |
| --- | --- |
| Permanently deleting a protected version by version ID | Rejected with 403 `AccessDenied`. Batch deletes report each item separately |
| Lifecycle deleting a protected noncurrent version | Skipped. Recent activity shows "Skipped: protected by Object Lock", and it's checked again in the next run |
| Deleting a file (without a version ID) | Allowed: it only adds a delete marker, and the protected version stays. Delete markers themselves aren't protected |
| Overwriting a file | Allowed: the old content becomes a noncurrent version, and its protection stays with it |
| Changing tags on a protected version | Allowed |
| Deleting the bucket | Returns 409 `BucketNotEmpty` while the bucket still has any version |

What Object Lock guarantees: protected versions can't be deleted through the storage API, the console, or lifecycle rules.

## Use the S3 API

| Operation | Description |
| --- | --- |
| GetObjectLockConfiguration | Requires list permission |
| PutObjectLockConfiguration | Enables Object Lock, or sets or clears the default retention; requires admin permission on the bucket |
| Retention on write | PutObject, CopyObject, CreateMultipartUpload, and PostObject with `x-amz-object-lock-mode` and `x-amz-object-lock-retain-until-date` (both are required together). Governance mode requires write permission, and compliance mode requires admin permission on the bucket. PutObject with retention must include `Content-MD5` or `x-amz-sdk-checksum-algorithm` |
| PutObjectRetention | Setting or extending governance retention requires write permission. Setting compliance retention, and shortening or removing governance retention, require admin permission on the bucket. Deleting with `x-amz-bypass-governance-retention` also requires admin permission |
| PutObjectLegalHold | Requires admin permission on the bucket |
| GetObjectRetention, GetObjectLegalHold | Require read permission. Return 404 `NoSuchObjectLockConfiguration` for versions that have never had it set |

<Note>
  Sub-user AccessKeys can upload files (which creates versions automatically), delete files without a version ID (which adds a delete marker and requires write permission), list versions, read specific versions, and read the versioning, lifecycle, and Object Lock settings.

  The following require admin permission on the bucket, which sub-user AccessKeys don't have, so do them in the console: enabling and suspending versioning, setting and deleting lifecycle rules, enabling Object Lock and setting the default retention, legal hold, setting compliance retention, permanently deleting by version ID (including items with a version ID in a batch delete), and bypassing governance mode.
</Note>

- For multipart uploads, retention parameters go in CreateMultipartUpload, and the default retention counts from when the upload completes.
- Copies don't inherit the source version's protection; they follow the request headers or the destination bucket's default retention.
- Protected versions can't be appended to.

## Differences from AWS

| Item | S4 behavior |
| --- | --- |
| Enabling on an existing bucket | Versioning is enabled at the same time if it isn't already (AWS requires enabling versioning first) |
| Bypassing governance mode | Requests without admin permission that carry `x-amz-bypass-governance-retention` get 403 right away, whether or not the version is protected. Batch deletes require permission on every key |
| Event hold | Not supported; the related headers and settings return 501 |
| Object-level `?object-lock` | Returns 400 `InvalidRequest`. Object Lock is configured only at the bucket level |
| Buckets without Object Lock | Retention parameters, or reading retention or legal hold, return 400 `InvalidRequest` |
| Retention length | Days or years, not both, up to 100 years. Invalid values return 400 `InvalidArgument` |
| Expiration precision | Stored in seconds; fractional seconds are rounded up |
| Mode values | Case-insensitive |
| Compliance certification | Compatible with the S3 Object Lock API; not assessed by a third party for compliance |

## Related

- [Versioning](/bitiful-s4/handbook/versioning)
- [Lifecycle](/bitiful-s4/handbook/lifecycle)
- [S3 API compatibility](/developer/s3/compatibility)
