Skip to content

Object Lock

Preview

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: what's protected is a version, not a file name.

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.

Enable Object Lock

Go to Object storage › Buckets › click the bucket name › Versions & protection, and click Enable Object Lock on the Object Lock card.

The Versions & protection page: the Object Lock card explains governance mode, compliance mode, and legal hold, and shows the default retention

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

  • 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

ProtectionDescription
Retention periodThe version can't be permanently deleted before its expiration time. There are two modes: governance and compliance
Legal holdAn 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

ModeDuring the retention period
Governance modeCan't be deleted. The bucket owner can shorten or remove the retention, or bypass it to delete. These actions are logged
Compliance modeNobody 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.

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.

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:

ActionDescription
Set retentionChoose a mode and an expiration time, which must be in the future
Extend retentionWorks in both modes
Shorten or remove retentionGovernance mode only, done by the bucket owner bypassing the retention
Turn legal hold on or offCan be switched at any time
Bypass retention and deleteOnly for versions in governance mode, one file at a time. Compliance mode and legal hold can't be bypassed

What gets rejected

OperationResult
Permanently deleting a protected version by version IDRejected with 403 AccessDenied. Batch deletes report each item separately
Lifecycle deleting a protected noncurrent versionSkipped. 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 fileAllowed: the old content becomes a noncurrent version, and its protection stays with it
Changing tags on a protected versionAllowed
Deleting the bucketReturns 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

OperationDescription
GetObjectLockConfigurationRequires list permission
PutObjectLockConfigurationEnables Object Lock, or sets or clears the default retention; requires admin permission on the bucket
Retention on writePutObject, 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
PutObjectRetentionSetting 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
PutObjectLegalHoldRequires admin permission on the bucket
GetObjectRetention, GetObjectLegalHoldRequire read permission. Return 404 NoSuchObjectLockConfiguration for versions that have never had it set

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.

  • 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

ItemS4 behavior
Enabling on an existing bucketVersioning is enabled at the same time if it isn't already (AWS requires enabling versioning first)
Bypassing governance modeRequests 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 holdNot supported; the related headers and settings return 501
Object-level ?object-lockReturns 400 InvalidRequest. Object Lock is configured only at the bucket level
Buckets without Object LockRetention parameters, or reading retention or legal hold, return 400 InvalidRequest
Retention lengthDays or years, not both, up to 100 years. Invalid values return 400 InvalidArgument
Expiration precisionStored in seconds; fractional seconds are rounded up
Mode valuesCase-insensitive
Compliance certificationCompatible with the S3 Object Lock API; not assessed by a third party for compliance