Fix GCP Cloud Storage Lock Policy Errors
When working with GCP Cloud Storage, you may encounter a configuration error that prevents your deployment from working. This guide explains the most common mistake with lock policy and shows the exact fix.
A Common Mistake
Applying a bucket lock to make a retention policy permanent, but then realizing the retention period is too long and cannot be shortened because locking is irreversible.
The incorrect command:
gsutil retention set 365d gs://my-bucket && gsutil retention lock gs://my-bucket
Error output:
Setting retention policy...
Locking retention policy on gs://my-bucket...
The retention policy is now permanent. The team later realizes they need only 90 days of retention, not 365.
gsutil retention set 90d gs://my-bucket
ERROR: 400 Cannot change retention policy on a locked bucket. The retention policy is immutable after locking.
The Correct Approach
The right way to configure lock policy in GCP Cloud Storage:
gsutil retention set 90d gs://my-bucket && gsutil retention lock gs://my-bucket
Successful result:
Setting retention policy to 90 days...
Locking retention policy...
The retention policy is permanently set to 90 days. Since you cannot shorten a locked retention policy, it is critical to choose the correct duration before locking.
How to Prevent This
Never lock a retention policy on the first attempt. Test with a 1-day retention for a week. Lock policies during a scheduled maintenance window with documented rollback plan. Locking is irreversible -- the minimum retention period is permanent. Consider using event-based holds instead for flexible retention requirements. Only lock when compliance regulations require it.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Secure your cloud with DodaTech.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro