Support key version with KMS names to correctly recognize when to skip re-encryption #1705
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.