Other Articles

Cloud Storage – Configure Bucket Retention or Lifecycle

Secure Configuration Checks > GCP

This check ensures that every Cloud Storage bucket has a retention policy or a lifecycle rule. A retention policy protects objects from early deletion. A lifecycle rule deletes or moves objects automatically as they age.

Check Details

  • Resource: Cloud Storage Bucket
  • Check: Configure bucket retention or lifecycle
  • Risk: Without either one, objects stay forever and storage cost grows. Objects can also be deleted at any time with no protection.

Remediation via Google Cloud Console

  1. Log in to the Google Cloud Console and navigate to Cloud Storage > Buckets. Cloud Storage Buckets
  2. Click on the affected bucket.
  3. To set a retention policy, open the Protection tab. Under Retention, click Set retention policy. Enter a retention period and click Save. Cloud Storage Retention Policy
  4. Or, to add a lifecycle rule, open the Lifecycle tab and click Add a rule. Select an action, such as Delete object. Set a condition, such as Age of 365 days. Click Create. Cloud Storage Lifecycle Rule
  5. Repeat steps 2 to 4 for every bucket that has neither.

Remediation via Google Cloud CLI

  1. Open the Google Cloud Console and launch Cloud Shell. GCP Cloud Shell
  2. List the buckets that have no retention policy and no lifecycle rule:

    for B in $(gcloud storage buckets list --format="value(name)"); do
      OUT=$(gcloud storage buckets describe "gs://$B" \
        --format="yaml(retention_policy,lifecycle_config)")
      [ -z "$OUT" ] && echo "$B"
    done
    
  3. Set a retention policy on the bucket:

    gcloud storage buckets update gs://<BUCKET_NAME> --retention-period=<PERIOD>
    

    Replace <BUCKET_NAME> with your bucket name and <PERIOD> with a period such as 30d or 1y. Do not lock the policy unless you must. A locked policy cannot be removed.

  4. Or add a lifecycle rule. Create a file named lifecycle.json:

    {
      "rule": [
        {
          "action": {"type": "Delete"},
          "condition": {"age": 365}
        }
      ]
    }
    

    Then apply it to the bucket:

    gcloud storage buckets update gs://<BUCKET_NAME> --lifecycle-file=lifecycle.json
    

    This replaces any lifecycle rules that the bucket already has. A delete rule removes objects for good.

  5. Verify the bucket configuration:

    gcloud storage buckets describe gs://<BUCKET_NAME> \
    --format="yaml(retention_policy,lifecycle_config)"
    
    Verify Cloud Storage retention or lifecycle

Default Value

By default, a bucket has no retention policy and no lifecycle rule. Objects stay until someone deletes them.

Updated on 09 November, 2026