Object locking

Protect objects from deletion and changes

Object locking requires a bucket created with object locking enabled. See Buckets.

Examples use the AWS CLI profile from Connecting. MinIO Client (mc) commands are at the end.

Modes

Mode Locked versions can be deleted before expiry
governance Only by users with the admin role, with an explicit bypass
compliance Never, by any user, including admins

Warning: A compliance lock cannot be removed or shortened by any user. Test with governance and short durations.

Default retention for a bucket

New objects are locked automatically:

aws --profile <profile> s3api put-object-lock-configuration --bucket <prefix>.<bucket-name> \
  --object-lock-configuration '{"ObjectLockEnabled":"Enabled","Rule":{"DefaultRetention":{"Mode":"GOVERNANCE","Days":30}}}'
aws --profile <profile> s3api get-object-lock-configuration --bucket <prefix>.<bucket-name>

Lock a single object

aws --profile <profile> s3api put-object-retention --bucket <prefix>.<bucket-name> --key <object> \
  --retention '{"Mode":"GOVERNANCE","RetainUntilDate":"2030-01-01T00:00:00Z"}'
aws --profile <profile> s3api get-object-retention --bucket <prefix>.<bucket-name> --key <object>

Locks an object until the hold is removed, regardless of retention. It also blocks deletion with bypass; clear the hold first.

aws --profile <profile> s3api put-object-legal-hold --bucket <prefix>.<bucket-name> --key <object> --legal-hold Status=ON
aws --profile <profile> s3api put-object-legal-hold --bucket <prefix>.<bucket-name> --key <object> --legal-hold Status=OFF

Delete a locked version (governance)

Requires the admin role. Find the version ID:

aws --profile <profile> s3api list-object-versions --bucket <prefix>.<bucket-name> --prefix <object> \
  --query 'Versions[].[Key,VersionId]' --output text

Delete it with bypass:

aws --profile <profile> s3api delete-object \
  --bucket <prefix>.<bucket-name> --key <object> --version-id <version-id> \
  --bypass-governance-retention

Other clients: send the header x-amz-bypass-governance-retention: true.

Note: Deleting without a version ID does not delete locked data. It only adds a delete marker that hides the object.

MinIO Client (mc)

# Default retention
mc retention set --default governance 30d <alias>/<prefix>.<bucket-name>
mc retention info --default <alias>/<prefix>.<bucket-name>

# Lock a single object
mc retention set governance 30d <alias>/<prefix>.<bucket-name>/<object>
mc retention info <alias>/<prefix>.<bucket-name>/<object>

# Legal hold
mc legalhold set <alias>/<prefix>.<bucket-name>/<object>
mc legalhold clear <alias>/<prefix>.<bucket-name>/<object>

# Delete a locked version
mc ls --versions <alias>/<prefix>.<bucket-name>/<object>
mc rm --version-id <version-id> --bypass <alias>/<prefix>.<bucket-name>/<object>