Support key version with KMS names to correctly recognize when to skip re-encryption#1705
Open
KDB223 wants to merge 6 commits intoGoogleCloudPlatform:masterfrom
Open
Support key version with KMS names to correctly recognize when to skip re-encryption#1705KDB223 wants to merge 6 commits intoGoogleCloudPlatform:masterfrom
KDB223 wants to merge 6 commits intoGoogleCloudPlatform:masterfrom
Conversation
… when to skip re-encryption
dilipped
reviewed
May 21, 2023
| 'keyRings/([a-zA-Z0-9_-]{1,63})/' | ||
| 'cryptoKeys/([a-zA-Z0-9_-]{1,63})$')) | ||
| 'cryptoKeys/([a-zA-Z0-9_-]{1,63})/' | ||
| 'cryptoKeyVersions/([0-9]{1,63})$')) |
Collaborator
There was a problem hiding this comment.
Looks like the ValidateCMEK function seems to be getting used at multiple places and not every time we pass a key with CryptoKeyVersions (e.g. if you are reading it from boto config)?. I have a feeling that this might break other workflows.
Author
There was a problem hiding this comment.
You're right, it will break a lot of things that rely on the CryptoKeyWrapper class.
Collaborator
|
Thanks for the PR! Can you please verify some of the other use cases that rely on this function? |
Author
|
Since this bug has to do specifically with |
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Jan 28, 2026
…leCloudPlatform#1705) to librarian release pull request: 20260106T130342Z (#1922)
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Jan 28, 2026
….0 (GoogleCloudPlatform#1705) to librarian release pull request: 20260106T130342Z (#1922)" This reverts commit a8858bc.
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Jan 28, 2026
…leCloudPlatform#1705) to librarian release pull request: 20260106T130342Z (#1922)
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Jan 28, 2026
….0 (GoogleCloudPlatform#1705) to librarian release pull request: 20260106T130342Z (#1922)" This reverts commit f953a82.
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Feb 2, 2026
…eCloudPlatform#1705) HEAD is now at f32301a chore: librarian release pull request: 20260106T130342Z (#1922)
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Feb 2, 2026
…main): release 2.39.0 (GoogleCloudPlatform#1705) HEAD is now at f32301a chore: librarian release pull request: 20260106T130342Z (#1922)
bhandarivijay-png
added a commit
to bhandarivijay-png/gsutil
that referenced
this pull request
Feb 2, 2026
… librarian release pull request: 20260106T130342Z (#1922) HEAD is now at ee1c7d3 chore(main): release 2.39.0 (GoogleCloudPlatform#1705)
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.
The metadata received from
GetObjectMetadata()at https://github.com/GoogleCloudPlatform/gsutil/blob/master/gslib/commands/rewrite.py#LL399C1-L403C5 is used to determine if the object's current encryption is CSEK or SMEK, and compared withdest_encryption_kms_key:The issue here is that GetObjectMetadata() returns the fully-qualified KMS key name, including the version number. Here is sample debugging output from one of my local runs:
encryption_unchangedwill thus never beTruefor objects with CMEK, and therewrite -kcommand will always re-encrypt the object despite having the same KMS key.To reproduce:
$ gsutil cp ./mysecretfile.txt gs://my-bucketrewriteto encrypt it with CMEK.storage.objects.rewritegets called as expected:storage.objects.rewritecalled again:Contrast this with a user-generated CSEK instead, where it skips the rewrite second time round:
Modifying
ValidateCMEK()to accept version numbers as part of the KMS name fixes this. Public docs already mention using the "fully-qualified" KMS key name, which includes the version number anyway.