Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How can i delete a bucket with retention policy?

I set my account (khanhxxxx@gmail.com) to storage admin and storage object admin, but i still cannot delete a object inside a bucket which i accidentally set retention policy. Please help me.

3 5 791
5 REPLIES 5

Hello @Khanhnam273  ,Welcome on Google Cloud Community.

Please check this guide: https://cloud.google.com/storage/docs/using-bucket-lock#set-policy

PS: If you locked your bucket, you will not able to remove retention policy and decrease the retention period for the bucket.

How to check retention policy and lock status:  https://cloud.google.com/storage/docs/using-bucket-lock#view-policy

--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost

Thanks DamianS  for your quick reply. 

How about Using this command with flag: --clear-retention-period

Khanhnam273_0-1721197934685.png

from this guidance: https://cloud.google.com/storage/docs/using-bucket-lock#command-line.

At which case this command will take effect and remove retension policy ?

It should be a way to remove it right for example some stupid guy like me who set it for 100 years ?

Please help me with my case. I am grateful for that.  

Hello,

If you have bucket retention policy and want to clear this policy , you must use command 

gsutil retention clear gs://BUCKET_NAME

It will remove this value ( red arrow )

DamianS_0-1721291923174.png

But if you locked your bucket, you will not being able to remove such retention policy 

DamianS_1-1721292184510.png

DamianS_2-1721292207012.png

DamianS_3-1721292214862.png

 

So sad that iam in  the retention lock mode. I played with terraform and set it by accident.

If I am (user/serviceaccount) the one who lock it so I should have permission to unlock it right ? please tell me that I will have a way to unlock it. Please please...

Bucket locks are there to prevent accidental and purposeful deletion, you cannot remove the bucket once locked until all objects have met the retention period and the documentation is clear on that.  Your only options are:

1) Wait for all objects to expire the retention period, an empty bucket can be deleted.  See: 

https://cloud.google.com/storage/docs/bucket-lock#:~:text=Thus%2C%20to%20%22remove%22%20a%20locked%2....

2) You can delete the entire project - but note that activating a retention will also activate a project lien to prevent accidental project deletion - this requires explicit IAM roles in order to remove this.  See: https://cloud.google.com/resource-manager/docs/project-liens