Repository navigation
feat(storage): retention policies, bucket lock, object holds and retention, soft delete and Requester Pays - #99
Merged
Michael McQuade (giraffesyo) merged 8 commits intoNov 5, 2026
Conversation
…ntion, soft delete and Requester Pays
…ps holds and retention, and media reads answer 404
…bucket gets follow the API reference
…take a get's body, and soft delete effective times follow their history
…tention needs setRetention
…hange rpo, and update permissions check the named generation
Michael McQuade (giraffesyo)
deleted the
feat/gcs-retention-holds-soft-delete
branch
November 5, 2026 18:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Cloud Storage stand-in now models the data protection features that decide whether a delete or an overwrite goes through:
retentionPolicyon bucket insert and patch, witheffectiveTimeandisLocked, andbuckets.lockRetentionPolicy, which needsifMetagenerationMatch. Objects reportretentionExpirationTime. A delete or overwrite before that time fails with 403retentionPolicyNotMetand Cloud Storage's message. A locked policy can be lengthened, up to 3,155,760,000 seconds, but not shortened or removed.temporaryHoldandeventBasedHoldcan be set on upload,objects.patchand the newobjects.update, and the bucket'sdefaultEventBasedHoldapplies them to new objects. A held generation can't be deleted, overwritten or made noncurrent, and fails with Cloud Storage's 403. Releasing an event-based hold starts the retention period again.enableObjectRetentionon bucket insert, and per-objectretentioninUnlockedorLockedmode, withoverrideUnlockedRetention, which shortening, removing or locking Unlocked retention needs. The 400 and 403 errors match Cloud Storage's.softDeletePolicydefaults to 7 days and accepts 0 or 7 to 90 days. Deleted and replaced generations are kept withsoftDeleteTimeandhardDeleteTime. They are listed withsoftDeleted=true, read withobjects.get(softDeletedandgeneration) and brought back withobjects.restore, until they expire on the server's clock.softDeletePolicy.effectiveTimefollows the policy's history, as the discovery document defines it. Deleted buckets are kept the same way, at least until their last soft-deleted object expires, listed and read withsoftDeleted=true, and brought back withbuckets.restore.billing.requesterPaysis recorded. UnderWithPolicy, a call withoutuserProjectneedsresourcemanager.projects.createBillingAssignmentand fails with 400 "Bucket is a requester pays bucket but no user project provided." A call withuserProjectneedsserviceusage.services.use.SetRetentionPolicy(locked or not),SetObjectHolds,SetObjectRetention,PutSoftDeletedObject,SoftDeletedObjectsandSoftDeletedBuckets.objects.get(metadata only),objects.patchandobjects.updateare new. Bucket insert and patch, and object patch and update, ignore the fields the server sets (effectiveTimeandisLockedin the bucket policies included), so a client can send back the body a get returned. A bucket patch accepts the insert-onlyname,locationandcustomPlacementConfigonly unchanged, andobjectRetentiononly as the bucket has it (it is set byenableObjectRetentionon insert);rpocan now be patched. A different objectstorageClassis rejected with 400.ifGenerationNotMatchand no live object fail with 412, per the reference.storage.objects.setRetention(for any body that includesretention, null included, and for anobjects.updatethat removes it),storage.objects.overrideUnlockedRetention,storage.objects.restoreandstorage.buckets.restore.Statuses, reasons and messages follow the JSON API reference, the feature pages and Cloud Storage's own responses; where none gives the answer, the package documentation marks it inferred. Shortening or removing a locked policy answers 403: the bucket lock page says 400, but the retentionPolicy field description in the JSON API discovery document describes these as PERMISSION_DENIED, which is what Cloud Storage answers, and the package doc says so. Retention error messages give the time in UTC, where Cloud Storage writes Pacific time.
Testing
cloud.google.com/go/storageinsdktest/gcp/storage/protection_test.go, plus a permission test. Bucket soft delete andobjects.updatego through the generatedgoogle.golang.org/api/storage/v1client, because the Go storage client has no calls for them.objects.restorefor object names that contain/restore. New fuzz seeds were added, andFuzzServeHTTPran for 30s.go build,go vetandgo test -racein both modules, plusmake lintandmake vuln.make bench, comparingBenchmarkUploadListDeletewith canary (n=6):Checklist
make checkpasses