Safeguard
Security Guides•

Should an artifact bucket use S3 versioning or Object Lock?

Versioning lets you recover overwritten build artifacts, and Object Lock makes versions undeletable for a set time. Learn when each fits a release bucket.

Safeguard Security Team
4 min read

Turn on versioning for any artifact bucket, because it lets you recover from overwrites and accidental deletes. Add Object Lock when released builds must not be changed or deleted for a set period, such as signed release binaries. Object Lock requires versioning, so you cannot have one without the other.

What each feature does

Versioning keeps multiple variants of an object in one bucket. AWS says an overwrite results in a new version and a delete inserts a delete marker instead of removing the object, so you can restore the previous version. Versioning is off by default, and once enabled a bucket can never return to unversioned. You can only suspend it.

Object Lock adds a write once, read many model. It prevents object versions from being deleted or overwritten for a fixed time or indefinitely. AWS states Object Lock works only in buckets that have versioning enabled, and that a lock protects the specific version, not the object name. New versions can still be created and delete markers can still be added.

Comparing the options

NeedVersioning onlyVersioning plus Object Lock
Recover a build overwritten by mistakeYesYes
Recover after a bad deleteYesYes
Stop a compromised role from permanently deleting a releaseNo, if the role may delete versionsYes, during retention
Prove a released file was not changedWeakStronger
Free to change your mind laterMostlyRetention can be hard to undo

Governance or compliance mode

Object Lock has two retention modes. In compliance mode, no user can overwrite or delete a protected version, including the root user, and the mode and period cannot be shortened. AWS adds that the only way to delete such an object before its retention date is to delete the associated account. In governance mode, most users cannot delete or alter lock settings, but users with the special bypass permission can, and the console includes the bypass header by default.

For most engineering teams, governance mode on release artifacts is the safer starting point. It stops routine mistakes and routine attackers, while leaving a break glass path. Choose compliance mode only if a requirement needs it, because a wrong retention period cannot be walked back.

A legal hold is a third option that has no expiry and stays until removed. It is useful when you want to freeze a set of builds during an investigation.

Setup steps

  1. Create or choose a bucket that holds only release artifacts. Keep scratch build output in a different bucket.
  2. Enable versioning.
  3. Enable Object Lock and set a default retention, for example matching your support window. You can also limit allowed retention with a bucket policy condition.
  4. Give the CI role permission to write objects, and no permission to change retention or bypass governance.
  5. Add a lifecycle rule for noncurrent versions of scratch buckets. AWS notes that you pay for every stored version, since each version is the whole object.
  6. Test: overwrite a file, delete a version, and confirm both behave as you expect.

Cost and housekeeping

Each version is a full copy and is billed as such. Versioned buckets with no lifecycle rule grow forever. Keep temporary artifacts out of locked buckets, since a locked object cannot be removed until retention ends.

Quick check

Can I enable Object Lock without versioning?

No. AWS says Object Lock works only in buckets with versioning enabled.

Does Object Lock stop someone adding a new version with the same name?

No. It protects the specific locked version. New versions and delete markers can still be created.

Safeguard does not manage your cloud accounts. It scans your code and dependencies, applies pull request policies and gates, and automates compliance evidence. Free scan: gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.