This page describes how to use the Object Retention Lock feature, including enabling it for a bucket and setting retention configurations for objects within the bucket.
Required roles
To get the permissions that you need to enable the Object Retention Lock feature
for a bucket and set retention configurations on objects, ask your administrator
to grant you the Storage Admin (roles/storage.admin) IAM role
on the bucket or the project that contains the bucket. This
predefined role contains the permissions
required to set and manage retention configurations. To see the exact
permissions that are required, expand the Required permissions section:
Required permissions
storage.buckets.createstorage.buckets.enableObjectRetentionstorage.buckets.getstorage.buckets.list- This permission is only required if you plan on using the Google Cloud console to perform the instructions on this page.
storage.objects.getstorage.objects.list- This permission is only required if you plan on using the Google Cloud console to perform the instructions on this page.
storage.objects.overrideUnlockedRetention- This permission is only required if you plan on locking or shortening an existing retention configuration.
storage.objects.setRetentionstorage.objects.update
You might also be able to get these permissions with custom roles.
For information about granting roles on buckets, see Set and manage IAM policies on buckets. For information about granting roles on projects, see Manage access to projects.
Enable object retentions for a bucket
Use the following instructions to allow retention configurations for objects in a bucket. If you want to enable object retention configurations for an existing bucket, you must follow the Google Cloud console instructions.
Console
To enable object retention configurations for a new bucket:
- Create a bucket as you normally would, and in the Choose how to protect object data step, select Retention (For compliance) followed by Enable object retention.
To enable object retention configurations for an existing bucket:
- In the Google Cloud console, go to the Cloud Storage Buckets page.
In the list of buckets, click the name of the bucket for which you want to enable object retentions.
Select the Protection tab near the top of the page.
The bucket's object retention status is displayed in the Object retention section.
In the Object retention section, click Object Retention Not Enabled.
In the dialog that appears, click Confirm.
Command line
Create a bucket as you normally would, and include the
--enable-per-object-retention flag in the command.
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Java
Node.js
PHP
Python
Rust
REST APIs
JSON API
Create a bucket as you normally would, and include the query
parameter enableObjectRetention=true as part of the request.
XML API
Create a bucket as you normally would, and include the header
x-goog-bucket-object-lock-enabled: True as part of the request.
View a bucket's object retention status
To see if retention configurations can be set for objects in a bucket:
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
Click the name of the bucket whose status you want to check.
Click the Protection tab.
The bucket's object retention status is displayed in the Object retention section.
Command line
Use the gcloud storage buckets describe command with the
--format flag:
gcloud storage buckets describe gs://BUCKET_NAME --format="default(per_object_retention)"
Where BUCKET_NAME is the name of the bucket
whose retention policy you want to view. For example, my-bucket.
If successful and a retention policy exists for the bucket, the response is similar to the following:
per_object_retention: mode: Enabled
If successful and a retention policy does not exist for the bucket, the response is similar to the following:
null
Client libraries
For more information, see the
Cloud Storage C++ API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage C# API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Java API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Node.js API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage PHP API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
For more information, see the
Cloud Storage Python API
reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials.
For more information, see
Set up authentication for client libraries.
C++
C#
Java
Node.js
PHP
Python